/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at http://www.apache.org/licenses/LICENSE-2.0 or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package software.amazon.documentdb.springboot.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import software.amazon.documentdb.springboot.model.Location; import software.amazon.documentdb.springboot.service.LocationService; import java.util.List; @RestController @RequestMapping("/api/locations") public class LocationController { @Autowired private LocationService locationService; @GetMapping("") public ResponseEntity> getAllLocations() { List locations = locationService.getAllLocations(); return new ResponseEntity<>(locations, HttpStatus.OK); } @GetMapping("/{id}") public ResponseEntity getLocationById(@PathVariable String id) { Location location = locationService.getLocationById(id); return new ResponseEntity<>(location, HttpStatus.OK); } @PostMapping("") public ResponseEntity createLocation(@RequestBody Location location) { Location newLocation = locationService.createLocation(location); return new ResponseEntity<>(newLocation, HttpStatus.CREATED); } @PutMapping("/{id}") public ResponseEntity updateLocation(@PathVariable String id, @RequestBody Location location) { locationService.updateLocation(id, location); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @DeleteMapping("/{id}") public ResponseEntity deleteLocation(@PathVariable String id) { locationService.deleteLocation(id); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } }