[ac25203] | 1 | package com.example.moviezone.web;
|
---|
| 2 |
|
---|
| 3 |
|
---|
[0fb69cc] | 4 | import com.example.moviezone.model.*;
|
---|
[1e7126f] | 5 | import com.example.moviezone.model.enums.GenreEnum;
|
---|
[f9cc555] | 6 | import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException;
|
---|
[8d49568] | 7 |
|
---|
[cc88ec2] | 8 | import com.example.moviezone.model.exceptions.UserNotFoundException;
|
---|
[9eba1fb] | 9 | import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
|
---|
[8d49568] | 10 |
|
---|
| 11 | import com.example.moviezone.model.procedures.FilmsReturnTable;
|
---|
| 12 |
|
---|
[1e7126f] | 13 | import com.example.moviezone.model.procedures.TicketsCancelClass;
|
---|
[302b233] | 14 | import com.example.moviezone.service.*;
|
---|
| 15 | import org.springframework.format.annotation.DateTimeFormat;
|
---|
[ac25203] | 16 | import org.springframework.stereotype.Controller;
|
---|
[adf250d] | 17 | import org.springframework.ui.Model;
|
---|
[eb5426c] | 18 | import org.springframework.web.bind.annotation.*;
|
---|
[e097c1c] | 19 |
|
---|
[cc88ec2] | 20 | import javax.servlet.http.HttpServletRequest;
|
---|
[5444409] | 21 | import javax.servlet.http.HttpServletResponse;
|
---|
[e097c1c] | 22 | import javax.servlet.http.HttpSession;
|
---|
[eb36f39] | 23 | import javax.transaction.Transactional;
|
---|
[5444409] | 24 | import java.io.IOException;
|
---|
[a554435] | 25 | import java.time.LocalDate;
|
---|
[1e7126f] | 26 | import java.time.LocalDateTime;
|
---|
| 27 | import java.time.temporal.ChronoUnit;
|
---|
| 28 | import java.util.ArrayList;
|
---|
[a8b6e6a] | 29 | import java.util.Collections;
|
---|
[8d49568] | 30 | import java.util.LinkedList;
|
---|
[eb5426c] | 31 | import java.util.List;
|
---|
| 32 | import java.util.stream.Collectors;
|
---|
[ac25203] | 33 |
|
---|
| 34 | @Controller
|
---|
[eb5426c] | 35 | @RequestMapping({"/","/home"})
|
---|
[ac25203] | 36 | public class HomeController {
|
---|
| 37 |
|
---|
| 38 | private final FilmService filmService;
|
---|
[e097c1c] | 39 | private final UserService userService;
|
---|
[a554435] | 40 | private final ProjectionService projectionService;
|
---|
| 41 | private final EventService eventService;
|
---|
[302b233] | 42 | private final TicketService ticketService;
|
---|
[448bd84] | 43 | private final WorkerService workerService;
|
---|
[43a1688] | 44 | private final CustomerRatesFilmService customerRatesFilmService;
|
---|
[fc448f5] | 45 | private final CinemaService cinemaService;
|
---|
| 46 | private final CinemaOrganizesEventService cinemaOrganizesEventService;
|
---|
[03fd098] | 47 | private final CinemaPlaysFilmService cinemaPlaysFilmService;
|
---|
[64ee7f4] | 48 | private final ProjectionIsPlayedInRoomService projectionIsPlayedInRoomService;
|
---|
[0ba5d1a] | 49 | private final CategoryService categoryService;
|
---|
[00fa72f] | 50 | private final SeatService seatService;
|
---|
| 51 | private final CustomerService customerService;
|
---|
| 52 | private final Projection_RoomService projectionRoomService;
|
---|
[ef84238] | 53 | private final CustomerIsInterestedInEventService customerIsInterestedInEventService;
|
---|
[1e7126f] | 54 | private final DiscountService discountService;
|
---|
[ac25203] | 55 |
|
---|
[1e7126f] | 56 | public HomeController(FilmService filmService, UserService userService, ProjectionService projectionService, EventService eventService, TicketService ticketService, WorkerService workerService, CustomerRatesFilmService customerRatesFilmService, CinemaService cinemaService, CinemaOrganizesEventService cinemaOrganizesEventService, CinemaPlaysFilmService cinemaPlaysFilmService, ProjectionIsPlayedInRoomService projectionIsPlayedInRoomService, CategoryService categoryService, SeatService seatService, CustomerService customerService, Projection_RoomService projectionRoomService, CustomerIsInterestedInEventService customerIsInterestedInEventService, DiscountService discountService)
|
---|
[89438a3] | 57 | {
|
---|
[93341f8] | 58 |
|
---|
[ac25203] | 59 | this.filmService = filmService;
|
---|
[e097c1c] | 60 | this.userService = userService;
|
---|
[a554435] | 61 | this.projectionService = projectionService;
|
---|
| 62 | this.eventService = eventService;
|
---|
[302b233] | 63 | this.ticketService = ticketService;
|
---|
[448bd84] | 64 | this.workerService = workerService;
|
---|
[43a1688] | 65 | this.customerRatesFilmService = customerRatesFilmService;
|
---|
[fc448f5] | 66 | this.cinemaService = cinemaService;
|
---|
| 67 | this.cinemaOrganizesEventService = cinemaOrganizesEventService;
|
---|
[03fd098] | 68 | this.cinemaPlaysFilmService = cinemaPlaysFilmService;
|
---|
[64ee7f4] | 69 | this.projectionIsPlayedInRoomService = projectionIsPlayedInRoomService;
|
---|
[0ba5d1a] | 70 | this.categoryService = categoryService;
|
---|
[00fa72f] | 71 | this.seatService = seatService;
|
---|
| 72 | this.customerService = customerService;
|
---|
| 73 | this.projectionRoomService = projectionRoomService;
|
---|
[ef84238] | 74 | this.customerIsInterestedInEventService = customerIsInterestedInEventService;
|
---|
[1e7126f] | 75 | this.discountService = discountService;
|
---|
[ac25203] | 76 | }
|
---|
| 77 |
|
---|
[eb5426c] | 78 | @GetMapping
|
---|
[adf250d] | 79 | public String getHomePage(Model model) {
|
---|
[eb5426c] | 80 | List<Film> films=filmService.findAllFilms();
|
---|
[a8b6e6a] | 81 | Collections.reverse(films);
|
---|
[eb5426c] | 82 | films=films.stream().limit(5).collect(Collectors.toList());
|
---|
[a8b6e6a] | 83 | List <Event> events=eventService.findAllEvents();
|
---|
| 84 | Collections.reverse(events);
|
---|
| 85 | events=events.stream().limit(5).collect(Collectors.toList());
|
---|
[eb5426c] | 86 | model.addAttribute("films", films);
|
---|
[0fb69cc] | 87 | model.addAttribute("events",events);
|
---|
[adf250d] | 88 | model.addAttribute("bodyContent", "home");
|
---|
[eb5426c] | 89 |
|
---|
| 90 | return "master-template";
|
---|
| 91 | }
|
---|
| 92 | @GetMapping("/getFilm/{id}")
|
---|
| 93 | public String getFilm(@PathVariable Long id, Model model) {
|
---|
[43a1688] | 94 | Film film=filmService.getFilmById(id).get();
|
---|
[eb5426c] | 95 | model.addAttribute("film", film);
|
---|
[43a1688] | 96 | List<String> genres= List.of(film.getGenre().split(","));
|
---|
| 97 | double r=customerRatesFilmService.avg_rating(film.getId_film());
|
---|
[a8b6e6a] | 98 | Double ra=Double.valueOf(r);
|
---|
| 99 | if(ra==null){
|
---|
| 100 | r=0;
|
---|
| 101 | }
|
---|
[b5ce654] | 102 | model.addAttribute("rating",r);
|
---|
[43a1688] | 103 | model.addAttribute("genres", genres);
|
---|
| 104 | model.addAttribute("bodyContent", "film");
|
---|
[eb5426c] | 105 |
|
---|
[adf250d] | 106 | return "master-template";
|
---|
| 107 | }
|
---|
[90317ea] | 108 | @GetMapping("/getEvent/{id}")
|
---|
| 109 | public String getEvent(@PathVariable Long id, Model model) {
|
---|
| 110 | Event event =eventService.getEventById(id).get();
|
---|
| 111 | model.addAttribute("event", event);
|
---|
| 112 | model.addAttribute("bodyContent", "event");
|
---|
[adf250d] | 113 |
|
---|
[90317ea] | 114 | return "master-template";
|
---|
| 115 | }
|
---|
[5867520] | 116 | @GetMapping("/getProjections/{id}")
|
---|
| 117 | @Transactional
|
---|
| 118 | public String getProjectionsFromFilm(@PathVariable Long id, Model model) {
|
---|
| 119 | Film film=filmService.getFilmById(id).get();
|
---|
| 120 | model.addAttribute("film",film);
|
---|
| 121 | model.addAttribute("projections",projectionService.getProjectionsForFilms(id.intValue()));
|
---|
[0ba5d1a] | 122 | model.addAttribute("categories",categoryService.findAllCategories());
|
---|
[5867520] | 123 | model.addAttribute("bodyContent", "projectionsForFilm");
|
---|
| 124 |
|
---|
| 125 | return "master-template";
|
---|
| 126 | }
|
---|
[00fa72f] | 127 | @GetMapping("/getSeats/{id}")
|
---|
| 128 | @Transactional
|
---|
| 129 | public String getSeats(@PathVariable Long id, Model model,@RequestParam Long id_category,@RequestParam Long film) {
|
---|
| 130 | Category category=categoryService.getCategoryById(id_category.intValue()).get();
|
---|
| 131 | Projection projection=projectionService.findById(id.intValue());
|
---|
| 132 | model.addAttribute("film",filmService.getFilmById(film).get());
|
---|
| 133 | model.addAttribute("projection",projection);
|
---|
| 134 | model.addAttribute("category",category);
|
---|
| 135 |
|
---|
[1e7126f] | 136 | List<Seat> seats=seatService.findAllByRoomAndCategory(projection,projectionRoomService.getRoomByProjection(projection.getId_projection()).get(0),category);
|
---|
[00fa72f] | 137 | model.addAttribute("seats",seats);
|
---|
| 138 | model.addAttribute("bodyContent", "seats");
|
---|
| 139 |
|
---|
| 140 | return "master-template";
|
---|
| 141 | }
|
---|
[e097c1c] | 142 | @GetMapping("/login")
|
---|
| 143 | public String getLoginPage(Model model)
|
---|
| 144 | {
|
---|
| 145 | model.addAttribute("bodyContent", "login");
|
---|
| 146 | return "master-template";
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | @GetMapping("/register")
|
---|
| 150 | public String getRegisterPage(Model model)
|
---|
| 151 | {
|
---|
| 152 | model.addAttribute("bodyContent", "register");
|
---|
| 153 | return "master-template";
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | @PostMapping("/login")
|
---|
[d7f5da9] | 157 | public String login(@RequestParam String username,
|
---|
[cc88ec2] | 158 | @RequestParam String password, Model model, HttpServletRequest request)
|
---|
[e097c1c] | 159 | {
|
---|
[d7f5da9] | 160 | // User user = null;
|
---|
[cc88ec2] | 161 | try {
|
---|
[d7f5da9] | 162 | User user=userService.login(username,password);
|
---|
| 163 | System.out.println(user.getFirst_name());
|
---|
[cc88ec2] | 164 | request.getSession().setAttribute("user", user);
|
---|
| 165 | // model.addAttribute("user",user);
|
---|
[e097c1c] | 166 | return "redirect:/home";
|
---|
[cc88ec2] | 167 |
|
---|
| 168 | }catch (UserNotFoundException e)
|
---|
| 169 | {
|
---|
| 170 | model.addAttribute("hasError", true);
|
---|
| 171 | model.addAttribute("error", e.getMessage());
|
---|
[5444409] | 172 | return "login";
|
---|
[cc88ec2] | 173 | }
|
---|
[e097c1c] | 174 |
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[5444409] | 177 | @PostMapping("/register")
|
---|
| 178 | public void register(@RequestParam String username,
|
---|
[f9cc555] | 179 | @RequestParam String first_name,
|
---|
| 180 | @RequestParam String last_name,
|
---|
| 181 | @RequestParam String password,
|
---|
| 182 | @RequestParam String repeatedPassword,
|
---|
| 183 | @RequestParam String email,
|
---|
| 184 | @RequestParam String number,
|
---|
[5444409] | 185 | @RequestParam Role role,HttpServletResponse response, HttpSession session) throws IOException {
|
---|
| 186 |
|
---|
| 187 | System.out.println(username + first_name+ last_name + password + repeatedPassword + email + number + role);
|
---|
| 188 | if(role.equals(Role.ROLE_ADMIN)){
|
---|
| 189 | session.setAttribute("username", username);
|
---|
| 190 | session.setAttribute("first_name", first_name);
|
---|
| 191 | session.setAttribute("last_name", last_name);
|
---|
| 192 | session.setAttribute("password", password);
|
---|
| 193 | session.setAttribute("repeatedPassword", repeatedPassword);
|
---|
| 194 | session.setAttribute("email", email);
|
---|
| 195 | session.setAttribute("number", number);
|
---|
| 196 | response.sendRedirect("/registerWorker");
|
---|
| 197 | }
|
---|
| 198 | else {
|
---|
| 199 | try {
|
---|
| 200 | userService.register(first_name,last_name,username,email,number,password,role);
|
---|
[7215773] | 201 |
|
---|
[5444409] | 202 | }catch (PasswordsDoNotMatchException exception)
|
---|
| 203 | {
|
---|
| 204 | // return "redirect:/register?error=" + exception.getMessage();
|
---|
| 205 | }
|
---|
[7215773] | 206 | response.sendRedirect("/login");
|
---|
[f9cc555] | 207 | }
|
---|
[8a18cf5] | 208 |
|
---|
[e097c1c] | 209 | }
|
---|
[5444409] | 210 | @GetMapping("/registerWorker")
|
---|
| 211 | public String getRegisterWorkerPage(Model model){
|
---|
| 212 | model.addAttribute("cinemas",cinemaService.findAllCinemas());
|
---|
| 213 | model.addAttribute("bodyContent","registerWorker");
|
---|
| 214 | return "master-template";
|
---|
| 215 | }
|
---|
| 216 | @PostMapping("/finishRegister")
|
---|
| 217 | public void handleWorkerRegister(Model model, HttpServletResponse response, HttpSession session,
|
---|
| 218 | @RequestParam String position, @RequestParam String work_hours_from,
|
---|
| 219 | @RequestParam String work_hours_to,@RequestParam Integer id_cinema){
|
---|
| 220 | System.out.println("here?");
|
---|
| 221 | String username = (String) session.getAttribute("username");
|
---|
| 222 | String first_name = (String) session.getAttribute("first_name");
|
---|
| 223 | String last_name = (String) session.getAttribute("last_name");
|
---|
| 224 | String password = (String) session.getAttribute("password");
|
---|
| 225 | String email = (String) session.getAttribute("email");
|
---|
| 226 | String number = (String) session.getAttribute("number");
|
---|
| 227 | Cinema cinema=cinemaService.findCinemaById(id_cinema);
|
---|
| 228 | userService.registerWorker(first_name,last_name,username,email,number,password,position,work_hours_from,work_hours_to,cinema);
|
---|
| 229 | try {
|
---|
| 230 | response.sendRedirect("/login");
|
---|
| 231 | } catch (IOException e) {
|
---|
| 232 | throw new RuntimeException(e);
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
[8d49568] | 235 |
|
---|
[86e187f] | 236 | @GetMapping("/films")
|
---|
| 237 | @Transactional
|
---|
[bcb4acc] | 238 | public String getFilmsPage1(Model model,@RequestParam(required = false) Integer id_cinema, @RequestParam(required = false) Integer id_genre){
|
---|
[86e187f] | 239 | model.addAttribute("cinemas",cinemaService.findAllCinemas());
|
---|
[bcb4acc] | 240 | List<GenreEnum> genres = List.of(GenreEnum.values());
|
---|
| 241 | model.addAttribute("genres", genres);
|
---|
| 242 | List<Film> films = filmService.findAllFilms();
|
---|
[86e187f] | 243 | if (id_cinema!=null) {
|
---|
[bcb4acc] | 244 | films = filmService.getFilmsFromCinema(id_cinema);
|
---|
[86e187f] | 245 | }
|
---|
[bcb4acc] | 246 | if ( id_genre != null){
|
---|
| 247 | List<Film> pom= new ArrayList<>();
|
---|
| 248 | for (int i = 0; i < films.size(); i++) {
|
---|
| 249 | if(films.get(i).getGenre().contains(genres.get(id_genre).name().toLowerCase())){
|
---|
| 250 | pom.add(films.get(i));
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 | films=pom;
|
---|
| 254 | }
|
---|
| 255 | model.addAttribute("films",films);
|
---|
[86e187f] | 256 | model.addAttribute("bodyContent","films");
|
---|
| 257 | return "master-template";
|
---|
| 258 | }
|
---|
[90317ea] | 259 | @Transactional
|
---|
[a554435] | 260 | @GetMapping("/projections")
|
---|
[90317ea] | 261 | public String getProjectionsPage(Model model,@RequestParam(required = false) Integer id_cinema)
|
---|
[a554435] | 262 | {
|
---|
[90317ea] | 263 | model.addAttribute("cinemas",cinemaService.findAllCinemas());
|
---|
| 264 | if (id_cinema!=null) {
|
---|
| 265 | model.addAttribute("films",filmService.getFilmsFromCinemaNow(id_cinema));
|
---|
| 266 | }else{
|
---|
| 267 | List<FilmsReturnTable> pom=new LinkedList<>();
|
---|
| 268 | model.addAttribute("films",filmService.getFilmsNow());
|
---|
| 269 | }
|
---|
[5867520] | 270 | model.addAttribute("bodyContent","projections");
|
---|
[a554435] | 271 | return "master-template";
|
---|
| 272 | }
|
---|
| 273 | @GetMapping("/events")
|
---|
[90317ea] | 274 | @Transactional
|
---|
| 275 | public String getEventsPage(Model model,@RequestParam(required = false) Integer id_cinema)
|
---|
[a554435] | 276 | {
|
---|
[90317ea] | 277 | model.addAttribute("cinemas",cinemaService.findAllCinemas());
|
---|
| 278 | if (id_cinema!=null) {
|
---|
| 279 | model.addAttribute("events",eventService.getEventsFromCinema(id_cinema));
|
---|
| 280 | }else{
|
---|
| 281 | model.addAttribute("events",eventService.getEventsNow());
|
---|
| 282 | }
|
---|
[a554435] | 283 | model.addAttribute("bodyContent","events");
|
---|
| 284 | return "master-template";
|
---|
| 285 | }
|
---|
[302b233] | 286 | @GetMapping("/myTickets")
|
---|
[01a1ca6] | 287 | public String getMyTicketsPage(Model model,HttpServletRequest request)
|
---|
[302b233] | 288 | {
|
---|
[01a1ca6] | 289 | Customer customer=customerService.findByUsername(request.getRemoteUser());
|
---|
[1e7126f] | 290 | List<Ticket> tickets = ticketService.findAllByCustomer(customer);
|
---|
| 291 | List<TicketsCancelClass> ticketsCancelClass = new ArrayList<>();
|
---|
| 292 | LocalDateTime oneDayLater = LocalDateTime.now().plus(1, ChronoUnit.DAYS);
|
---|
| 293 | for (int i = 0; i < tickets.size(); i++) {
|
---|
| 294 | if(tickets.get(i).getProjection().getDate_time_start().isAfter(oneDayLater)){
|
---|
| 295 | ticketsCancelClass.add(new TicketsCancelClass(tickets.get(i),true));
|
---|
| 296 | }else{
|
---|
| 297 | ticketsCancelClass.add(new TicketsCancelClass(tickets.get(i),false));
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 | model.addAttribute("tickets",ticketsCancelClass);
|
---|
[302b233] | 301 | model.addAttribute("bodyContent","myTickets");
|
---|
| 302 | return "master-template";
|
---|
| 303 | }
|
---|
[1e7126f] | 304 |
|
---|
| 305 | @PostMapping("/cancelTicket/{id}")
|
---|
| 306 | public String getSeats(@PathVariable Long id, Model model) {
|
---|
| 307 | ticketService.delete(id.intValue());
|
---|
| 308 | return "redirect:/myTickets";
|
---|
| 309 | }
|
---|
| 310 |
|
---|
[302b233] | 311 | @GetMapping("/addProjection")
|
---|
[1e7126f] | 312 | @Transactional
|
---|
[302b233] | 313 | public String getAddProjectionPage(Model model)
|
---|
| 314 | {
|
---|
| 315 | model.addAttribute("films",filmService.findAllFilms());
|
---|
[1e7126f] | 316 | model.addAttribute("projection_rooms", projectionRoomService.findAllProjectionRooms());
|
---|
| 317 | model.addAttribute("discounts",discountService.getValidDiscounts());
|
---|
[302b233] | 318 | model.addAttribute("bodyContent","addProjection");
|
---|
| 319 | return "master-template";
|
---|
| 320 | }
|
---|
[1e7126f] | 321 | @GetMapping("/addDiscount")
|
---|
| 322 | public String getAddDiscountPage(Model model)
|
---|
| 323 | {
|
---|
| 324 | model.addAttribute("bodyContent","addDiscount");
|
---|
| 325 | return "master-template";
|
---|
| 326 | }
|
---|
[302b233] | 327 | @GetMapping("/addEvent")
|
---|
| 328 | public String getAddEventPage(Model model)
|
---|
| 329 | {
|
---|
| 330 | model.addAttribute("bodyContent","addEvent");
|
---|
| 331 | return "master-template";
|
---|
| 332 | }
|
---|
| 333 | @GetMapping("/addFilm")
|
---|
| 334 | public String getAddFilmPage(Model model)
|
---|
| 335 | {
|
---|
| 336 | model.addAttribute("bodyContent","addFilm");
|
---|
| 337 | return "master-template";
|
---|
| 338 | }
|
---|
| 339 |
|
---|
[1e7126f] | 340 | @PostMapping("/addD")
|
---|
| 341 | public String saveEvent(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate validity,
|
---|
| 342 | @RequestParam String type,
|
---|
| 343 | @RequestParam String code,
|
---|
| 344 | @RequestParam Integer percent)
|
---|
| 345 | {
|
---|
| 346 | discountService.save(code,type,validity,percent);
|
---|
| 347 | return "redirect:/home";
|
---|
| 348 | }
|
---|
| 349 |
|
---|
[302b233] | 350 | @PostMapping("/addP")
|
---|
[1e7126f] | 351 | public String saveProjection(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime date_time_start,
|
---|
| 352 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime date_time_end,
|
---|
[302b233] | 353 | @RequestParam String type_of_technology,
|
---|
[1e7126f] | 354 | @RequestParam Integer id_film,
|
---|
| 355 | @RequestParam Integer id_room,
|
---|
| 356 | @RequestParam Integer id_discount)
|
---|
[302b233] | 357 | {
|
---|
[1e7126f] | 358 | projectionService.save(date_time_start,date_time_end,type_of_technology,id_film,id_room,id_discount);
|
---|
[302b233] | 359 | return "redirect:/home";
|
---|
| 360 | }
|
---|
| 361 | @PostMapping("/addE")
|
---|
| 362 | public String saveEvent(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start_date,
|
---|
| 363 | @RequestParam String theme,
|
---|
| 364 | @RequestParam String duration,
|
---|
[0fb69cc] | 365 | @RequestParam String img_url,
|
---|
[302b233] | 366 | @RequestParam String repeating)
|
---|
| 367 | {
|
---|
[0fb69cc] | 368 | eventService.save(start_date,theme,duration,repeating,img_url);
|
---|
[302b233] | 369 | return "redirect:/home";
|
---|
| 370 | }
|
---|
| 371 | @PostMapping("/addF")
|
---|
| 372 | public String saveFilm(
|
---|
| 373 | @RequestParam String name,
|
---|
| 374 | @RequestParam Integer duration,
|
---|
| 375 | @RequestParam String actors,
|
---|
| 376 | @RequestParam String genre,
|
---|
| 377 | @RequestParam String age_category,
|
---|
| 378 | @RequestParam String url,
|
---|
| 379 | @RequestParam String director,
|
---|
| 380 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start_date,
|
---|
| 381 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end_date
|
---|
| 382 | )
|
---|
| 383 | {
|
---|
| 384 | filmService.save(name,duration,actors,genre,age_category,url,director,start_date,end_date);
|
---|
| 385 | return "redirect:/home";
|
---|
| 386 | }
|
---|
[a554435] | 387 |
|
---|
[448bd84] | 388 | @GetMapping("/workers")
|
---|
| 389 | public String getWorkersPage(Model model)
|
---|
| 390 | {
|
---|
| 391 | model.addAttribute("workers",workerService.findAllWorkers());
|
---|
| 392 | model.addAttribute("bodyContent", "workers");
|
---|
| 393 | return "master-template";
|
---|
| 394 | }
|
---|
[fc448f5] | 395 |
|
---|
| 396 | @GetMapping("/addEventToCinema")
|
---|
| 397 | public String getCinemaOrganizesEventPage(Model model)
|
---|
| 398 | {
|
---|
| 399 | model.addAttribute("cinemas",cinemaService.findAllCinemas());
|
---|
| 400 | model.addAttribute("events",eventService.findAllEvents());
|
---|
| 401 | model.addAttribute("bodyContent","addEventToCinema");
|
---|
| 402 | return "master-template";
|
---|
| 403 | }
|
---|
[1e7126f] | 404 |
|
---|
[fc448f5] | 405 | @PostMapping("/addCinemaOrganizesEvent")
|
---|
| 406 | public String saveCinemaOrganizesEvent(@RequestParam Integer id_cinema,
|
---|
| 407 | @RequestParam Integer id_event)
|
---|
| 408 | {
|
---|
| 409 |
|
---|
| 410 | cinemaOrganizesEventService.save(id_cinema,id_event);
|
---|
[1e7126f] | 411 | return "redirect:/home";
|
---|
[fc448f5] | 412 | }
|
---|
[03fd098] | 413 | @GetMapping("/addFilmToCinema")
|
---|
| 414 | public String getCinemaPlaysFilmPage(Model model)
|
---|
| 415 | {
|
---|
| 416 | model.addAttribute("cinemas",cinemaService.findAllCinemas());
|
---|
| 417 | model.addAttribute("films",filmService.findAllFilms());
|
---|
| 418 | model.addAttribute("bodyContent","addFilmToCinema");
|
---|
| 419 | return "master-template";
|
---|
| 420 | }
|
---|
| 421 | @PostMapping("/addCinemaPlaysFilm")
|
---|
| 422 | public String saveCinemaPlaysFilm(@RequestParam Integer id_cinema,
|
---|
| 423 | @RequestParam Integer id_film)
|
---|
| 424 | {
|
---|
| 425 | cinemaPlaysFilmService.save(id_cinema,id_film);
|
---|
| 426 | return "redirect:/home";
|
---|
| 427 | }
|
---|
[9eba1fb] | 428 |
|
---|
| 429 | @GetMapping("/getProjection/{id}")
|
---|
| 430 | public String getProjection(@PathVariable Integer id_projection,Model model)
|
---|
| 431 | {
|
---|
| 432 | List<Projection_Room> projectionRooms = null;
|
---|
| 433 | Projection projection=projectionService.findById(id_projection);
|
---|
| 434 |
|
---|
| 435 |
|
---|
[64ee7f4] | 436 | List<ProjectionIsPlayedInRoom> p= projectionIsPlayedInRoomService.getProjectionPlayedInRoom(id_projection);
|
---|
[9eba1fb] | 437 |
|
---|
| 438 | model.addAttribute("projection",projection);
|
---|
| 439 | model.addAttribute("p_rooms",projectionRooms);
|
---|
| 440 | model.addAttribute("bodyContent","projectionDetails");
|
---|
| 441 | return "master-template";
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | @PostMapping("/makeReservation")
|
---|
[00fa72f] | 445 | @Transactional
|
---|
[01a1ca6] | 446 | public String createTicketForReservation(@RequestParam Long film,@RequestParam Long projection,@RequestParam Long id_seat,@RequestParam String discount,HttpServletRequest request, HttpServletResponse respons)
|
---|
[9eba1fb] | 447 | {
|
---|
[00fa72f] | 448 | Ticket t;
|
---|
[01a1ca6] | 449 | Customer customer=customerService.findByUsername(request.getRemoteUser());
|
---|
[00fa72f] | 450 | Projection projection1=projectionService.findById(projection.intValue());
|
---|
[8a18cf5] | 451 | if(projection1.getDiscount()!=null && projection1.getDiscount().getCode().equals(discount)){
|
---|
[01a1ca6] | 452 | t=ticketService.saveWithDiscount(LocalDate.now(),customer,projection1,projection1.getDiscount(),seatService.getSeatById(id_seat.intValue()).get());
|
---|
[8a18cf5] | 453 | Integer price=ticketService.priceForTicket(t.getId_ticket());
|
---|
| 454 | price+=seatService.getSeatById(id_seat.intValue()).get().getCategory().getExtra_amount();
|
---|
| 455 | price-=(price*projection1.getDiscount().getPercent())/100;
|
---|
| 456 | t.setPrice(price);
|
---|
[00fa72f] | 457 | }else{
|
---|
[01a1ca6] | 458 | t=ticketService.saveWithout(LocalDate.now(),customer,projection1,seatService.getSeatById(id_seat.intValue()).get());
|
---|
[8a18cf5] | 459 | Integer price=ticketService.priceForTicket(t.getId_ticket());
|
---|
| 460 | price+=seatService.getSeatById(id_seat.intValue()).get().getCategory().getExtra_amount();
|
---|
| 461 | t.setPrice(price);
|
---|
[00fa72f] | 462 | }
|
---|
[8a18cf5] | 463 |
|
---|
[01a1ca6] | 464 | return "redirect:/myTickets";
|
---|
[9eba1fb] | 465 | }
|
---|
[73f0dbc] | 466 | @PostMapping("/addRating/{id}")
|
---|
| 467 | public String addRating(@RequestParam Long rate,@PathVariable Long id,HttpServletRequest request, HttpServletResponse respons)
|
---|
| 468 | {
|
---|
| 469 | Customer customer=customerService.findByUsername(request.getRemoteUser());
|
---|
| 470 | System.out.println(customer.getFirst_name());
|
---|
| 471 | customerRatesFilmService.addRating(customer.getId_user(),Integer.valueOf(id.intValue()),Integer.valueOf(rate.intValue()));
|
---|
| 472 | return "redirect:/home/getFilm/"+id;
|
---|
| 473 | }
|
---|
[7926d68] | 474 | @GetMapping("/profileWorker")
|
---|
| 475 | public String getWorkerProfile(Model model,HttpServletRequest request)
|
---|
| 476 | {
|
---|
| 477 | Worker worker=workerService.getWorkerByUsername(request.getRemoteUser());
|
---|
| 478 | model.addAttribute("worker",worker);
|
---|
| 479 | model.addAttribute("bodyContent", "profileWorker");
|
---|
| 480 | return "master-template";
|
---|
| 481 | }
|
---|
| 482 | @GetMapping("/profileUser")
|
---|
[ef84238] | 483 | @Transactional
|
---|
[7926d68] | 484 | public String getUserProfile(Model model,HttpServletRequest request)
|
---|
| 485 | {
|
---|
| 486 | Customer customer=customerService.findByUsername(request.getRemoteUser());
|
---|
| 487 | System.out.println(customer.getFirst_name());
|
---|
[ef84238] | 488 | List<Event> events=eventService.getEventsForCustomer(customer.getId_user());
|
---|
[7926d68] | 489 | model.addAttribute("customer",customer);
|
---|
[ef84238] | 490 | model.addAttribute("events",events);
|
---|
[7926d68] | 491 | model.addAttribute("bodyContent", "profileUser");
|
---|
| 492 | return "master-template";
|
---|
| 493 | }
|
---|
[ef84238] | 494 | @PostMapping("/addInterestedEvent/{id}")
|
---|
| 495 | public String addInterestedEvent(@PathVariable Long id,HttpServletRequest request, HttpServletResponse respons)
|
---|
| 496 | {
|
---|
| 497 | Customer customer=customerService.findByUsername(request.getRemoteUser());
|
---|
| 498 | customerIsInterestedInEventService.add(customer.getId_user(),Integer.valueOf(id.intValue()));
|
---|
| 499 | return "redirect:/profileUser";
|
---|
| 500 | }
|
---|
| 501 | @PostMapping("/deleteInterestedEvent/{id}")
|
---|
| 502 | public String deleteInterestedEvent(@PathVariable Long id,HttpServletRequest request, HttpServletResponse respons)
|
---|
| 503 | {
|
---|
| 504 | Customer customer=customerService.findByUsername(request.getRemoteUser());
|
---|
| 505 | Event event=eventService.getEventById(id).get();
|
---|
| 506 | customerIsInterestedInEventService.delete(customer,event);
|
---|
| 507 | return "redirect:/profileUser";
|
---|
| 508 | }
|
---|
[ac25203] | 509 | }
|
---|