1 | package com.example.demo.service.ServiceImpl;
|
---|
2 |
|
---|
3 | import com.example.demo.model.*;
|
---|
4 | import com.example.demo.model.Client.Client;
|
---|
5 | import com.example.demo.model.Client.ClientCompositeKey;
|
---|
6 | import com.example.demo.model.Reservation.Reservations;
|
---|
7 | import com.example.demo.model.Seat.Seat;
|
---|
8 | import com.example.demo.model.Seat.SeatCompositeKey;
|
---|
9 | import com.example.demo.repository.*;
|
---|
10 | import com.example.demo.service.MovieProjectionService;
|
---|
11 | import com.example.demo.service.ReservationService;
|
---|
12 | import org.springframework.stereotype.Service;
|
---|
13 | import org.springframework.transaction.annotation.Transactional;
|
---|
14 | import java.util.Optional;
|
---|
15 |
|
---|
16 | @Service
|
---|
17 | public class ReservationServiceImpl implements ReservationService {
|
---|
18 | private final PaymentTypeRepository paymentTypeRepository;
|
---|
19 | private final ClientRepository clientRepository;
|
---|
20 | private final SeatRepository seatRepository;
|
---|
21 | private final AuditoriumRepository auditoriumRepository;
|
---|
22 | private final UserRepository userRepository;
|
---|
23 | private final MovieProjectionService movieProjectionService;
|
---|
24 | private final PaymentRepository paymentRepository;
|
---|
25 | private final ReservationsRepository reservationsRepository;
|
---|
26 | public ReservationServiceImpl(PaymentTypeRepository paymentTypeRepository, ClientRepository clientRepository, SeatRepository seatRepository, AuditoriumRepository auditoriumRepository, UserRepository userRepository, MovieProjectionService movieProjectionService, PaymentRepository paymentRepository, ReservationsRepository reservationsRepository) {
|
---|
27 | this.paymentTypeRepository = paymentTypeRepository;
|
---|
28 | this.clientRepository = clientRepository;
|
---|
29 | this.seatRepository = seatRepository;
|
---|
30 | this.auditoriumRepository = auditoriumRepository;
|
---|
31 | this.userRepository = userRepository;
|
---|
32 | this.movieProjectionService = movieProjectionService;
|
---|
33 | this.paymentRepository = paymentRepository;
|
---|
34 | this.reservationsRepository = reservationsRepository;
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | @Transactional
|
---|
39 | public Optional<Reservations> save(
|
---|
40 | Integer reservation_id,
|
---|
41 | String reservation_end_date,
|
---|
42 | Integer payment_type_id,
|
---|
43 | Integer user_id,
|
---|
44 | Integer seat_id,
|
---|
45 | Integer auditorium_id,
|
---|
46 | Integer projection_id) {
|
---|
47 |
|
---|
48 | PaymentType paymentType = this.paymentTypeRepository.findById(payment_type_id).get();
|
---|
49 |
|
---|
50 |
|
---|
51 | User user = this.userRepository.findById(String.valueOf(user_id)).get();
|
---|
52 | ClientCompositeKey clientCompositeKey = new ClientCompositeKey();
|
---|
53 | clientCompositeKey.setUser(user);
|
---|
54 | Client client = this.clientRepository.findById(clientCompositeKey).get();
|
---|
55 |
|
---|
56 |
|
---|
57 | SeatCompositeKey seatCompositeKey = new SeatCompositeKey();
|
---|
58 | seatCompositeKey.setSeat_id(seat_id);
|
---|
59 | Auditorium auditorium = this.auditoriumRepository.findById(auditorium_id).get();
|
---|
60 | seatCompositeKey.setAuditorium(auditorium);
|
---|
61 | Seat seat = seatRepository.findById(seatCompositeKey).get();
|
---|
62 |
|
---|
63 | MovieProjection movieProjection = movieProjectionService.findById(projection_id).get();
|
---|
64 |
|
---|
65 |
|
---|
66 | /*
|
---|
67 | return Optional.of(this.reservationsRepository.save(new Reservations(reservation_id,reservation_end_date,paymentType,
|
---|
68 | seat,client,movieProjection)));
|
---|
69 | }
|
---|
70 |
|
---|
71 | */
|
---|
72 | return null;
|
---|
73 | }
|
---|
74 | @Override
|
---|
75 | public Optional<Reservations> findAll() {
|
---|
76 | return this.reservationsRepository.findAllReservations();
|
---|
77 | }
|
---|
78 | }
|
---|