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

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

Resolved bux for fronted and repaired filtering through title and genres for movies

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