1 | package com.example.villadihovo.service.impl.reservationImpl;
|
---|
2 |
|
---|
3 | import com.example.villadihovo.dto.ReservationForRoomDto;
|
---|
4 | import com.example.villadihovo.model.reservations.Reservation;
|
---|
5 | import com.example.villadihovo.repository.reservation.GuestMakeReservationRepository;
|
---|
6 | import com.example.villadihovo.repository.reservation.ReservationRepository;
|
---|
7 | import com.example.villadihovo.repository.offers.RoomRepository;
|
---|
8 | import com.example.villadihovo.repository.offers.VillaRepository;
|
---|
9 | import com.example.villadihovo.service.reservation.GuestMakeReservationService;
|
---|
10 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
11 | import org.springframework.stereotype.Service;
|
---|
12 |
|
---|
13 | import java.time.LocalDate;
|
---|
14 | import java.util.List;
|
---|
15 | import java.util.Optional;
|
---|
16 |
|
---|
17 | @Service
|
---|
18 | public class GuestMakeReservationServiceImpl implements GuestMakeReservationService {
|
---|
19 |
|
---|
20 | @Autowired
|
---|
21 | private GuestMakeReservationRepository guestMakeReservationRepository;
|
---|
22 | @Autowired
|
---|
23 | private ReservationRepository reservationRepository;
|
---|
24 | @Autowired
|
---|
25 | private RoomRepository roomRepository;
|
---|
26 | @Autowired
|
---|
27 | private VillaRepository villaRepository;
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public List<ReservationForRoomDto> findAllRoomReservations() {
|
---|
31 | return guestMakeReservationRepository.findAllRoomReservationsDTO();
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public ReservationForRoomDto findRoomReservationByReservationId(Integer id) {
|
---|
36 | return guestMakeReservationRepository.findRoomReservationsDTOById(id);
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | public ReservationForRoomDto updateRoomReservationById(Integer roomReservationId, LocalDate start_date, LocalDate end_date, Integer adults, Integer children, Integer number_guests) {
|
---|
41 | Optional<Reservation> reservation = reservationRepository.findById(roomReservationId);
|
---|
42 | if (reservation.isPresent()) {
|
---|
43 |
|
---|
44 | reservation.get().setStart_date(start_date);
|
---|
45 | reservation.get().setEnd_date(end_date);
|
---|
46 | reservation.get().setNumber_guests(number_guests);
|
---|
47 | reservation.get().setAdults(adults);
|
---|
48 | reservation.get().setChildren(children);
|
---|
49 |
|
---|
50 | reservationRepository.save(reservation.get());
|
---|
51 | }
|
---|
52 | return guestMakeReservationRepository.findRoomReservationsDTOById(roomReservationId);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public void deleteReservationById(Integer reservation_id) {
|
---|
57 | reservationRepository.deleteById(reservation_id);
|
---|
58 | }
|
---|
59 | }
|
---|