Skip to content

Commit

Permalink
security commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Papabdou12 committed Nov 12, 2022
1 parent 9d31392 commit 64bab82
Show file tree
Hide file tree
Showing 113 changed files with 6,080 additions and 737 deletions.
14 changes: 7 additions & 7 deletions Flight-Managment-System/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.7.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.7.5</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
Expand All @@ -49,6 +53,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.7.5</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -59,17 +64,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.7.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
<artifactId>spring-security-web</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.saraya.flightmanagmentsystem.controller;
import com.saraya.flightmanagmentsystem.exception.ResourceNotFoundException;
import com.saraya.flightmanagmentsystem.model.*;
import com.saraya.flightmanagmentsystem.repository.BookingRepository;
import com.saraya.flightmanagmentsystem.repository.FlightRepository;
import com.saraya.flightmanagmentsystem.repository.PassengerRepository;
import com.saraya.flightmanagmentsystem.service.BookingService;
import lombok.Data;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
import java.util.Optional;

@CrossOrigin(origins = "http://localhost:4200")
Expand All @@ -18,11 +22,25 @@ public class BookingController {
@Autowired
private final BookingService service;

@Autowired
private final BookingRepository repo;

@Autowired
private final FlightRepository flightRepository;

@Autowired
private final PassengerRepository passengerRepository;



@Autowired
private final ModelMapper mapper;

public BookingController(BookingService service, ModelMapper mapper) {
public BookingController(BookingService service, BookingRepository repo, FlightRepository flightRepository, PassengerRepository passengerRepository, ModelMapper mapper) {
this.service = service;
this.repo = repo;
this.flightRepository = flightRepository;
this.passengerRepository = passengerRepository;
this.mapper = mapper;
}

Expand All @@ -38,21 +56,13 @@ public ResponseEntity<Optional<Booking>> getBooking(@PathVariable Long bookingId

return new ResponseEntity<>(booking,HttpStatus.OK);
}
@PostMapping("/add")
public ResponseEntity<Booking> createBooking(@RequestBody Booking booking) {
Booking b = service.create(booking);

@PostMapping("/add/{bookingId}")
public ResponseEntity<Booking> createBooking( @PathVariable Long bookingId,@RequestBody Booking booking) {
Booking b = service.create(booking, bookingId);
return new ResponseEntity<>(b,HttpStatus.CREATED);
}
//@PostMapping("/add/{bookingId}")
// public ResponseEntity<Booking> createBooking(@RequestBody Booking booking, @PathVariable Long bookingId) {
// Booking b = service.create(booking,bookingId);
// return new ResponseEntity<>(b,HttpStatus.CREATED);
// }
// @PostMapping("/add/booking/toPassenger")
// public ResponseEntity<?> addRoleToUser(@RequestBody BookingToPassengerForm form){
// service.addRoleToUser(form.getBookingId(), form.getPassengerId());
// return ResponseEntity.ok().build();
// }

@PutMapping("/update/{bookingId}")
public ResponseEntity<Booking> updateBooking(@RequestBody Booking booking, @PathVariable Long bookingId) {
booking = service.updateBooking(bookingId, booking);
Expand All @@ -64,6 +74,48 @@ public ResponseEntity<Booking> updateBooking(@RequestBody Booking booking, @Pat
return new ResponseEntity<>(HttpStatus.OK);
}



@PostMapping("/add")
@Transactional
public ResponseEntity<Booking> createBooking( @RequestBody Booking request) {
BookingDto dto = mapper.map(request,BookingDto.class);
Booking booking = repo.save(request);

Passenger passenger = request.getPassenger();
passenger.setBooking(booking);
passengerRepository.save(passenger);

Flight flight = request.getFlights();
flight.setBooking(booking);
flightRepository.save(flight);


return new ResponseEntity<>(booking, HttpStatus.CREATED);
}

@GetMapping("/booking/{passengerId}/booking")
@Transactional
public ResponseEntity<Booking> getBookingByPassengerId(@PathVariable(value = "passengerId") Long passengerId) {

Passenger passenger = passengerRepository.findById(passengerId)
.orElseThrow(() -> new ResourceNotFoundException("Not found Branch with id = " + passengerId));

Booking booking = repo.findByPassenger(passengerId);
return new ResponseEntity<>(booking, HttpStatus.OK);
}

@GetMapping("/booking/{flightId}/booking")
@Transactional
public ResponseEntity<Booking> getBookingByFlightId(@PathVariable(value = "flightId") Long flightId) {

Flight flight = flightRepository.findById(flightId)
.orElseThrow(() -> new ResourceNotFoundException("Not found Branch with id = " + flightId));

Booking booking = repo.findByFlights(flightId);
return new ResponseEntity<>(booking, HttpStatus.OK);
}

}

//@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@CrossOrigin("http://localhost:4200")
Expand Down Expand Up @@ -46,4 +47,10 @@ public Flight updateFlight(@RequestBody Flight flight){
public void DeleteById(@PathVariable Long flightId){
service.DeleteById(flightId);
}

@GetMapping("/search/{from}/{to}/flight")
public List<Flight> search( @PathVariable String from, @PathVariable String to){
return service.search(from, to);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public Passenger create(@RequestBody Passenger passenger) {
return service.create(passenger);
}
@PutMapping("/update")
public Passenger updateAirport(@RequestBody Passenger passenger){
return service.updateAirport(passenger);
public Passenger update(@RequestBody Passenger passenger){
return service.updatePassenger(passenger);
}

@DeleteMapping("/delete/{passengerId}")
public void deleteById(Long passengerId){
public void deleteById(@PathVariable Long passengerId){
service.DeleteById(passengerId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.saraya.flightmanagmentsystem.controller;

import com.saraya.flightmanagmentsystem.exception.ResourceNotFoundException;
import com.saraya.flightmanagmentsystem.model.Airport;
import com.saraya.flightmanagmentsystem.model.Schedule;
import com.saraya.flightmanagmentsystem.model.ScheduleDto;
import com.saraya.flightmanagmentsystem.repository.AirportRepository;
import com.saraya.flightmanagmentsystem.repository.ScheduleRepository;
import com.saraya.flightmanagmentsystem.service.ScheduleService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
import java.util.List;


Expand All @@ -17,11 +25,18 @@ public class ScheduleController {
@Autowired
private final ScheduleService service;

@Autowired
private final ScheduleRepository repo;

@Autowired
private final AirportRepository airportRepository;
@Autowired
private ModelMapper mapper;

public ScheduleController(ScheduleService service, ModelMapper mapper) {
public ScheduleController(ScheduleService service, ScheduleRepository repo, AirportRepository airportRepository, ModelMapper mapper) {
this.service = service;
this.repo = repo;
this.airportRepository = airportRepository;
this.mapper = mapper;
}
@GetMapping("/viewAll")
Expand Down Expand Up @@ -52,4 +67,29 @@ public Schedule getByIdSchedule(@PathVariable long scheduleId) {

}


@PostMapping("/add")
@Transactional
public ResponseEntity<Schedule> createSchedule( @RequestBody Schedule scheduleRequest) {
ScheduleDto scheduleDto = mapper.map(scheduleRequest,ScheduleDto.class);
Schedule schedule = repo.save(scheduleRequest);

Airport airport = scheduleRequest.getAirport();
airport.setSchedule(schedule);
airportRepository.save(airport);

return new ResponseEntity<>(schedule, HttpStatus.CREATED);
}

@GetMapping("/schedule/{airportId}/schedule")
@Transactional
public ResponseEntity<Schedule> getScheduleByAirportId(@PathVariable(value = "airportId") Long airportId) {

Airport airport= airportRepository.findById(airportId)
.orElseThrow(() -> new ResourceNotFoundException("Not found Branch with id = " + airportId));

Schedule schedule = repo.findByAirport(airportId);
return new ResponseEntity<>(schedule, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.saraya.flightmanagmentsystem.controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.saraya.flightmanagmentsystem.model.*;
import com.saraya.flightmanagmentsystem.service.ScheduleFlightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Optional;

Expand All @@ -23,13 +23,13 @@ public ScheduleFlightController( ScheduleFlightService scheduleFlightService) {
}

@GetMapping("/viewAll")
@ResponseStatus(code = HttpStatus.OK)
// @ResponseStatus(code = HttpStatus.OK)
public List<ScheduleFlight> getAll(){

return scheduleFlightService.getAll();
}
@GetMapping("/viewById/{scheduleFlightId}")
@ResponseStatus(code = HttpStatus.OK)
//@ResponseStatus(code = HttpStatus.OK)
public Optional<ScheduleFlight> getById(@PathVariable Long scheduleFlightId){

return scheduleFlightService.getById(scheduleFlightId);
Expand All @@ -38,21 +38,20 @@ public Optional<ScheduleFlight> getById(@PathVariable Long scheduleFlightId){


@PutMapping("/update/{scheduleFlightId}")
@ResponseStatus(code = HttpStatus.OK)
public ScheduleFlight UpdateScheduleFlight( @RequestBody ScheduleFlight scheduleFlight,@PathVariable Long scheduleFlightId){
public ScheduleFlight UpdateScheduleFlight(@PathVariable(value = "scheduleFlightId") Long scheduleFlightId, @RequestBody ScheduleFlight scheduleFlight){

return scheduleFlightService.UpdateScheduleFlight(scheduleFlight,scheduleFlightId);
}

@DeleteMapping("/delete/{scheduleFlightId}")
@ResponseStatus(code = HttpStatus.OK)
// @ResponseStatus(code = HttpStatus.OK)
public void DeleteById(@PathVariable Long scheduleFlightId){
scheduleFlightService.DeleteById(scheduleFlightId);
}

@PostMapping("/add/{scheduleFlightId}")
@ResponseStatus(code = HttpStatus.CREATED)
public ScheduleFlight create(@RequestBody ScheduleFlight scheduleFlight,@PathVariable Long scheduleFlightId) {
@PostMapping ("/add/{scheduleFlightId}")
// @ResponseStatus(code = HttpStatus.CREATED)
public ScheduleFlight create( @RequestBody ScheduleFlight scheduleFlight, @PathVariable("scheduleFlightId") Long scheduleFlightId) {
return scheduleFlightService.create(scheduleFlight, scheduleFlightId);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saraya.flightmanagmentsystem.model;


import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import javax.persistence.*;
Expand All @@ -23,8 +24,16 @@ public class Airport {
private String airportCode;
private String airportLocation;
private String airportName;
// private String srcAirport;
// private String dstAirport;

@OneToOne
@JoinColumn(name = "sk_schedule_id")
@JsonIgnore
private Schedule schedule;

// @OneToOne(cascade = CascadeType.ALL)

// @JoinColumn(name = "sk_schedule_id")



}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ public class Booking {
private Long bookingId;
private LocalDate bookingDate;
private int noOfPassenger;
// @OneToOne ( cascade = CascadeType.ALL,fetch = FetchType.LAZY)
// @ToString.Exclude
// @JoinColumn(name = "flight_booking_id")
// @JsonIgnore
// private Flight flights;
// @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
// @ToString.Exclude
// @JsonIgnore
// @JoinColumn(name = "passenger_booking_id")
// private List<Passenger> PassengerList = new ArrayList<>();
@OneToOne (fetch = FetchType.LAZY)
@ToString.Exclude
@JoinColumn(name = "flight_booking_id")
private Flight flights;
@OneToOne (fetch = FetchType.LAZY)
@ToString.Exclude
@JoinColumn(name = "passenger_booking_id")
private Passenger passenger;


private Double ticketCost;
Expand Down
Loading

0 comments on commit 64bab82

Please sign in to comment.