working customer post, get and delete
This commit is contained in:
51
AB.API/Controllers/BusinessPartner/CustomerController.cs
Normal file
51
AB.API/Controllers/BusinessPartner/CustomerController.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using AB.Contracts;
|
||||
using AB.Services.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AB.API.Controllers.BusinessPartner;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/customers")]
|
||||
public class CustomerController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly ICustomerService _customerService;
|
||||
|
||||
public CustomerController(ICustomerService customerService)
|
||||
{
|
||||
_customerService = customerService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<CustomerDto>>> GetCustomers(CancellationToken cancellationToken)
|
||||
{
|
||||
var customers = await _customerService.GetAllAsync(cancellationToken);
|
||||
|
||||
return Ok(customers);
|
||||
}
|
||||
|
||||
[HttpGet("{customerId:guid}")]
|
||||
public async Task<ActionResult<CustomerDto>> GetCustomerById(Guid customerId, CancellationToken cancellationToken)
|
||||
{
|
||||
var customer = await _customerService.GetByIdAsync(customerId, cancellationToken);
|
||||
|
||||
return Ok(customer);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<CreatedAtActionResult> CreateCustomer([FromBody] CustomerForCreationDto customerForCreation)
|
||||
{
|
||||
var customerDto = await _customerService.CreateAsync(customerForCreation);
|
||||
|
||||
return CreatedAtAction(nameof(CreateCustomer), new { customerId = customerDto.Id }, customerDto);
|
||||
}
|
||||
|
||||
[HttpDelete("{customerId:guid}")]
|
||||
public async Task<NoContentResult> DeleteCustomer(Guid customerId, CancellationToken cancellationToken)
|
||||
{
|
||||
await _customerService.DeleteAsync(customerId, cancellationToken);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
}
|
||||
48
AB.API/Controllers/BusinessPartner/SupplierController.cs
Normal file
48
AB.API/Controllers/BusinessPartner/SupplierController.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using AB.Contracts;
|
||||
using AB.Services.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AB.API.Controllers.BusinessPartner;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/suppliers")]
|
||||
public class SupplierController : ControllerBase
|
||||
{
|
||||
|
||||
public readonly ISupplierService _supplierService;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<SupplierDto>>> GetSupplieres(CancellationToken cancellationToken)
|
||||
{
|
||||
var suppliers = await _supplierService.GetAllAsync(cancellationToken);
|
||||
|
||||
return Ok(suppliers);
|
||||
}
|
||||
|
||||
[HttpGet("{supplierId:guid}")]
|
||||
public async Task<ActionResult<SupplierDto>> GetSupplierById(Guid supplierId, CancellationToken cancellationToken)
|
||||
{
|
||||
var supplierDto = await _supplierService.GetSupplierByIdAsync(supplierId, cancellationToken);
|
||||
|
||||
return Ok(supplierDto);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<CreatedAtActionResult> CreateSupplier([FromBody] SupplierForCreationDto supplierForCreation)
|
||||
{
|
||||
var supplierDto = await _supplierService.CreateAsync(supplierForCreation);
|
||||
|
||||
return CreatedAtAction(nameof(CreateSupplier), new { id = supplierDto.Id }, supplierDto);
|
||||
}
|
||||
|
||||
[HttpDelete("{supplierId:guid}")]
|
||||
public async Task<NoContentResult> DeleteSupplier(Guid supplierId, CancellationToken cancellationToken)
|
||||
{
|
||||
await _supplierService.DeleteAsync(supplierId, cancellationToken);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
using AB.Contracts;
|
||||
using AB.Services.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AB.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/customers")]
|
||||
public class CustomerController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly ICustomerService _customerService;
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetCustomers(CancellationToken cancellationToken)
|
||||
{
|
||||
var customers = await _customerService.GetAllAsync(cancellationToken);
|
||||
|
||||
return Ok(customers);
|
||||
}
|
||||
|
||||
[HttpGet("{customerId:guid}")]
|
||||
public async Task<IActionResult> GetCustomerById(Guid customerId, CancellationToken cancellationToken)
|
||||
{
|
||||
var customer = await _customerService.GetByIdAsync(customerId, cancellationToken);
|
||||
|
||||
return Ok(customer);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateCustomer([FromBody] CustomerForCreationDto customerForCreation)
|
||||
{
|
||||
var customerDto = await _customerService.CreateAsync(customerForCreation);
|
||||
|
||||
return CreatedAtAction(nameof(CreateCustomer), new {customerId = customerDto.Id}, customerDto);
|
||||
}
|
||||
|
||||
[HttpDelete("{customerId:guid}")]
|
||||
public async Task<IActionResult> DeleteCustomer(Guid customerId, CancellationToken cancellationToken)
|
||||
{
|
||||
await _customerService.DeleteAsync(customerId, cancellationToken);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user