source: src/main/java/com/example/moviezone/service/Impl/SeatServiceImpl.java@ 8a18cf5

Last change on this file since 8a18cf5 was 8a18cf5, checked in by DenicaKj <dkorvezir@…>, 21 months ago

fixes

  • Property mode set to 100644
File size: 3.2 KB
Line 
1package com.example.moviezone.service.Impl;
2
3import com.example.moviezone.model.Category;
4import com.example.moviezone.model.Projection_Room;
5import com.example.moviezone.model.Seat;
6import com.example.moviezone.model.Ticket;
7import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
8import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository;
9import com.example.moviezone.repository.Projection_RoomRepository;
10import com.example.moviezone.repository.SeatRepository;
11import com.example.moviezone.service.SeatService;
12import org.springframework.stereotype.Service;
13
14import java.util.ArrayList;
15import java.util.List;
16import java.util.Optional;
17
18@Service
19public class SeatServiceImpl implements SeatService {
20
21
22 private final SeatRepository seatRepository;
23 private final TicketServiceImpl ticketService;
24 private final ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository;
25 private final Projection_RoomRepository projection_roomRepository;
26
27 public SeatServiceImpl(SeatRepository seatRepository, TicketServiceImpl ticketService, ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository, Projection_RoomRepository projection_roomRepository) {
28 this.seatRepository = seatRepository;
29 this.ticketService = ticketService;
30 this.projectionIsPlayedInRoomRepository = projectionIsPlayedInRoomRepository;
31 this.projection_roomRepository = projection_roomRepository;
32 }
33
34 @Override
35 public List<Seat> findAllSeats() {
36 return seatRepository.findAll();
37 }
38
39 @Override
40 public List<Seat> findAllByProjection_Room(Projection_Room projection_room) {
41 return seatRepository.findAllByProjection(projection_room);
42 }
43
44 @Override
45 public List<Seat> findAllByRoomAndCategory(Projection_Room projectionRoom, Category category) {
46 List<Ticket> tickets=ticketService.findAllTickets();
47 List<Seat> seats=seatRepository.findAllByCategoryAndProjection(category,projectionRoom);
48 List<Seat> s=new ArrayList<>();
49 List<Projection_Room> projection_rooms=new ArrayList<>();
50 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()));
54 }
55 }
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;
74 }
75
76 @Override
77 public Optional<Seat> getSeatById(int id) {
78 return Optional.of(seatRepository.getById(id));
79 }
80}
Note: See TracBrowser for help on using the repository browser.