Changeset 00fa72f for src/main/java


Ignore:
Timestamp:
02/09/23 14:06:45 (23 months ago)
Author:
DenicaKj <dkorvezir@…>
Branches:
master
Children:
6a9006d, a9ffccd
Parents:
0ba5d1a
Message:

Reservation Implemented

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  
    2525    @Column(name = "id_category", nullable = false)
    2626    @GeneratedValue(strategy = GenerationType.IDENTITY)
    27     Integer id_category;
     27    Integer idcategory;
    2828    String name;
    2929    Integer extra_amount;
     
    4343        if (o == null || getClass() != o.getClass()) return false;
    4444        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);
    4646    }
    4747
    4848    @Override
    4949    public int hashCode() {
    50         return Objects.hash(id_category, name, extra_amount);
     50        return Objects.hash(idcategory, name, extra_amount);
    5151    }
    5252}
  • src/main/java/com/example/moviezone/model/Ticket.java

    r0ba5d1a r00fa72f  
    4343    }
    4444
     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
    4560    public Ticket() {
    4661
    4762    }
     63
     64    public void setPrice(long price) {
     65        this.price = price;
     66    }
    4867}
  • src/main/java/com/example/moviezone/repository/CategoryRepository.java

    r0ba5d1a r00fa72f  
    55import org.springframework.stereotype.Repository;
    66
     7import java.util.Optional;
     8
    79@Repository
    810public interface CategoryRepository extends JpaRepository<Category,Integer>{
     11    Optional<Category> getByIdcategory(int id);
    912}
  • src/main/java/com/example/moviezone/repository/Projection_RoomRepository.java

    r0ba5d1a r00fa72f  
    44import com.example.moviezone.model.Projection_Room;
    55import org.springframework.data.jpa.repository.JpaRepository;
     6import org.springframework.data.jpa.repository.query.Procedure;
     7
     8import java.util.List;
    69
    710public interface Projection_RoomRepository extends JpaRepository<Projection_Room,Integer> {
     11    @Procedure("project.getRoomsForProjection")
     12    List<Projection_Room> getRoomsForProjection(int id);
    813}
  • src/main/java/com/example/moviezone/repository/SeatRepository.java

    r0ba5d1a r00fa72f  
    11package com.example.moviezone.repository;
    22
     3import com.example.moviezone.model.Category;
     4import com.example.moviezone.model.Projection;
    35import com.example.moviezone.model.Projection_Room;
    46import com.example.moviezone.model.Seat;
     
    1113public interface SeatRepository extends JpaRepository<Seat,Integer> {
    1214    List<Seat> findAllByProjection(Projection_Room projection);
     15    List<Seat> findAllByCategoryAndProjection(Category category, Projection_Room projectionRoom);
    1316}
  • src/main/java/com/example/moviezone/repository/TicketRepository.java

    r0ba5d1a r00fa72f  
    44import com.example.moviezone.model.Ticket;
    55import org.springframework.data.jpa.repository.JpaRepository;
     6import org.springframework.data.jpa.repository.query.Procedure;
    67import org.springframework.stereotype.Repository;
    78
     
    1011public interface TicketRepository extends JpaRepository<Ticket,Integer> {
    1112    List<Ticket> findAllByCustomer(Customer customer);
     13    @Procedure("project.getPriceForTicket")
     14    Integer getPriceForTicket(int id);
    1215}
  • src/main/java/com/example/moviezone/service/CategoryService.java

    r0ba5d1a r00fa72f  
    44
    55import java.util.List;
     6import java.util.Optional;
    67
    78public interface CategoryService {
    89    List<Category> findAllCategories();
     10    Optional<Category> getCategoryById(int id);
    911}
  • src/main/java/com/example/moviezone/service/CustomerService.java

    r0ba5d1a r00fa72f  
    55
    66import java.util.List;
     7import java.util.Optional;
     8
    79@Repository
    810public interface CustomerService {
    911    List<Customer> findAllCustomers();
     12    Optional<Customer> getCustomerById(int id);
    1013}
  • src/main/java/com/example/moviezone/service/Impl/CategoryServiceImpl.java

    r0ba5d1a r00fa72f  
    77
    88import java.util.List;
     9import java.util.Optional;
    910
    1011@Service
     
    2021        return categoryRepository.findAll();
    2122    }
     23
     24    @Override
     25    public Optional<Category> getCategoryById(int id) {
     26        return categoryRepository.getByIdcategory(id);
     27    }
    2228}
  • src/main/java/com/example/moviezone/service/Impl/CustomerServiceImpl.java

    r0ba5d1a r00fa72f  
    77
    88import java.util.List;
     9import java.util.Optional;
    910
    1011@Service
     
    2021        return customerRepository.findAll();
    2122    }
     23
     24    @Override
     25    public Optional<Customer> getCustomerById(int id) {
     26        return customerRepository.findById(id);
     27    }
    2228}
  • src/main/java/com/example/moviezone/service/Impl/Projection_RoomServiceImpl.java

    r0ba5d1a r00fa72f  
    2020        return projectionRoomRepository.findAll();
    2121    }
     22
     23    @Override
     24    public List<Projection_Room> getRoomByProjection(int id) {
     25        return projectionRoomRepository.getRoomsForProjection(id);
     26    }
    2227}
  • src/main/java/com/example/moviezone/service/Impl/SeatServiceImpl.java

    r0ba5d1a r00fa72f  
    11package com.example.moviezone.service.Impl;
    22
     3import com.example.moviezone.model.Category;
    34import com.example.moviezone.model.Projection_Room;
    45import com.example.moviezone.model.Seat;
     
    89
    910import java.util.List;
     11import java.util.Optional;
    1012
    1113@Service
    1214public class SeatServiceImpl implements SeatService {
     15
     16
    1317    private final SeatRepository seatRepository;
    1418
     
    2630        return seatRepository.findAllByProjection(projection_room);
    2731    }
     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    }
    2842}
  • src/main/java/com/example/moviezone/service/Impl/TicketServiceImpl.java

    r0ba5d1a r00fa72f  
    11package com.example.moviezone.service.Impl;
    22
    3 import com.example.moviezone.model.Customer;
    4 import com.example.moviezone.model.Ticket;
     3import com.example.moviezone.model.*;
    54import com.example.moviezone.repository.TicketRepository;
    65import com.example.moviezone.service.TicketService;
    76import org.springframework.stereotype.Service;
    87
     8import java.time.LocalDate;
    99import java.util.List;
    1010
     
    2828
    2929    @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
    3042    public Ticket save(long price, Customer customer) {
    3143        return ticketRepository.save(new Ticket(price,customer));
    3244    }
     45
     46    @Override
     47    public Integer priceForTicket(int id) {
     48        return ticketRepository.getPriceForTicket(id);
     49    }
    3350}
  • src/main/java/com/example/moviezone/service/Projection_RoomService.java

    r0ba5d1a r00fa72f  
    22
    33import com.example.moviezone.model.Projection_Room;
     4import org.springframework.data.jpa.repository.query.Procedure;
    45
    56import java.util.List;
     
    78public interface Projection_RoomService {
    89    List<Projection_Room> findAllProjectionRooms();
     10
     11    List<Projection_Room> getRoomByProjection(int id);
    912}
  • src/main/java/com/example/moviezone/service/SeatService.java

    r0ba5d1a r00fa72f  
    11package com.example.moviezone.service;
    22
     3import com.example.moviezone.model.Category;
    34import com.example.moviezone.model.Projection_Room;
    45import com.example.moviezone.model.Seat;
    56
    67import java.util.List;
     8import java.util.Optional;
    79
    810public interface SeatService {
    911    List<Seat> findAllSeats();
    1012    List<Seat> findAllByProjection_Room(Projection_Room projection_room);
     13    List<Seat> findAllByRoomAndCategory(Projection_Room projectionRoom, Category category);
     14    Optional<Seat> getSeatById(int id);
    1115}
  • src/main/java/com/example/moviezone/service/TicketService.java

    r0ba5d1a r00fa72f  
    11package com.example.moviezone.service;
    22
    3 import com.example.moviezone.model.Customer;
    4 import com.example.moviezone.model.Ticket;
     3import com.example.moviezone.model.*;
    54
     5import java.time.LocalDate;
    66import java.util.List;
    77
     
    99    List<Ticket> findAllTickets();
    1010    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);
    1213    Ticket save(long price,Customer customer);
     14    Integer priceForTicket(int id);
    1315}
  • src/main/java/com/example/moviezone/web/HomeController.java

    r0ba5d1a r00fa72f  
    3838private final ProjectionIsPlayedInRoomService projectionIsPlayedInRoomService;
    3939private 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)
     40private final SeatService seatService;
     41private final CustomerService customerService;
     42private 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)
    4245    {
    4346
     
    5457        this.projectionIsPlayedInRoomService = projectionIsPlayedInRoomService;
    5558        this.categoryService = categoryService;
     59        this.seatService = seatService;
     60        this.customerService = customerService;
     61        this.projectionRoomService = projectionRoomService;
    5662    }
    5763
     
    95101        model.addAttribute("categories",categoryService.findAllCategories());
    96102        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");
    97118
    98119        return "master-template";
     
    316337
    317338    @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";
    321352    }
    322353
Note: See TracChangeset for help on using the changeset viewer.