source: source/MovieZilla-master/src/main/java/com/example/demo/controller/ReserveController.java

Last change on this file was fc7ec52, checked in by darkopopovski <darkopopovski39@…>, 2 years ago

all files

  • Property mode set to 100644
File size: 4.8 KB
Line 
1package com.example.demo.controller;
2
3
4import com.example.demo.model.Auditorium;
5import com.example.demo.model.Client.Client;
6import com.example.demo.model.MovieProjection;
7import com.example.demo.model.PaymentType;
8import com.example.demo.model.Reservation.Reservations;
9import com.example.demo.model.Seat.Seat;
10import com.example.demo.repository.*;
11import org.springframework.security.access.prepost.PreAuthorize;
12import org.springframework.stereotype.Controller;
13import org.springframework.ui.Model;
14import org.springframework.web.bind.annotation.PostMapping;
15import org.springframework.web.bind.annotation.RequestMapping;
16import org.springframework.web.bind.annotation.RequestParam;
17
18import java.sql.Date;
19import java.time.LocalDateTime;
20import java.time.format.DateTimeFormatter;
21import java.util.List;
22
23@Controller
24@RequestMapping("/reserve")
25public class ReserveController {
26
27
28 private final SeatRepository seatRepository;
29 private final AuditoriumRepository auditoriumRepository;
30 private final PaymentTypeRepository paymentTypeRepository;
31 private final MovieProjectionRepository movieProjectionRepository;
32 private final ClientRepository clientRepository;
33 private final ReservationsRepository reservationsRepository;
34
35 public ReserveController(SeatRepository seatRepository, AuditoriumRepository auditoriumRepository, PaymentTypeRepository paymentTypeRepository, MovieProjectionRepository movieProjectionRepository, ClientRepository clientRepository, ReservationsRepository reservationsRepository) {
36 this.seatRepository = seatRepository;
37 this.auditoriumRepository = auditoriumRepository;
38 this.paymentTypeRepository = paymentTypeRepository;
39 this.movieProjectionRepository = movieProjectionRepository;
40 this.clientRepository = clientRepository;
41 this.reservationsRepository = reservationsRepository;
42 }
43// @PreAuthorize("hasRole('ROLE_EMPLOYEE')" +
44// " || hasRole('Client')" )
45 @RequestMapping("/projection")
46 public String viewReservationDetail(@RequestParam(value = "projection_id", required = false) Integer projection_id, Model model) {
47 List<Seat> seats11 = seatRepository.SelectionByProjection(projection_id);
48 List<Seat> seatsAll = seatRepository.selectFreeSeatsByProjection(projection_id);
49 List<Auditorium> auditoriums = auditoriumRepository.SelectAuditoriumsByProjection(projection_id);
50 List<PaymentType> paymentType = paymentTypeRepository.findAll();
51 List<MovieProjection> projections = movieProjectionRepository.findProjectionsById(projection_id);
52 List<Client> client = clientRepository.findAll();
53 List<Reservations> reservations = reservationsRepository.findAll();
54 model.addAttribute("projection_id",projection_id);
55 model.addAttribute("seatsAll",seatsAll);
56 model.addAttribute("projections",projections);
57 model.addAttribute("paymentType", paymentType);
58 model.addAttribute("auditorium",auditoriums);
59 model.addAttribute("seats11",seats11);
60 model.addAttribute("client",client);
61 model.addAttribute("reservation",reservations);
62
63 return "reserve";
64 }
65// @PreAuthorize("hasRole('ROLE_EMPLOYEE')" +
66// " && hasRole('Client')" )
67 @PostMapping("/projection/add")
68 public String addReservation(
69 @RequestParam(value = "auditorium_id", required = false) Integer auditorium_id, Model model,
70 @RequestParam(value = "payment_type_id", required = false) Integer payment_type_id,
71 @RequestParam(value = "seat_id", required = false) Integer seat_id,
72 @RequestParam(value = "projection_id", required = false) Integer projection_id,
73 @RequestParam(value = "user_id", required = false) Integer user_id
74 ){
75
76 PaymentType paymentType1337 = paymentTypeRepository.findById(payment_type_id).get();
77 Seat seat = seatRepository.findSeatAuditorium(seat_id,auditorium_id).get();
78 MovieProjection movieProjection = movieProjectionRepository.findById(projection_id).get();
79 Client client = clientRepository.findClient(user_id).get();
80 Reservations reservations = new Reservations();
81 LocalDateTime localDateTime = LocalDateTime.now();
82 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy");
83 //////////ID-FUNCTION/////////////
84 List<Reservations> reservationsList = reservationsRepository.findAll();
85 Integer myID = reservationsList.size()+2;
86 reservations.setReservation_id(myID);
87 //////////ID-FUNCTION//////////////
88 reservations.setReservation_date(localDateTime);
89 reservations.setPaymentType(paymentType1337);
90 reservations.setSeat(seat);
91 reservations.setClient(client);
92 reservations.setMovieProjection(movieProjection);
93 this.reservationsRepository.save(reservations);
94 return "redirect:/movies";
95 }
96
97
98}
Note: See TracBrowser for help on using the repository browser.