Changeset 00fa72f for src/main/java
- Timestamp:
- 02/09/23 14:06:45 (23 months ago)
- Branches:
- master
- Children:
- 6a9006d, a9ffccd
- Parents:
- 0ba5d1a
- Location:
- src/main/java/com/example/moviezone
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/model/Category.java
r0ba5d1a r00fa72f 25 25 @Column(name = "id_category", nullable = false) 26 26 @GeneratedValue(strategy = GenerationType.IDENTITY) 27 Integer id _category;27 Integer idcategory; 28 28 String name; 29 29 Integer extra_amount; … … 43 43 if (o == null || getClass() != o.getClass()) return false; 44 44 Category that = (Category) o; 45 return Objects.equals(id _category, that.id_category) && Objects.equals(name, that.name) && Objects.equals(extra_amount, that.extra_amount);45 return Objects.equals(idcategory, that.idcategory) && Objects.equals(name, that.name) && Objects.equals(extra_amount, that.extra_amount); 46 46 } 47 47 48 48 @Override 49 49 public int hashCode() { 50 return Objects.hash(id _category, name, extra_amount);50 return Objects.hash(idcategory, name, extra_amount); 51 51 } 52 52 } -
src/main/java/com/example/moviezone/model/Ticket.java
r0ba5d1a r00fa72f 43 43 } 44 44 45 public Ticket(LocalDate date_reserved, Customer customer, Projection projection, Seat seat) { 46 this.date_reserved = date_reserved; 47 this.customer = customer; 48 this.projection = projection; 49 this.seat = seat; 50 } 51 52 public Ticket( LocalDate date_reserved, Customer customer, Projection projection, Discount discount, Seat seat) { 53 this.date_reserved = date_reserved; 54 this.customer = customer; 55 this.projection = projection; 56 this.discount = discount; 57 this.seat = seat; 58 } 59 45 60 public Ticket() { 46 61 47 62 } 63 64 public void setPrice(long price) { 65 this.price = price; 66 } 48 67 } -
src/main/java/com/example/moviezone/repository/CategoryRepository.java
r0ba5d1a r00fa72f 5 5 import org.springframework.stereotype.Repository; 6 6 7 import java.util.Optional; 8 7 9 @Repository 8 10 public interface CategoryRepository extends JpaRepository<Category,Integer>{ 11 Optional<Category> getByIdcategory(int id); 9 12 } -
src/main/java/com/example/moviezone/repository/Projection_RoomRepository.java
r0ba5d1a r00fa72f 4 4 import com.example.moviezone.model.Projection_Room; 5 5 import org.springframework.data.jpa.repository.JpaRepository; 6 import org.springframework.data.jpa.repository.query.Procedure; 7 8 import java.util.List; 6 9 7 10 public interface Projection_RoomRepository extends JpaRepository<Projection_Room,Integer> { 11 @Procedure("project.getRoomsForProjection") 12 List<Projection_Room> getRoomsForProjection(int id); 8 13 } -
src/main/java/com/example/moviezone/repository/SeatRepository.java
r0ba5d1a r00fa72f 1 1 package com.example.moviezone.repository; 2 2 3 import com.example.moviezone.model.Category; 4 import com.example.moviezone.model.Projection; 3 5 import com.example.moviezone.model.Projection_Room; 4 6 import com.example.moviezone.model.Seat; … … 11 13 public interface SeatRepository extends JpaRepository<Seat,Integer> { 12 14 List<Seat> findAllByProjection(Projection_Room projection); 15 List<Seat> findAllByCategoryAndProjection(Category category, Projection_Room projectionRoom); 13 16 } -
src/main/java/com/example/moviezone/repository/TicketRepository.java
r0ba5d1a r00fa72f 4 4 import com.example.moviezone.model.Ticket; 5 5 import org.springframework.data.jpa.repository.JpaRepository; 6 import org.springframework.data.jpa.repository.query.Procedure; 6 7 import org.springframework.stereotype.Repository; 7 8 … … 10 11 public interface TicketRepository extends JpaRepository<Ticket,Integer> { 11 12 List<Ticket> findAllByCustomer(Customer customer); 13 @Procedure("project.getPriceForTicket") 14 Integer getPriceForTicket(int id); 12 15 } -
src/main/java/com/example/moviezone/service/CategoryService.java
r0ba5d1a r00fa72f 4 4 5 5 import java.util.List; 6 import java.util.Optional; 6 7 7 8 public interface CategoryService { 8 9 List<Category> findAllCategories(); 10 Optional<Category> getCategoryById(int id); 9 11 } -
src/main/java/com/example/moviezone/service/CustomerService.java
r0ba5d1a r00fa72f 5 5 6 6 import java.util.List; 7 import java.util.Optional; 8 7 9 @Repository 8 10 public interface CustomerService { 9 11 List<Customer> findAllCustomers(); 12 Optional<Customer> getCustomerById(int id); 10 13 } -
src/main/java/com/example/moviezone/service/Impl/CategoryServiceImpl.java
r0ba5d1a r00fa72f 7 7 8 8 import java.util.List; 9 import java.util.Optional; 9 10 10 11 @Service … … 20 21 return categoryRepository.findAll(); 21 22 } 23 24 @Override 25 public Optional<Category> getCategoryById(int id) { 26 return categoryRepository.getByIdcategory(id); 27 } 22 28 } -
src/main/java/com/example/moviezone/service/Impl/CustomerServiceImpl.java
r0ba5d1a r00fa72f 7 7 8 8 import java.util.List; 9 import java.util.Optional; 9 10 10 11 @Service … … 20 21 return customerRepository.findAll(); 21 22 } 23 24 @Override 25 public Optional<Customer> getCustomerById(int id) { 26 return customerRepository.findById(id); 27 } 22 28 } -
src/main/java/com/example/moviezone/service/Impl/Projection_RoomServiceImpl.java
r0ba5d1a r00fa72f 20 20 return projectionRoomRepository.findAll(); 21 21 } 22 23 @Override 24 public List<Projection_Room> getRoomByProjection(int id) { 25 return projectionRoomRepository.getRoomsForProjection(id); 26 } 22 27 } -
src/main/java/com/example/moviezone/service/Impl/SeatServiceImpl.java
r0ba5d1a r00fa72f 1 1 package com.example.moviezone.service.Impl; 2 2 3 import com.example.moviezone.model.Category; 3 4 import com.example.moviezone.model.Projection_Room; 4 5 import com.example.moviezone.model.Seat; … … 8 9 9 10 import java.util.List; 11 import java.util.Optional; 10 12 11 13 @Service 12 14 public class SeatServiceImpl implements SeatService { 15 16 13 17 private final SeatRepository seatRepository; 14 18 … … 26 30 return seatRepository.findAllByProjection(projection_room); 27 31 } 32 33 @Override 34 public List<Seat> findAllByRoomAndCategory(Projection_Room projectionRoom, Category category) { 35 return seatRepository.findAllByCategoryAndProjection(category,projectionRoom); 36 } 37 38 @Override 39 public Optional<Seat> getSeatById(int id) { 40 return Optional.of(seatRepository.getById(id)); 41 } 28 42 } -
src/main/java/com/example/moviezone/service/Impl/TicketServiceImpl.java
r0ba5d1a r00fa72f 1 1 package com.example.moviezone.service.Impl; 2 2 3 import com.example.moviezone.model.Customer; 4 import com.example.moviezone.model.Ticket; 3 import com.example.moviezone.model.*; 5 4 import com.example.moviezone.repository.TicketRepository; 6 5 import com.example.moviezone.service.TicketService; 7 6 import org.springframework.stereotype.Service; 8 7 8 import java.time.LocalDate; 9 9 import java.util.List; 10 10 … … 28 28 29 29 @Override 30 public Ticket saveWithDiscount(LocalDate date, Customer customer, Projection projection, Discount discount, Seat seat) { 31 Ticket t=new Ticket(date,customer,projection,discount,seat); 32 return ticketRepository.save(t); 33 } 34 35 @Override 36 public Ticket saveWithout(LocalDate date, Customer customer, Projection projection, Seat seat) { 37 Ticket t=new Ticket(date,customer,projection,seat); 38 return ticketRepository.save(t); 39 } 40 41 @Override 30 42 public Ticket save(long price, Customer customer) { 31 43 return ticketRepository.save(new Ticket(price,customer)); 32 44 } 45 46 @Override 47 public Integer priceForTicket(int id) { 48 return ticketRepository.getPriceForTicket(id); 49 } 33 50 } -
src/main/java/com/example/moviezone/service/Projection_RoomService.java
r0ba5d1a r00fa72f 2 2 3 3 import com.example.moviezone.model.Projection_Room; 4 import org.springframework.data.jpa.repository.query.Procedure; 4 5 5 6 import java.util.List; … … 7 8 public interface Projection_RoomService { 8 9 List<Projection_Room> findAllProjectionRooms(); 10 11 List<Projection_Room> getRoomByProjection(int id); 9 12 } -
src/main/java/com/example/moviezone/service/SeatService.java
r0ba5d1a r00fa72f 1 1 package com.example.moviezone.service; 2 2 3 import com.example.moviezone.model.Category; 3 4 import com.example.moviezone.model.Projection_Room; 4 5 import com.example.moviezone.model.Seat; 5 6 6 7 import java.util.List; 8 import java.util.Optional; 7 9 8 10 public interface SeatService { 9 11 List<Seat> findAllSeats(); 10 12 List<Seat> findAllByProjection_Room(Projection_Room projection_room); 13 List<Seat> findAllByRoomAndCategory(Projection_Room projectionRoom, Category category); 14 Optional<Seat> getSeatById(int id); 11 15 } -
src/main/java/com/example/moviezone/service/TicketService.java
r0ba5d1a r00fa72f 1 1 package com.example.moviezone.service; 2 2 3 import com.example.moviezone.model.Customer; 4 import com.example.moviezone.model.Ticket; 3 import com.example.moviezone.model.*; 5 4 5 import java.time.LocalDate; 6 6 import java.util.List; 7 7 … … 9 9 List<Ticket> findAllTickets(); 10 10 List<Ticket> findAllByCustomer(Customer customer); 11 11 Ticket saveWithDiscount(LocalDate date, Customer customer, Projection projection, Discount discount, Seat seat); 12 Ticket saveWithout(LocalDate date,Customer customer,Projection projection,Seat seat); 12 13 Ticket save(long price,Customer customer); 14 Integer priceForTicket(int id); 13 15 } -
src/main/java/com/example/moviezone/web/HomeController.java
r0ba5d1a r00fa72f 38 38 private final ProjectionIsPlayedInRoomService projectionIsPlayedInRoomService; 39 39 private final CategoryService categoryService; 40 41 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) 40 private final SeatService seatService; 41 private final CustomerService customerService; 42 private final Projection_RoomService projectionRoomService; 43 44 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) 42 45 { 43 46 … … 54 57 this.projectionIsPlayedInRoomService = projectionIsPlayedInRoomService; 55 58 this.categoryService = categoryService; 59 this.seatService = seatService; 60 this.customerService = customerService; 61 this.projectionRoomService = projectionRoomService; 56 62 } 57 63 … … 95 101 model.addAttribute("categories",categoryService.findAllCategories()); 96 102 model.addAttribute("bodyContent", "projectionsForFilm"); 103 104 return "master-template"; 105 } 106 @GetMapping("/getSeats/{id}") 107 @Transactional 108 public String getSeats(@PathVariable Long id, Model model,@RequestParam Long id_category,@RequestParam Long film) { 109 Category category=categoryService.getCategoryById(id_category.intValue()).get(); 110 Projection projection=projectionService.findById(id.intValue()); 111 model.addAttribute("film",filmService.getFilmById(film).get()); 112 model.addAttribute("projection",projection); 113 model.addAttribute("category",category); 114 115 List<Seat> seats=seatService.findAllByRoomAndCategory(projectionRoomService.getRoomByProjection(projection.getId_projection()).get(0),category); 116 model.addAttribute("seats",seats); 117 model.addAttribute("bodyContent", "seats"); 97 118 98 119 return "master-template"; … … 316 337 317 338 @PostMapping("/makeReservation") 318 public String createTicketForReservation() 319 { 320 return "redirect:/myTickets"; 339 @Transactional 340 public String createTicketForReservation(@RequestParam Long film,@RequestParam Long projection,@RequestParam Long id_seat,@RequestParam String discount) 341 { 342 Ticket t; 343 Projection projection1=projectionService.findById(projection.intValue()); 344 if(projection1.getDiscount().equals(discount)){ 345 t=ticketService.saveWithDiscount(LocalDate.now(),customerService.getCustomerById(2).get(),projection1,projection1.getDiscount(),seatService.getSeatById(id_seat.intValue()).get()); 346 }else{ 347 t=ticketService.saveWithout(LocalDate.now(),customerService.getCustomerById(4).get(),projection1,seatService.getSeatById(id_seat.intValue()).get()); 348 } 349 Integer price=ticketService.priceForTicket(t.getId_ticket()); 350 t.setPrice(price); 351 return "redirect:/home"; 321 352 } 322 353
Note:
See TracChangeset
for help on using the changeset viewer.