Changeset 1e7126f for src/main/java
- Timestamp:
- 08/24/23 02:28:14 (16 months ago)
- Branches:
- master
- Children:
- bcb4acc
- Parents:
- 40935d3
- Location:
- src/main/java/com/example/moviezone
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/config/WebSecurityConfig.java
r40935d3 r1e7126f 34 34 .antMatchers("/","/films","/home/projections","/home/events","/home/getProjections/**","/home/films","/home/getFilm/**","/getFilm/**","/home/getEvent/**","/getEvent/**","/login","/events","/projections" ,"/home", "/assets/**", "/register", "/registerWorker","/api/**").permitAll() 35 35 .antMatchers("/","/finishRegister","/registerWorker","/films","/home/projections","/home/events","/home/getProjections/**","/home/films","/home/getFilm/**","/getFilm/**","/home/getEvent/**","/getEvent/**","redirect:/login","/login","/events","/projections" ,"/home", "/assets/**", "/register", "/api/**").permitAll() 36 .antMatchers("/home/getSeats/**","/myTickets","/home/addInterestedEvent/**","/home/deleteInterestedEvent/**","/home/addRating/**","/addRating/**","/getProjection/**","/home/makeReservation","/profileUser").hasRole("USER") 36 .antMatchers("/home/getSeats/**","/myTickets","/home/addInterestedEvent/**","/home/deleteInterestedEvent/**","/home/addRating/**","/addRating/**","/getProjection/**","/home/makeReservation","/profileUser","/cancelTicket/**").hasRole("USER") 37 .antMatchers("/profileWorker").hasRole("WORKER") 37 38 .antMatchers("/**").hasRole("ADMIN") 38 39 .anyRequest() -
src/main/java/com/example/moviezone/model/Discount.java
r40935d3 r1e7126f 29 29 String type; 30 30 Integer percent; 31 32 public Discount() { 33 } 34 35 public Discount(LocalDate validity, String code, String type, Integer percent) { 36 this.validity = validity; 37 this.code = code; 38 this.type = type; 39 this.percent = percent; 40 } 31 41 } -
src/main/java/com/example/moviezone/model/Projection.java
r40935d3 r1e7126f 8 8 9 9 import java.time.LocalDate; 10 import java.time.LocalDateTime; 10 11 11 12 @Getter … … 20 21 Integer id_projection; 21 22 22 LocalDate date_time_start;23 LocalDateTime date_time_start; 23 24 String type_of_technology; 24 LocalDate date_time_end;25 LocalDateTime date_time_end; 25 26 @ManyToOne 26 27 @JoinColumn(name = "id_film") … … 33 34 Discount discount; 34 35 35 public Projection(LocalDate date_time_start, String type_of_technology, LocalDate date_time_end, Film film) {36 public Projection(LocalDateTime date_time_start, String type_of_technology, LocalDateTime date_time_end, Film film, Discount discount) { 36 37 this.date_time_start = date_time_start; 37 38 this.type_of_technology = type_of_technology; 38 39 this.date_time_end = date_time_end; 39 40 this.film = film; 41 this.discount = discount; 40 42 } 41 43 -
src/main/java/com/example/moviezone/model/Role.java
r40935d3 r1e7126f 6 6 public enum Role implements GrantedAuthority { 7 7 8 ROLE_USER, ROLE_ADMIN ;8 ROLE_USER, ROLE_ADMIN, ROLE_WORKER; 9 9 10 10 @Override -
src/main/java/com/example/moviezone/model/Worker.java
r40935d3 r1e7126f 59 59 @Override 60 60 public Collection<? extends GrantedAuthority> getAuthorities() { 61 return Collections.singletonList(Role.ROLE_ADMIN); 61 if (position.equalsIgnoreCase("admin")) 62 return Collections.singletonList(Role.ROLE_ADMIN); 63 else{ 64 return Collections.singletonList(Role.ROLE_WORKER); 65 } 62 66 } 63 67 -
src/main/java/com/example/moviezone/model/enums/GenreEnum.java
r40935d3 r1e7126f 1 package com.example.moviezone.model;public enum GenreEnum { 1 package com.example.moviezone.model.enums; 2 3 public enum GenreEnum { 4 Animation, 5 Adventure, 6 Comedy, 7 Fantasy, 8 Crime, 9 Drama, 10 Thriller 2 11 } -
src/main/java/com/example/moviezone/model/manytomany/ProjectionIsPlayedInRoom.java
r40935d3 r1e7126f 30 30 Integer idroom; 31 31 32 32 public ProjectionIsPlayedInRoom(Integer idprojection, Integer idroom) { 33 this.idprojection = idprojection; 34 this.idroom = idroom; 35 } 33 36 } -
src/main/java/com/example/moviezone/model/procedures/TicketsCancelClass.java
r40935d3 r1e7126f 1 package com.example.moviezone.model.procedures;public class TicketsCancelClass { 1 package com.example.moviezone.model.procedures; 2 3 import com.example.moviezone.model.Ticket; 4 5 public class TicketsCancelClass { 6 public Ticket ticket; 7 public boolean canCancel; 8 9 public TicketsCancelClass(Ticket ticket, boolean canCancel) { 10 this.ticket = ticket; 11 this.canCancel = canCancel; 12 } 13 14 public TicketsCancelClass() { 15 } 2 16 } -
src/main/java/com/example/moviezone/repository/DiscountRepository.java
r40935d3 r1e7126f 2 2 3 3 import com.example.moviezone.model.Discount; 4 import com.example.moviezone.model.Projection; 4 5 import org.springframework.data.jpa.repository.JpaRepository; 6 import org.springframework.data.jpa.repository.query.Procedure; 5 7 8 import javax.transaction.Transactional; 9 import java.util.List; 10 11 @Transactional 6 12 public interface DiscountRepository extends JpaRepository<Discount,Integer> { 13 @Procedure("project.getValidDiscounts") 14 List<Discount> getValidDiscounts(); 7 15 } -
src/main/java/com/example/moviezone/repository/ProjectionRepository.java
r40935d3 r1e7126f 12 12 @Procedure("project.getProjectionsForFilms") 13 13 List<Projection> getProjectionsForFilms(int id); 14 @Procedure("project.getProjectionsNow") 15 List<Projection> getProjectionsNow(); 14 16 } -
src/main/java/com/example/moviezone/service/CustomerService.java
r40935d3 r1e7126f 7 7 import java.util.Optional; 8 8 9 @Repository10 9 public interface CustomerService { 11 10 List<Customer> findAllCustomers(); -
src/main/java/com/example/moviezone/service/DiscountService.java
r40935d3 r1e7126f 1 package com.example.moviezone.service;public interface DiscountService { 1 package com.example.moviezone.service; 2 3 import com.example.moviezone.model.Discount; 4 import org.springframework.stereotype.Repository; 5 6 import java.time.LocalDate; 7 import java.util.List; 8 9 10 public interface DiscountService { 11 Discount save(String code, String type, LocalDate validity, Integer percent); 12 List<Discount> getValidDiscounts(); 2 13 } -
src/main/java/com/example/moviezone/service/Impl/DiscountServiceImpl.java
r40935d3 r1e7126f 1 package com.example.moviezone.service.Impl;public class DiscountServiceImpl { 1 package com.example.moviezone.service.Impl; 2 3 import com.example.moviezone.model.Discount; 4 import com.example.moviezone.repository.DiscountRepository; 5 import com.example.moviezone.service.DiscountService; 6 import org.springframework.stereotype.Service; 7 8 import java.time.LocalDate; 9 import java.util.List; 10 11 @Service 12 public class DiscountServiceImpl implements DiscountService { 13 private final DiscountRepository discountRepository; 14 15 public DiscountServiceImpl(DiscountRepository discountRepository) { 16 this.discountRepository = discountRepository; 17 } 18 19 @Override 20 public Discount save(String code, String type, LocalDate validity, Integer percent) { 21 return discountRepository.save(new Discount(validity,code,type,percent)); 22 } 23 24 @Override 25 public List<Discount> getValidDiscounts() { 26 return discountRepository.getValidDiscounts(); 27 } 2 28 } -
src/main/java/com/example/moviezone/service/Impl/ProjectionServiceImpl.java
r40935d3 r1e7126f 1 1 package com.example.moviezone.service.Impl; 2 2 3 import com.example.moviezone.model.Discount; 3 4 import com.example.moviezone.model.Film; 4 5 import com.example.moviezone.model.Projection; 6 import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom; 7 import com.example.moviezone.repository.DiscountRepository; 5 8 import com.example.moviezone.repository.FilmRepository; 9 import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository; 6 10 import com.example.moviezone.repository.ProjectionRepository; 7 11 import com.example.moviezone.service.ProjectionService; … … 9 13 10 14 import java.time.LocalDate; 15 import java.time.LocalDateTime; 11 16 import java.util.List; 12 17 … … 14 19 public class ProjectionServiceImpl implements ProjectionService { 15 20 private final ProjectionRepository projectionRepository; 21 private final ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository; 16 22 private final FilmRepository filmRepository; 17 public ProjectionServiceImpl(ProjectionRepository projectionRepository, FilmRepository filmRepository) { 23 private final DiscountRepository discountRepository; 24 public ProjectionServiceImpl(ProjectionRepository projectionRepository, ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository, FilmRepository filmRepository, DiscountRepository discountRepository) { 18 25 this.projectionRepository = projectionRepository; 26 this.projectionIsPlayedInRoomRepository = projectionIsPlayedInRoomRepository; 19 27 this.filmRepository = filmRepository; 28 this.discountRepository = discountRepository; 20 29 } 21 30 … … 31 40 32 41 @Override 42 public List<Projection> getProjectionsNow() { 43 return projectionRepository.getProjectionsNow(); 44 } 45 46 @Override 33 47 public Projection findById(Integer id_projection) { 34 48 return projectionRepository.findById(id_projection).orElseThrow(RuntimeException::new); … … 37 51 38 52 @Override 39 public Projection save(LocalDate date_time_start, LocalDate date_time_end, String type_of_technology, Integer id_film) {53 public Projection save(LocalDateTime date_time_start, LocalDateTime date_time_end, String type_of_technology, Integer id_film, Integer id_room, Integer id_discount) { 40 54 Film film=filmRepository.findById(id_film).orElseThrow(RuntimeException::new); 41 return projectionRepository.save(new Projection(date_time_start,type_of_technology,date_time_end,film)); 55 Discount discount = discountRepository.findById(id_discount).orElseThrow(RuntimeException::new); 56 Projection projection = projectionRepository.save(new Projection(date_time_start,type_of_technology,date_time_end,film,discount)); 57 projectionIsPlayedInRoomRepository.save(new ProjectionIsPlayedInRoom(projection.getId_projection(),id_room)); 58 return projection; 42 59 } 43 60 -
src/main/java/com/example/moviezone/service/Impl/SeatServiceImpl.java
r40935d3 r1e7126f 1 1 package com.example.moviezone.service.Impl; 2 2 3 import com.example.moviezone.model.Category; 4 import com.example.moviezone.model.Projection_Room; 5 import com.example.moviezone.model.Seat; 6 import com.example.moviezone.model.Ticket; 3 import com.example.moviezone.model.*; 7 4 import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom; 8 5 import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository; … … 43 40 44 41 @Override 45 public List<Seat> findAllByRoomAndCategory(Projection _Room projectionRoom, Category category) {42 public List<Seat> findAllByRoomAndCategory(Projection projection, Projection_Room projectionRoom, Category category) { 46 43 List<Ticket> tickets=ticketService.findAllTickets(); 47 44 List<Seat> seats=seatRepository.findAllByCategoryAndProjection(category,projectionRoom); 48 List<Seat> s=new ArrayList<>(); 49 List<Projection_Room> projection_rooms=new ArrayList<>(); 45 50 46 for (int i = 0; i < tickets.size(); i++) { 51 List<ProjectionIsPlayedInRoom> projectionIsPlayedInRooms= projectionIsPlayedInRoomRepository.findAllByProjectionId(tickets.get(i).getProjection().getId_projection()); 52 for (int j = 0; j < projectionIsPlayedInRooms.size(); j++) { 53 projection_rooms.add(projection_roomRepository.getById(projectionIsPlayedInRooms.get(j).getIdroom())); 47 if(tickets.get(i).getProjection()==projection){ 48 if(seats.contains(tickets.get(i).getSeat())){ 49 seats.remove(tickets.get(i).getSeat()); 50 } 54 51 } 55 52 } 56 int f=0; 57 for (int i = 0; i < seats.size(); i++) { 58 for (int j = 0; j < tickets.size(); j++) { 59 if(seats.get(i).getId_seat().equals(tickets.get(j).getSeat().getId_seat())){ 60 for (int k = 0; k < projection_rooms.size(); k++) { 61 if(seats.get(i).getProjection().getId_room().equals(projection_rooms.get(k).getId_room())) 62 f=1; 63 } 64 } 65 66 } 67 68 if(f==0){ 69 s.add(seats.get(i)); 70 } 71 f=0; 72 } 73 return s; 53 return seats; 74 54 } 75 55 -
src/main/java/com/example/moviezone/service/Impl/TicketServiceImpl.java
r40935d3 r1e7126f 48 48 return ticketRepository.getPriceForTicket(id); 49 49 } 50 51 @Override 52 public void delete(int id) { 53 ticketRepository.deleteById(id); 54 } 50 55 } -
src/main/java/com/example/moviezone/service/ProjectionService.java
r40935d3 r1e7126f 5 5 6 6 import java.time.LocalDate; 7 import java.time.LocalDateTime; 7 8 import java.util.List; 8 9 … … 10 11 List<Projection> findAllProjections(); 11 12 List<Projection> getProjectionsForFilms(int id); 13 List<Projection> getProjectionsNow(); 12 14 Projection findById(Integer id_projection); 13 Projection save(LocalDate date_time_start,LocalDate date_time_end, String type_of_technology, Integer id_film);15 Projection save(LocalDateTime date_time_start, LocalDateTime date_time_end, String type_of_technology, Integer id_film, Integer id_room, Integer id_discount); 14 16 } -
src/main/java/com/example/moviezone/service/SeatService.java
r40935d3 r1e7126f 2 2 3 3 import com.example.moviezone.model.Category; 4 import com.example.moviezone.model.Projection; 4 5 import com.example.moviezone.model.Projection_Room; 5 6 import com.example.moviezone.model.Seat; … … 11 12 List<Seat> findAllSeats(); 12 13 List<Seat> findAllByProjection_Room(Projection_Room projection_room); 13 List<Seat> findAllByRoomAndCategory(Projection _Room projectionRoom, Category category);14 List<Seat> findAllByRoomAndCategory(Projection projection, Projection_Room projectionRoom, Category category); 14 15 Optional<Seat> getSeatById(int id); 15 16 } -
src/main/java/com/example/moviezone/service/TicketService.java
r40935d3 r1e7126f 13 13 Ticket save(long price,Customer customer); 14 14 Integer priceForTicket(int id); 15 void delete(int id); 15 16 } -
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.