-
Notifications
You must be signed in to change notification settings - Fork 0
/
planController.java
53 lines (44 loc) · 1.69 KB
/
planController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@Component
@Controller
@SessionAttributes(value = {"episode", "user"})
public class planController {
private UserService userService;
private PlanRepository planRepository;
private UserRepository userRepository;
@Autowired
EpisodeService episodeService;
@Autowired
public void setPlanRepository(PlanRepository planRepository) {this.planRepository = planRepository; }
@Autowired
public void setUserRepository(UserRepository userRepository) {
this.userRepository = userRepository;
}
@Autowired
public void setUserService(UserService userService) {
this.userService = userService;
}
@ModelAttribute("user")
public User getUser() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
User user = userRepository.findByEmail(auth.getName());
return user;
}
@GetMapping("/newplan")
public String Episode(Model model, Episode episode, HttpSession session) {
List<User> users = userService.findAll();
Map<String,List<UserOrganisationPair>> mapUsersOrgs = userService.getOrganisationLinkedHashMap();
Plan plan = episode.getPlan();
model.addAttribute("organisations", mapUsersOrgs);
model.addAttribute("users", users);
model.addAttribute("episode", episode);
model.addAttribute("plan", plan);
return "newplan";
}
@PostMapping("/planSubmit")
public String submitPlan(@ModelAttribute Plan plan, Episode episode) {
planRepository.save(plan);
episodeService.associateEpisodeToPlan(episode.getPlan().getId(), episode);
episodeService.submitPlan(episode);
return "redirect:dashboard";
}
}