-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from davewalker5/MC-258-Equipment-Register-API
Added the API for an equipment registry
- Loading branch information
Showing
39 changed files
with
2,233 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM mcr.microsoft.com/dotnet/core/aspnet:latest | ||
COPY musiccatalogue.api-1.23.0.0 /opt/musiccatalogue.api-1.23.0.0 | ||
WORKDIR /opt/musiccatalogue.api-1.23.0.0/bin | ||
COPY musiccatalogue.api-1.24.0.0 /opt/musiccatalogue.api-1.24.0.0 | ||
WORKDIR /opt/musiccatalogue.api-1.24.0.0/bin | ||
ENTRYPOINT [ "./MusicCatalogue.Api" ] |
130 changes: 130 additions & 0 deletions
130
src/MusicCatalogue.Api/Controllers/EquipmentController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MusicCatalogue.Entities.Database; | ||
using MusicCatalogue.Entities.Interfaces; | ||
using MusicCatalogue.Entities.Search; | ||
|
||
namespace MusicCatalogue.Api.Controllers | ||
{ | ||
[Authorize] | ||
[ApiController] | ||
[ApiConventionType(typeof(DefaultApiConventions))] | ||
[Route("[controller]")] | ||
public class EquipmentController : Controller | ||
{ | ||
private readonly IMusicCatalogueFactory _factory; | ||
|
||
public EquipmentController(IMusicCatalogueFactory factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
/// <summary> | ||
/// Return a list of all items of equipment matching the filter criteria | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpPost] | ||
[Route("search")] | ||
public async Task<ActionResult<List<Equipment>>> GetEquipmentAsync([FromBody] EquipmentSearchCriteria criteria) | ||
{ | ||
// Ideally, this method would use the GET verb but as more filtering criteria are added that leads | ||
// to an increasing number of query string parameters and a very messy URL. So the filter criteria | ||
// are POSTed in the request body, instead, and bound into a strongly typed criteria object | ||
|
||
var equipment = await _factory.Search.EquipmentSearchAsync(criteria); | ||
|
||
if (equipment == null) | ||
{ | ||
return NoContent(); | ||
} | ||
|
||
return equipment; | ||
} | ||
|
||
/// <summary> | ||
/// Return equipment details given an equipment type ID | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
[HttpGet] | ||
[Route("{id:int}")] | ||
public async Task<ActionResult<Equipment>> GetEquipmentByIdAsync(int id) | ||
{ | ||
var equipment = await _factory.Equipment.GetAsync(x => x.Id == id); | ||
|
||
if (equipment == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return equipment; | ||
} | ||
|
||
/// <summary> | ||
/// Add an item of equipment from a template contained in the request body | ||
/// </summary> | ||
/// <param name="template"></param> | ||
/// <returns></returns> | ||
[HttpPost] | ||
[Route("")] | ||
public async Task<ActionResult<Equipment>> AddEquipmentAsync([FromBody] Equipment template) | ||
{ | ||
var equipment = await _factory.Equipment.AddAsync( | ||
template.EquipmentTypeId, | ||
template.ManufacturerId, | ||
template.Description, | ||
template.Model, | ||
template.SerialNumber, | ||
template.IsWishListItem, | ||
template.Purchased, | ||
template.Price, | ||
template.RetailerId); | ||
return equipment; | ||
} | ||
|
||
/// <summary> | ||
/// Update an item of equipment from a template contained in the request body | ||
/// </summary> | ||
/// <param name="template"></param> | ||
/// <returns></returns> | ||
[HttpPut] | ||
[Route("")] | ||
public async Task<ActionResult<Equipment?>> UpdateEquipmentAsync([FromBody] Equipment template) | ||
{ | ||
var equipment = await _factory.Equipment.UpdateAsync( | ||
template.Id, | ||
template.EquipmentTypeId, | ||
template.ManufacturerId, | ||
template.Description, | ||
template.Model, | ||
template.SerialNumber, | ||
template.IsWishListItem, | ||
template.Purchased, | ||
template.Price, | ||
template.RetailerId); | ||
return equipment; | ||
} | ||
|
||
/// <summary> | ||
/// Delete an item of equipment given their ID | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
[HttpDelete] | ||
[Route("{id}")] | ||
public async Task<IActionResult> DeleteEquipment(int id) | ||
{ | ||
// Check the equipment exists, first | ||
var equipment = await _factory.Equipment.GetAsync(x => x.Id == id); | ||
if (equipment == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
// It does, so delete it | ||
await _factory.Equipment.DeleteAsync(id); | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/MusicCatalogue.Api/Controllers/EquipmentTypesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MusicCatalogue.Entities.Database; | ||
using MusicCatalogue.Entities.Exceptions; | ||
using MusicCatalogue.Entities.Interfaces; | ||
|
||
namespace MusicCatalogue.Api.Controllers | ||
{ | ||
[Authorize] | ||
[ApiController] | ||
[ApiConventionType(typeof(DefaultApiConventions))] | ||
[Route("[controller]")] | ||
public class EquipmentTypesController : Controller | ||
{ | ||
private readonly IMusicCatalogueFactory _factory; | ||
|
||
public EquipmentTypesController(IMusicCatalogueFactory factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
/// <summary> | ||
/// Return a list of all the equipment types in the catalogue matching the filter criteria in the request body | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet] | ||
[Route("")] | ||
public async Task<ActionResult<List<EquipmentType>>> GetEquipmentTypesAsync() | ||
{ | ||
var equipmentTypes = await _factory.EquipmentTypes.ListAsync(x => true); | ||
|
||
if (equipmentTypes == null) | ||
{ | ||
return NoContent(); | ||
} | ||
|
||
return equipmentTypes; | ||
} | ||
|
||
/// <summary> | ||
/// Return equipment type details given an equipment type ID | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
[HttpGet] | ||
[Route("{id:int}")] | ||
public async Task<ActionResult<EquipmentType>> GetEquipmentTypeByIdAsync(int id) | ||
{ | ||
var equipmentType = await _factory.EquipmentTypes.GetAsync(x => x.Id == id); | ||
|
||
if (equipmentType == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return equipmentType; | ||
} | ||
|
||
/// <summary> | ||
/// Add an equipment type from a template contained in the request body | ||
/// </summary> | ||
/// <param name="template"></param> | ||
/// <returns></returns> | ||
[HttpPost] | ||
[Route("")] | ||
public async Task<ActionResult<EquipmentType>> AddEquipmentTypeAsync([FromBody] EquipmentType template) | ||
{ | ||
var equipmentType = await _factory.EquipmentTypes.AddAsync(template.Name); | ||
return equipmentType; | ||
} | ||
|
||
/// <summary> | ||
/// Update an equipment type from a template contained in the request body | ||
/// </summary> | ||
/// <param name="template"></param> | ||
/// <returns></returns> | ||
[HttpPut] | ||
[Route("")] | ||
public async Task<ActionResult<EquipmentType?>> UpdateEquipmentTypeAsync([FromBody] EquipmentType template) | ||
{ | ||
var equipmentType = await _factory.EquipmentTypes.UpdateAsync(template.Id, template.Name); | ||
return equipmentType; | ||
} | ||
|
||
/// <summary> | ||
/// Delete an equipment type given their ID | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
[HttpDelete] | ||
[Route("{id}")] | ||
public async Task<IActionResult> DeleteEquipmentType(int id) | ||
{ | ||
// Check the equipment type exists, first | ||
var equipmentType = await _factory.EquipmentTypes.GetAsync(x => x.Id == id); | ||
if (equipmentType == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
try | ||
{ | ||
// It does, so delete them | ||
await _factory.EquipmentTypes.DeleteAsync(id); | ||
} | ||
catch (EquipmentTypeInUseException) | ||
{ | ||
// Equipment type is in use (has equipment associated with it) so this is a bad request | ||
return BadRequest(); | ||
} | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/MusicCatalogue.Api/Controllers/ManufacturersController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MusicCatalogue.Entities.Database; | ||
using MusicCatalogue.Entities.Exceptions; | ||
using MusicCatalogue.Entities.Interfaces; | ||
|
||
namespace MusicCatalogue.Api.Controllers | ||
{ | ||
[Authorize] | ||
[ApiController] | ||
[ApiConventionType(typeof(DefaultApiConventions))] | ||
[Route("[controller]")] | ||
public class ManufacturersController : Controller | ||
{ | ||
private readonly IMusicCatalogueFactory _factory; | ||
|
||
public ManufacturersController(IMusicCatalogueFactory factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
/// <summary> | ||
/// Return a list of all the manufacturers in the catalogue matching the filter criteria in the request body | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet] | ||
[Route("")] | ||
public async Task<ActionResult<List<Manufacturer>>> GetManufacturersAsync() | ||
{ | ||
var manufacturers = await _factory.Manufacturers.ListAsync(x => true); | ||
|
||
if (manufacturers == null) | ||
{ | ||
return NoContent(); | ||
} | ||
|
||
return manufacturers; | ||
} | ||
|
||
/// <summary> | ||
/// Return manufacturer details given a manufacturer ID | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
[HttpGet] | ||
[Route("{id:int}")] | ||
public async Task<ActionResult<Manufacturer>> GetManufacturerByIdAsync(int id) | ||
{ | ||
var manufacturer = await _factory.Manufacturers.GetAsync(x => x.Id == id); | ||
|
||
if (manufacturer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return manufacturer; | ||
} | ||
|
||
/// <summary> | ||
/// Add a manufacturer from a template contained in the request body | ||
/// </summary> | ||
/// <param name="template"></param> | ||
/// <returns></returns> | ||
[HttpPost] | ||
[Route("")] | ||
public async Task<ActionResult<Manufacturer>> AddManufacturerAsync([FromBody] Manufacturer template) | ||
{ | ||
var manufacturer = await _factory.Manufacturers.AddAsync(template.Name); | ||
return manufacturer; | ||
} | ||
|
||
/// <summary> | ||
/// Update a manufacturer from a template contained in the request body | ||
/// </summary> | ||
/// <param name="template"></param> | ||
/// <returns></returns> | ||
[HttpPut] | ||
[Route("")] | ||
public async Task<ActionResult<Manufacturer?>> UpdateManufacturerAsync([FromBody] Manufacturer template) | ||
{ | ||
var manufacturer = await _factory.Manufacturers.UpdateAsync(template.Id, template.Name); | ||
return manufacturer; | ||
} | ||
|
||
/// <summary> | ||
/// Delete a manufacturer given their ID | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
[HttpDelete] | ||
[Route("{id}")] | ||
public async Task<IActionResult> DeleteManufacturer(int id) | ||
{ | ||
// Check the manufacturer exists, first | ||
var manufacturer = await _factory.Manufacturers.GetAsync(x => x.Id == id); | ||
if (manufacturer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
try | ||
{ | ||
// They do, so delete them | ||
await _factory.Manufacturers.DeleteAsync(id); | ||
} | ||
catch (ManufacturerInUseException) | ||
{ | ||
// Manufacturer is in use (have equipment associated with them) so this is a bad request | ||
return BadRequest(); | ||
} | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.