Skip to content

Instantly share code, notes, and snippets.

@urbansky urbansky/mpa.groovy
Created Aug 27, 2018

Embed
What would you like to do?
// ------------------------
// Controller classes
// ------------------------
package de.beispiel.api
import de.beispiel.SuperController
import de.beispiel.exception.DomainObjectNotFoundException
class CrmProjectController extends SuperController {
CrmProjectService crmProjectService
def index(String product) {
[projects: CrmProject.findAllByProduct(product)]
}
def show(String product, long projectId) {
CrmProject project = CrmProject.get(projectId)
if (project?.product != product) throw new DomainObjectNotFoundException("CrmProject not found")
[project: project]
}
def create(String product) {
[:]
}
def save(String product) {
CrmProject project = crmProjectService.create(product, params)
redirect action: "show", params: [product: product, projectId: project.id]
}
def edit(String product, long projectId) {
CrmProject project = CrmProject.get(projectId)
if (project?.product != product) throw new DomainObjectNotFoundException("CrmProject not found")
[project: project]
}
def update(String product, long projectId) {
CrmProject project = CrmProject.get(projectId)
if (project?.product != product) throw new DomainObjectNotFoundException("CrmProject not found")
crmProjectService.update(project, params)
redirect action: "show", params: [product: product, projectId: project.id]
}
def delete(String product, long projectId) {
CrmProject project = CrmProject.get(projectId)
if (project?.product != product) throw new DomainObjectNotFoundException("CrmProject not found")
crmProjectService.delete(project)
redirect action: "index", params: [product: product]
}
}
// ------------------------
// URL mapping
// ------------------------
"/crm/project/$product" (controller: "crmProject")
"/crm/project/$product/create" (controller: "crmProject", action: "create")
"/crm/project/$product/save" (controller: "crmProject", action: "save")
"/crm/project/$product/edit" (controller: "crmProject", action: "edit")
"/crm/project/$product/update" (controller: "crmProject", action: "update")
"/crm/project/$product/$projectId/show" (controller: "crmProject", action: "show")
"/crm/project/$product/$projectId/delete" (controller: "crmProject", action: "delete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.