Created
December 30, 2016 07:42
-
-
Save orekyuu/0feafae8ce33658b4529a7126550fddb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.orekyuu.workbench.infra.ProjectName; | |
import net.orekyuu.workbench.project.domain.model.Project; | |
import net.orekyuu.workbench.project.usecase.ProjectUsecase; | |
import net.orekyuu.workbench.service.exceptions.ProjectNotFoundException; | |
import org.eclipse.jgit.api.errors.GitAPIException; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.Model; | |
import org.springframework.web.bind.annotation.ControllerAdvice; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.ModelAttribute; | |
import org.springframework.web.bind.annotation.PathVariable; | |
@ControllerAdvice("net.orekyuu.workbench.controller.view.user.project") | |
public class ProjectControllerAdvice { | |
@Autowired | |
private ProjectUsecase usecase; | |
@ModelAttribute | |
public void addProjectObject(@PathVariable("projectId") String projectId, Model model) { | |
Project project = usecase.findById(projectId).orElseThrow(() -> new ProjectNotFoundException(projectId)); | |
model.addAttribute("project", project); | |
} | |
} | |
@Controller | |
public class ProjectDashboardController { | |
@GetMapping("/project/{projectId}") | |
public String show(@PathVariable String projectId, Model model) { | |
Object project = model.asMap().get("project"); | |
if (project == null || !(project instanceof Project)) { | |
throw new ProjectNotFoundException(projectId); | |
} | |
//... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment