Changeset 84d0fbb for trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/PlannerRestController.java
- Timestamp:
- 12/19/21 19:39:00 (3 years ago)
- Branches:
- master
- Children:
- bdd6491
- Parents:
- 1ad8e64
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/PlannerRestController.java
r1ad8e64 r84d0fbb 3 3 import finki.diplomska.tripplanner.models.Location; 4 4 import finki.diplomska.tripplanner.models.Planner; 5 import finki.diplomska.tripplanner.models.User; 5 6 import finki.diplomska.tripplanner.models.dto.PlannerDto; 6 7 import finki.diplomska.tripplanner.service.LocationService; … … 9 10 import org.springframework.http.MediaType; 10 11 import org.springframework.http.ResponseEntity; 12 import org.springframework.security.core.Authentication; 11 13 import org.springframework.web.bind.annotation.*; 12 14 import org.springframework.web.bind.annotation.RestController; 13 15 16 import javax.validation.Valid; 14 17 import java.util.ArrayList; 15 18 import java.util.List; … … 17 20 18 21 @RestController 19 @CrossOrigin(origins = "http://localhost:4200" )22 @CrossOrigin(origins = "http://localhost:4200", exposedHeaders = "token") 20 23 @RequestMapping(value = "/api") 21 24 public class PlannerRestController { … … 31 34 public List<Planner> getAllPlanners(){ 32 35 return this.plannerService.getAllPlaners(); 36 } 37 38 39 @GetMapping(value = "/planners/user") 40 public List<Planner> getPlannersByUser(Authentication authentication){ 41 User user = (User) authentication.getPrincipal(); 42 return this.plannerService.getPlannersByUser(user.getUsername()); 33 43 } 34 44 … … 57 67 @PostMapping(value = "/planner/new", consumes= MediaType.APPLICATION_JSON_VALUE) 58 68 @ResponseStatus(HttpStatus.CREATED) 59 public ResponseEntity<Planner> newPlanner(@RequestBody PlannerDto plannerDto) { 60 return this.plannerService.newPlanner(plannerDto) 69 public ResponseEntity<?> newPlanner(@Valid @RequestBody PlannerDto plannerDto, Authentication authentication) { 70 71 User user = (User) authentication.getPrincipal(); 72 return this.plannerService.newPlanner(plannerDto, user.getUsername()) 61 73 .map(planner -> ResponseEntity.ok().body(planner)) 62 74 .orElseGet(() -> ResponseEntity.badRequest().build()); … … 65 77 66 78 @PutMapping(value ="edit/planner/{id}", consumes= MediaType.APPLICATION_JSON_VALUE) 67 public ResponseEntity<Planner> editPlanner(@PathVariable Long id, @RequestBody PlannerDto plannerDto){ 68 return this.plannerService.editPlanner(id, plannerDto) 79 public ResponseEntity<Planner> editPlanner(@PathVariable Long id, @Valid @RequestBody PlannerDto plannerDto, Authentication authentication){ 80 User user = (User) authentication.getPrincipal(); 81 return this.plannerService.editPlanner(id, plannerDto, user.getUsername()) 69 82 .map(planner -> ResponseEntity.ok().body(planner)) 70 83 .orElseGet(()-> ResponseEntity.badRequest().build());
Note:
See TracChangeset
for help on using the changeset viewer.