source: Git/src/main/java/com/wediscussmovies/project/web/controller/UsersController.java@ e0ef1b1

main
Last change on this file since e0ef1b1 was e0ef1b1, checked in by Test <matonikolov77@…>, 2 years ago

Added CRUD for movies,persons,discussion,replies,genres
Added ajaxcalls

  • Property mode set to 100644
File size: 2.7 KB
Line 
1package com.wediscussmovies.project.web.controller;
2
3
4import com.wediscussmovies.project.LoggedUser;
5import com.wediscussmovies.project.model.exception.InvalidArgumentsException;
6import com.wediscussmovies.project.model.exception.PasswordsDoNotMatchException;
7import com.wediscussmovies.project.service.MovieService;
8import com.wediscussmovies.project.service.UserService;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.GetMapping;
12import org.springframework.web.bind.annotation.PostMapping;
13import org.springframework.web.bind.annotation.RequestMapping;
14import org.springframework.web.bind.annotation.RequestParam;
15
16@Controller
17@RequestMapping
18public class UsersController{
19 private final UserService userService;
20 private final MovieService movieService;
21
22 public UsersController(UserService userService, MovieService movieService) {
23 this.userService = userService;
24 this.movieService = movieService;
25 }
26 @PostMapping("/register")
27 public String register(@RequestParam String username,
28 @RequestParam String password,
29 @RequestParam String repeatedPassword,
30 @RequestParam String email,
31 @RequestParam String name,
32 @RequestParam String surname) {
33 try{
34 this.userService.register(email,username,password,repeatedPassword,name,surname);
35 return "redirect:/login";
36 } catch (InvalidArgumentsException | PasswordsDoNotMatchException exception) {
37 return "redirect:/register?error=" + exception.getMessage();
38 }
39 }
40 @GetMapping("/register")
41 public String getRegisterPage(@RequestParam(required = false) String error, Model model) {
42 addModelError(model,error);
43 model.addAttribute("contentTemplate","register");
44 return "template";
45 }
46 @GetMapping("/login")
47 public String getLoginPage(@RequestParam(required = false) String error,Model model){
48 addModelError(model,error);
49 model.addAttribute("contentTemplate","login");
50 return "template";
51 }
52
53 private void addModelError(Model model,String error){
54 if(error != null && !error.isEmpty()) {
55 model.addAttribute("hasError", true);
56 model.addAttribute("error", error);
57 }
58 }
59 @GetMapping("/favoriteList")
60 public String getFavoriteList(Model model){
61 model.addAttribute("movies",this.movieService.findLikedMoviesByUser(LoggedUser.getLoggedUser()));
62 model.addAttribute("contentTemplate","favoriteList");
63 return "template";
64
65 }
66
67
68}
Note: See TracBrowser for help on using the repository browser.