Ignore:
Timestamp:
02/06/22 18:15:51 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
571e0df
Parents:
76712b2
Message:

add location feature

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java

    r76712b2 r6fe77af  
    22
    33import finki.diplomska.tripplanner.models.Location;
     4import finki.diplomska.tripplanner.models.User;
     5import finki.diplomska.tripplanner.models.dto.LocationDto;
    46import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
    57import finki.diplomska.tripplanner.service.LocationService;
    68import finki.diplomska.tripplanner.service.PlannerService;
    79import org.springframework.http.ResponseEntity;
     10import org.springframework.security.core.Authentication;
    811import org.springframework.web.bind.annotation.*;
    912
     
    8285    }
    8386
     87    @PostMapping("/add")
     88    public ResponseEntity<Location> save(@RequestBody LocationDto locationDto, Authentication authentication) {
     89        User user = (User) authentication.getPrincipal();
     90        return this.locationService.save(locationDto, user.getUsername())
     91                .map(location -> ResponseEntity.ok().body(location))
     92                .orElseGet(() -> ResponseEntity.badRequest().build());
     93    }
    8494}
Note: See TracChangeset for help on using the changeset viewer.