Update to latest packages and show examples
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
using Asp.Versioning;
|
||||
using GerstITS.Data;
|
||||
using GerstITS.Examples.Api.Versioning;
|
||||
using GerstITS.Examples.Logic.Customers;
|
||||
using GerstITS.Search;
|
||||
using GerstITS.Validation;
|
||||
using GerstITS.Web.Api;
|
||||
using GerstITS.Web.Api.FluentApi;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GerstITS.Examples.Api.Controllers._1._1;
|
||||
|
||||
/// <summary>
|
||||
/// Is responsible to manage customers backed by the repository based data access.
|
||||
/// </summary>
|
||||
[ApiController,
|
||||
ApiVersion(Versions._1_1),
|
||||
Route(ApplicationEnvironment.WebApi.ControllerRouteTemplate)]
|
||||
public class CustomerController : FluentApiControllerBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly ICustomerProvider _provider;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public CustomerController(ICustomerProvider provider,
|
||||
IValidator validator)
|
||||
: base(validator)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a customer by specified id. Deactivated customers are excluded by default.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the customer.</param>
|
||||
/// <param name="includeInactive">Includes deactivated (soft deleted) customers if set to true.</param>
|
||||
/// <returns>Returns a customer.</returns>
|
||||
[HttpGet,
|
||||
Route("{id}")]
|
||||
public IActionResult Get(int id, [FromQuery] bool includeInactive = false)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Get(x => _provider.GetById(x, includeInactive));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches customers by specified filter using the search engine (paging, sorting, filtering).
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter criteria of the search.</param>
|
||||
/// <returns>Returns the matching customers including the total count.</returns>
|
||||
[HttpPost,
|
||||
Route("Search")]
|
||||
public IActionResult Search([FromBody] CustomerSearchFilter filter)
|
||||
{
|
||||
return Api().Use(filter)
|
||||
.Get(_provider.Search);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new customer.
|
||||
/// </summary>
|
||||
/// <param name="customer">Customer to create.</param>
|
||||
/// <returns>Returns the created customer.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Create([FromBody] Customer customer)
|
||||
{
|
||||
return Api().Use(customer)
|
||||
.Create(_provider.Create);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing customer.
|
||||
/// </summary>
|
||||
/// <param name="customer">Customer to update.</param>
|
||||
/// <returns>Returns the updated customer.</returns>
|
||||
[HttpPut]
|
||||
public IActionResult Update([FromBody] Customer customer)
|
||||
{
|
||||
return Api().Use(customer)
|
||||
.Update(_provider.Update);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a customer. Performs a soft delete by default, a permanent delete if force is set to true.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the customer.</param>
|
||||
/// <param name="force">Deletes the customer permanently if set to true.</param>
|
||||
/// <returns>Returns true if the customer was deleted.</returns>
|
||||
[HttpDelete,
|
||||
Route("{id}")]
|
||||
public IActionResult Delete(int id, [FromQuery] bool force = false)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Delete(x => _provider.Delete(x, force));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imports customers using bulk operations.
|
||||
/// </summary>
|
||||
/// <param name="customers">Customers to import.</param>
|
||||
/// <returns>Returns the bulk operation result.</returns>
|
||||
[HttpPost,
|
||||
Route("Import")]
|
||||
public IActionResult Import([FromBody] IEnumerable<Customer> customers)
|
||||
{
|
||||
return Api().Use(customers)
|
||||
.Create(_provider.Import);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all notes of a customer ordered by their validity.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the customer.</param>
|
||||
/// <returns>Returns the notes of the customer.</returns>
|
||||
[HttpGet,
|
||||
Route("{id}/Notes")]
|
||||
public IActionResult GetNotes(int id)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Get(_provider.GetNotes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a historicized note to a customer.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the customer.</param>
|
||||
/// <param name="note">Note to add.</param>
|
||||
/// <returns>Returns the created note.</returns>
|
||||
[HttpPost,
|
||||
Route("{id}/Notes")]
|
||||
public IActionResult AddNote(int id, [FromBody] CustomerNote note)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Create(x => _provider.AddNote(x, note.Text));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user