source: src/main/java/com/example/villadihovo/service/impl/reservationImpl/GuestMakeReservationServiceImpl.java

Last change on this file was f7c05a1, checked in by Elena Shulevska <elena.shulevska@…>, 16 months ago

initial commit of the source code on origin

  • Property mode set to 100644
File size: 2.3 KB
Line 
1package com.example.villadihovo.service.impl.reservationImpl;
2
3import com.example.villadihovo.dto.ReservationForRoomDto;
4import com.example.villadihovo.model.reservations.Reservation;
5import com.example.villadihovo.repository.reservation.GuestMakeReservationRepository;
6import com.example.villadihovo.repository.reservation.ReservationRepository;
7import com.example.villadihovo.repository.offers.RoomRepository;
8import com.example.villadihovo.repository.offers.VillaRepository;
9import com.example.villadihovo.service.reservation.GuestMakeReservationService;
10import org.springframework.beans.factory.annotation.Autowired;
11import org.springframework.stereotype.Service;
12
13import java.time.LocalDate;
14import java.util.List;
15import java.util.Optional;
16
17@Service
18public 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}
Note: See TracBrowser for help on using the repository browser.