Last change
on this file since 3d60932 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | package com.example.skychasemk.services;
|
---|
2 |
|
---|
3 | import com.example.skychasemk.model.Booking;
|
---|
4 | import com.example.skychasemk.repository.BookingRepository;
|
---|
5 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
6 | import org.springframework.stereotype.Service;
|
---|
7 |
|
---|
8 | import java.util.List;
|
---|
9 | import java.util.Optional;
|
---|
10 |
|
---|
11 | @Service
|
---|
12 | public class BookingService {
|
---|
13 |
|
---|
14 | @Autowired
|
---|
15 | private BookingRepository bookingRepository;
|
---|
16 |
|
---|
17 | public List<Booking> getAllBookings() {
|
---|
18 | return bookingRepository.findAll();
|
---|
19 | }
|
---|
20 |
|
---|
21 | public Optional<Booking> getBookingById(Integer bookingID) {
|
---|
22 | return bookingRepository.findById(bookingID);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public Booking saveBooking(Booking booking) {
|
---|
26 | return bookingRepository.save(booking);
|
---|
27 | }
|
---|
28 |
|
---|
29 | public Booking updateBooking(Integer bookingID, Booking booking) {
|
---|
30 | if (bookingRepository.existsById(bookingID)) {
|
---|
31 | booking.setBookingID(bookingID);
|
---|
32 | return bookingRepository.save(booking);
|
---|
33 | } else {
|
---|
34 | throw new RuntimeException("Booking not found with id " + bookingID);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public void deleteBooking(Integer bookingID) {
|
---|
39 | bookingRepository.deleteById(bookingID);
|
---|
40 | }
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.