- Trips brauchten weitere Annotation um zyklische Abhängigkeit zu verhindern - Anpassen FriendCode länge und generierung
This commit is contained in:
@@ -6,14 +6,13 @@ import SuMoC.backend.trip.dtos.NewTripDTO;
|
||||
import SuMoC.backend.trip.dtos.TripDTO;
|
||||
import SuMoC.backend.trip.models.Trip;
|
||||
import SuMoC.backend.user.models.User;
|
||||
import SuMoC.backend.user.repository.UserRepository;
|
||||
import SuMoC.backend.user.service.CurrentUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
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;
|
||||
@@ -25,20 +24,14 @@ public class TripController {
|
||||
|
||||
private final TripService tripService;
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final CurrentUserService currentUser;
|
||||
|
||||
private final AdHocSuggestionService adHocSuggestionService;
|
||||
|
||||
// TODO extend security context with user id to avoid unnecessary db query
|
||||
private User getAuthenticatedUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
return userRepository.findByEmail(authentication.getName()).orElseThrow(() -> new RuntimeException("User not found"));
|
||||
}
|
||||
|
||||
@Operation(summary = "User uploads a new trip from the App.")
|
||||
@PostMapping("/uploadTrip")
|
||||
public ResponseEntity<Long> uploadTrip(@Valid @RequestBody NewTripDTO newTripDTO) {
|
||||
User user = getAuthenticatedUser();
|
||||
User user = currentUser.get();
|
||||
Trip savedTrip = tripService.addTrip(user, newTripDTO);
|
||||
|
||||
// let the ad hoc service suggest an alternative more ecofriendly route if appropriate
|
||||
@@ -50,7 +43,7 @@ public class TripController {
|
||||
@Operation(summary = "Retrieve all trips of the authenticated user.")
|
||||
@GetMapping("/getAllUserTrips")
|
||||
public ResponseEntity<List<TripDTO>> getAllUserTrips() {
|
||||
User user = getAuthenticatedUser();
|
||||
User user = currentUser.get();
|
||||
|
||||
List<TripDTO> userTrips = tripService.getAllTripsOfUser(user);
|
||||
return ResponseEntity.ok(userTrips);
|
||||
@@ -59,7 +52,7 @@ public class TripController {
|
||||
@Operation(summary = "Validate a trip for the authenticated user.")
|
||||
@PutMapping("/validateTrip/{tripId}")
|
||||
public ResponseEntity<Void> validateTrip(@PathVariable Long tripId) {
|
||||
User user = getAuthenticatedUser();
|
||||
User user = currentUser.get();
|
||||
|
||||
tripService.validateTrip(user, tripId);
|
||||
return ResponseEntity.ok().build();
|
||||
@@ -68,7 +61,7 @@ public class TripController {
|
||||
@Operation(summary = "Invalidate a trip for the authenticated user.")
|
||||
@PutMapping("/invalidateTrip/{tripId}")
|
||||
public ResponseEntity<Void> invalidateTrip(@PathVariable Long tripId) {
|
||||
User user = getAuthenticatedUser();
|
||||
User user = currentUser.get();
|
||||
|
||||
tripService.invalidateTrip(user, tripId);
|
||||
return ResponseEntity.ok().build();
|
||||
|
||||
Reference in New Issue
Block a user