trips: add controller, service, mappers, dtos etc.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package SuMoC.backend.trip;
|
||||
|
||||
|
||||
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 org.apache.commons.lang3.NotImplementedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/trip")
|
||||
public class TripController {
|
||||
private TripService tripService;
|
||||
|
||||
@Autowired
|
||||
public TripController(TripService tripService) {
|
||||
this.tripService = tripService;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Operation(summary = "Retrieve all trips of the authenticated user.")
|
||||
@GetMapping("/getAllUserTrips")
|
||||
public ResponseEntity<List<TripDTO>> getAllUserTrips(Authentication authentication) {
|
||||
String username = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
|
||||
List<TripDTO> userTrips = tripService.getAllTripsOfUser(username);
|
||||
return ResponseEntity.ok(userTrips);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user