1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sourceforge.mystique.application;
22
23 import java.util.List;
24
25 import net.sourceforge.mystique.domain.entity.Project;
26 import net.sourceforge.mystique.domain.entity.Version;
27 import net.sourceforge.mystique.domain.repository.ProjectRepository;
28 import net.sourceforge.mystique.domain.repository.Repository;
29 import net.sourceforge.mystique.domain.repository.RepositoryException;
30 import net.sourceforge.mystique.domain.repository.VersionRepository;
31
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Controller;
34 import org.springframework.ui.Model;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestParam;
37
38
39
40
41 @Controller
42 public class VersionController {
43
44 @Autowired
45 private ProjectRepository projectRepository;
46
47 @Autowired
48 private VersionRepository versionRepository;
49
50 @RequestMapping("/project/version/list.xhtml")
51 public String handleList(@RequestParam("projectId") Long projectId, Model model) throws RepositoryException {
52
53 Project project = projectRepository.findById(projectId);
54 List<Version> list = versionRepository.findByProject(project, 0, Repository.SMALL_RESULT);
55
56 model.addAttribute("project", project);
57 model.addAttribute("list", list);
58
59 return "project.version.list";
60
61 }
62
63 @RequestMapping("/project/version/remove.xhtml")
64
65 public String handleRemove(@RequestParam("versionId") Long versionId) throws RepositoryException {
66
67 Version version = versionRepository.findById(versionId);
68 Long projectId = version.getProject().getId();
69 versionRepository.remove(version);
70
71 return "redirect:list.xhtml?projectId=" + projectId;
72
73 }
74
75 }