implement basic structure for ad hoc suggestions where we send user a notification for better alternatives after user finished trip
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
- notification logic still missing - Weather api missing
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
package SuMoC.backend.trip;
|
||||
|
||||
|
||||
import SuMoC.backend.suggestion.services.AdHocSuggestionService;
|
||||
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 io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -18,15 +20,14 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/trip")
|
||||
@RequiredArgsConstructor
|
||||
public class TripController {
|
||||
|
||||
private final TripService tripService;
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
public TripController(TripService tripService, UserRepository userRepository) {
|
||||
this.tripService = tripService;
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
private final AdHocSuggestionService adHocSuggestionService;
|
||||
|
||||
// TODO extend security context with user id to avoid unnecessary db query
|
||||
private User getAuthenticatedUser() {
|
||||
@@ -38,8 +39,11 @@ public class TripController {
|
||||
@PostMapping("/uploadTrip")
|
||||
public ResponseEntity<Void> uploadTrip(@Valid @RequestBody NewTripDTO newTripDTO) {
|
||||
User user = getAuthenticatedUser();
|
||||
Trip savedTrip = tripService.addTrip(user, newTripDTO);
|
||||
|
||||
// let the ad hoc service suggest an alternative more ecofriendly route if appropriate
|
||||
adHocSuggestionService.checkNewTripForNotifiedAlternativeSuggestion(savedTrip);
|
||||
|
||||
tripService.addTrip(user, newTripDTO);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user