/* Copyright 2019 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. */ using System; using docdb_dotnet_starter.Models; using docdb_dotnet_starter.Services; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; namespace docdb_dotnet_starter.Controllers { [Route("api/[controller]")] [ApiController] public class LocationsController : ControllerBase { private readonly LocationsService _locationService; public LocationsController(LocationsService locationService) { _locationService = locationService; } [HttpGet] public ActionResult> Get(int pageLength) { var locations = _locationService.Get(pageLength); return locations; } [HttpGet("{id:length(24)}", Name = "GetLocation")] public ActionResult Get(string id) { var location = _locationService.Get(id); if (location == null) { return NotFound(); } return location; } [HttpPost] public ActionResult Create(Location location) { _locationService.Create(location); return CreatedAtRoute("GetLocation", new { id = location.Id.ToString() }, location); } [HttpPut("{id:length(24)}")] public IActionResult Update(string id, Location locationIn) { var location = _locationService.Get(id); if (location == null) { return NotFound(); } _locationService.Update(id, locationIn); return NoContent(); } [HttpDelete("{id:length(24)}")] public IActionResult Delete(string id) { var location = _locationService.Get(id); if (location == null) { return NotFound(); } _locationService.Delete(location.Id); return NoContent(); } } }