Ignore:
Timestamp:
08/24/23 02:28:14 (15 months ago)
Author:
DenicaKj <dkorvezir@…>
Branches:
master
Children:
bcb4acc
Parents:
40935d3
Message:

fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/web/HomeController.java

    r40935d3 r1e7126f  
    33
    44import com.example.moviezone.model.*;
     5import com.example.moviezone.model.enums.GenreEnum;
    56import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException;
    67
     
    1011import com.example.moviezone.model.procedures.FilmsReturnTable;
    1112
     13import com.example.moviezone.model.procedures.TicketsCancelClass;
    1214import com.example.moviezone.service.*;
    1315import org.springframework.format.annotation.DateTimeFormat;
     
    2224import java.io.IOException;
    2325import java.time.LocalDate;
     26import java.time.LocalDateTime;
     27import java.time.temporal.ChronoUnit;
     28import java.util.ArrayList;
    2429import java.util.Collections;
    2530import java.util.LinkedList;
     
    4752private final Projection_RoomService projectionRoomService;
    4853private 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)
     54private 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)
    5157    {
    5258
     
    6773        this.projectionRoomService = projectionRoomService;
    6874        this.customerIsInterestedInEventService = customerIsInterestedInEventService;
     75        this.discountService = discountService;
    6976    }
    7077
     
    127134        model.addAttribute("category",category);
    128135
    129         List<Seat> seats=seatService.findAllByRoomAndCategory(projectionRoomService.getRoomByProjection(projection.getId_projection()).get(0),category);
     136        List<Seat> seats=seatService.findAllByRoomAndCategory(projection,projectionRoomService.getRoomByProjection(projection.getId_projection()).get(0),category);
    130137        model.addAttribute("seats",seats);
    131138        model.addAttribute("bodyContent", "seats");
     
    231238    public String getFilmsPage1(Model model,@RequestParam(required = false) Integer id_cinema){
    232239        model.addAttribute("cinemas",cinemaService.findAllCinemas());
     240        model.addAttribute("genres", GenreEnum.values());
    233241        if (id_cinema!=null) {
    234242            model.addAttribute("films",filmService.getFilmsFromCinema(id_cinema));
     
    272280    {
    273281        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);
    275293        model.addAttribute("bodyContent","myTickets");
    276294        return "master-template";
    277295    }
     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
    278303    @GetMapping("/addProjection")
     304    @Transactional
    279305    public  String getAddProjectionPage(Model model)
    280306    {
    281307        model.addAttribute("films",filmService.findAllFilms());
     308        model.addAttribute("projection_rooms", projectionRoomService.findAllProjectionRooms());
     309        model.addAttribute("discounts",discountService.getValidDiscounts());
    282310        model.addAttribute("bodyContent","addProjection");
    283311        return "master-template";
    284312    }
    285 
    286 
     313    @GetMapping("/addDiscount")
     314    public  String getAddDiscountPage(Model model)
     315    {
     316        model.addAttribute("bodyContent","addDiscount");
     317        return "master-template";
     318    }
    287319    @GetMapping("/addEvent")
    288320    public  String getAddEventPage(Model model)
     
    298330    }
    299331
     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
    300342    @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,
    303345                                 @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);
    307351         return "redirect:/home";
    308352    }
     
    350394        return "master-template";
    351395    }
     396
    352397    @PostMapping("/addCinemaOrganizesEvent")
    353398    public String saveCinemaOrganizesEvent(@RequestParam Integer id_cinema,
     
    356401
    357402       cinemaOrganizesEventService.save(id_cinema,id_event);
    358         return "redirect:/home";
     403       return "redirect:/home";
    359404    }
    360405    @GetMapping("/addFilmToCinema")
Note: See TracChangeset for help on using the changeset viewer.