Changeset 1e7126f for src/main/java/com/example/moviezone/web
- Timestamp:
- 08/24/23 02:28:14 (16 months ago)
- Branches:
- master
- Children:
- bcb4acc
- Parents:
- 40935d3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/web/HomeController.java
r40935d3 r1e7126f 3 3 4 4 import com.example.moviezone.model.*; 5 import com.example.moviezone.model.enums.GenreEnum; 5 6 import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException; 6 7 … … 10 11 import com.example.moviezone.model.procedures.FilmsReturnTable; 11 12 13 import com.example.moviezone.model.procedures.TicketsCancelClass; 12 14 import com.example.moviezone.service.*; 13 15 import org.springframework.format.annotation.DateTimeFormat; … … 22 24 import java.io.IOException; 23 25 import java.time.LocalDate; 26 import java.time.LocalDateTime; 27 import java.time.temporal.ChronoUnit; 28 import java.util.ArrayList; 24 29 import java.util.Collections; 25 30 import java.util.LinkedList; … … 47 52 private final Projection_RoomService projectionRoomService; 48 53 private final CustomerIsInterestedInEventService customerIsInterestedInEventService; 49 50 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) 54 private final DiscountService discountService; 55 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) 51 57 { 52 58 … … 67 73 this.projectionRoomService = projectionRoomService; 68 74 this.customerIsInterestedInEventService = customerIsInterestedInEventService; 75 this.discountService = discountService; 69 76 } 70 77 … … 127 134 model.addAttribute("category",category); 128 135 129 List<Seat> seats=seatService.findAllByRoomAndCategory(projection RoomService.getRoomByProjection(projection.getId_projection()).get(0),category);136 List<Seat> seats=seatService.findAllByRoomAndCategory(projection,projectionRoomService.getRoomByProjection(projection.getId_projection()).get(0),category); 130 137 model.addAttribute("seats",seats); 131 138 model.addAttribute("bodyContent", "seats"); … … 231 238 public String getFilmsPage1(Model model,@RequestParam(required = false) Integer id_cinema){ 232 239 model.addAttribute("cinemas",cinemaService.findAllCinemas()); 240 model.addAttribute("genres", GenreEnum.values()); 233 241 if (id_cinema!=null) { 234 242 model.addAttribute("films",filmService.getFilmsFromCinema(id_cinema)); … … 272 280 { 273 281 Customer customer=customerService.findByUsername(request.getRemoteUser()); 274 model.addAttribute("tickets",ticketService.findAllByCustomer(customer)); 282 List<Ticket> tickets = ticketService.findAllByCustomer(customer); 283 List<TicketsCancelClass> ticketsCancelClass = new ArrayList<>(); 284 LocalDateTime oneDayLater = LocalDateTime.now().plus(1, ChronoUnit.DAYS); 285 for (int i = 0; i < tickets.size(); i++) { 286 if(tickets.get(i).getProjection().getDate_time_start().isAfter(oneDayLater)){ 287 ticketsCancelClass.add(new TicketsCancelClass(tickets.get(i),true)); 288 }else{ 289 ticketsCancelClass.add(new TicketsCancelClass(tickets.get(i),false)); 290 } 291 } 292 model.addAttribute("tickets",ticketsCancelClass); 275 293 model.addAttribute("bodyContent","myTickets"); 276 294 return "master-template"; 277 295 } 296 297 @PostMapping("/cancelTicket/{id}") 298 public String getSeats(@PathVariable Long id, Model model) { 299 ticketService.delete(id.intValue()); 300 return "redirect:/myTickets"; 301 } 302 278 303 @GetMapping("/addProjection") 304 @Transactional 279 305 public String getAddProjectionPage(Model model) 280 306 { 281 307 model.addAttribute("films",filmService.findAllFilms()); 308 model.addAttribute("projection_rooms", projectionRoomService.findAllProjectionRooms()); 309 model.addAttribute("discounts",discountService.getValidDiscounts()); 282 310 model.addAttribute("bodyContent","addProjection"); 283 311 return "master-template"; 284 312 } 285 286 313 @GetMapping("/addDiscount") 314 public String getAddDiscountPage(Model model) 315 { 316 model.addAttribute("bodyContent","addDiscount"); 317 return "master-template"; 318 } 287 319 @GetMapping("/addEvent") 288 320 public String getAddEventPage(Model model) … … 298 330 } 299 331 332 @PostMapping("/addD") 333 public String saveEvent(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate validity, 334 @RequestParam String type, 335 @RequestParam String code, 336 @RequestParam Integer percent) 337 { 338 discountService.save(code,type,validity,percent); 339 return "redirect:/home"; 340 } 341 300 342 @PostMapping("/addP") 301 public String saveProjection(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE ) LocalDate date_time_start,302 @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE ) LocalDate date_time_end,343 public String saveProjection(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime date_time_start, 344 @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime date_time_end, 303 345 @RequestParam String type_of_technology, 304 @RequestParam Integer id_film) 305 { 306 projectionService.save(date_time_start,date_time_end,type_of_technology,id_film); 346 @RequestParam Integer id_film, 347 @RequestParam Integer id_room, 348 @RequestParam Integer id_discount) 349 { 350 projectionService.save(date_time_start,date_time_end,type_of_technology,id_film,id_room,id_discount); 307 351 return "redirect:/home"; 308 352 } … … 350 394 return "master-template"; 351 395 } 396 352 397 @PostMapping("/addCinemaOrganizesEvent") 353 398 public String saveCinemaOrganizesEvent(@RequestParam Integer id_cinema, … … 356 401 357 402 cinemaOrganizesEventService.save(id_cinema,id_event); 358 403 return "redirect:/home"; 359 404 } 360 405 @GetMapping("/addFilmToCinema")
Note:
See TracChangeset
for help on using the changeset viewer.