source: src/main/java/com/example/skychasemk/services/AirportService.java@ 57e58a3

Last change on this file since 57e58a3 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1package com.example.skychasemk.services;
2
3import com.example.skychasemk.model.Airport;
4import com.example.skychasemk.repository.AirportRepository;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.stereotype.Service;
7
8import java.util.List;
9import java.util.Optional;
10
11@Service
12public class AirportService {
13
14 @Autowired
15 private AirportRepository airportRepository;
16
17 // Get all airports
18 public List<Airport> getAllAirports() {
19 return airportRepository.findAll();
20 }
21
22 // Get airport by ID
23 public Optional<Airport> getAirportById(Integer airportID) {
24 return airportRepository.findById(airportID);
25 }
26
27 // Save new airport
28 public Airport saveAirport(Airport airport) {
29 return airportRepository.save(airport);
30 }
31
32 // Update an airport
33 public Airport updateAirport(Integer airportID, Airport airport) {
34 if (airportRepository.existsById(airportID)) {
35 airport.setAirportID(airportID);
36 return airportRepository.save(airport);
37 } else {
38 throw new RuntimeException("Airport not found with id " + airportID);
39 }
40 }
41
42 // Delete airport
43 public void deleteAirport(Integer airportID) {
44 airportRepository.deleteById(airportID);
45 }
46}
Note: See TracBrowser for help on using the repository browser.