add basic trip upload and retrieval functionality
This commit is contained in:
@@ -5,8 +5,10 @@ import SuMoC.backend.trip.dtos.NewTripDTO;
|
||||
import SuMoC.backend.trip.dtos.TripDTO;
|
||||
import SuMoC.backend.trip.models.Trip;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.validation.Valid;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -26,18 +28,19 @@ public class TripController {
|
||||
|
||||
@Operation(summary = "User uploads a new trip from the App.")
|
||||
@PostMapping("/uploadTrip")
|
||||
public ResponseEntity<Void> uploadTrip(@RequestBody NewTripDTO newTripDTO) {
|
||||
// TODO implement upload trip
|
||||
throw new NotImplementedException();
|
||||
//return ResponseEntity.ok().build();
|
||||
public ResponseEntity<Void> uploadTrip(@Valid @RequestBody NewTripDTO newTripDTO) {
|
||||
String userEmail = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
|
||||
tripService.addTrip(userEmail, newTripDTO);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Retrieve all trips of the authenticated user.")
|
||||
@GetMapping("/getAllUserTrips")
|
||||
public ResponseEntity<List<TripDTO>> getAllUserTrips(Authentication authentication) {
|
||||
String username = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
public ResponseEntity<List<TripDTO>> getAllUserTrips() {
|
||||
String userEmail = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
|
||||
List<TripDTO> userTrips = tripService.getAllTripsOfUser(username);
|
||||
List<TripDTO> userTrips = tripService.getAllTripsOfUser(userEmail);
|
||||
return ResponseEntity.ok(userTrips);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user