1 | package com.example.moviezone.service.Impl;
|
---|
2 |
|
---|
3 | import com.example.moviezone.model.*;
|
---|
4 | import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
|
---|
5 | import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository;
|
---|
6 | import com.example.moviezone.repository.Projection_RoomRepository;
|
---|
7 | import com.example.moviezone.repository.SeatRepository;
|
---|
8 | import com.example.moviezone.service.SeatService;
|
---|
9 | import org.springframework.stereotype.Service;
|
---|
10 |
|
---|
11 | import java.util.ArrayList;
|
---|
12 | import java.util.List;
|
---|
13 | import java.util.Optional;
|
---|
14 |
|
---|
15 | @Service
|
---|
16 | public class SeatServiceImpl implements SeatService {
|
---|
17 |
|
---|
18 |
|
---|
19 | private final SeatRepository seatRepository;
|
---|
20 | private final TicketServiceImpl ticketService;
|
---|
21 | private final ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository;
|
---|
22 | private final Projection_RoomRepository projection_roomRepository;
|
---|
23 |
|
---|
24 | public SeatServiceImpl(SeatRepository seatRepository, TicketServiceImpl ticketService, ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository, Projection_RoomRepository projection_roomRepository) {
|
---|
25 | this.seatRepository = seatRepository;
|
---|
26 | this.ticketService = ticketService;
|
---|
27 | this.projectionIsPlayedInRoomRepository = projectionIsPlayedInRoomRepository;
|
---|
28 | this.projection_roomRepository = projection_roomRepository;
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public List<Seat> findAllSeats() {
|
---|
33 | return seatRepository.findAll();
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public List<Seat> findAllByProjection_Room(Projection_Room projection_room) {
|
---|
38 | return seatRepository.findAllByProjection(projection_room);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public List<Seat> findAllByRoomAndCategory(Projection projection, Projection_Room projectionRoom, Category category) {
|
---|
43 | List<Ticket> tickets=ticketService.findAllTickets();
|
---|
44 | List<Seat> seats=seatRepository.findAllByCategoryAndProjection(category,projectionRoom);
|
---|
45 |
|
---|
46 | for (int i = 0; i < tickets.size(); i++) {
|
---|
47 | if(tickets.get(i).getProjection()==projection){
|
---|
48 | if(seats.contains(tickets.get(i).getSeat())){
|
---|
49 | seats.remove(tickets.get(i).getSeat());
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | return seats;
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public Optional<Seat> getSeatById(int id) {
|
---|
58 | return Optional.of(seatRepository.getById(id));
|
---|
59 | }
|
---|
60 | }
|
---|