-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathSalesController.cs
More file actions
43 lines (39 loc) · 1.32 KB
/
SalesController.cs
File metadata and controls
43 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using ECommerce.API.Interfaces.Services;
using ECommerce.API.Models;
using ECommerce.Shared.Models;
using Microsoft.AspNetCore.Mvc;
namespace ECommerce.API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class SalesController(ISaleService saleService) : ControllerBase
{
[HttpPost]
public async Task<IActionResult> PostSale([FromBody] List<CreateSaleItemDto> saleItems)
{
var success = await saleService.PostSaleAsync(saleItems);
return success switch
{
null => NotFound(),
true => NoContent(),
false => StatusCode(StatusCodes.Status500InternalServerError)
};
}
[HttpGet]
public async Task<ActionResult<PagedResponse<Sale>>> GetItemsAsync([FromQuery] PaginationParams paginationParams)
{
var pagedResponse = await saleService.GetSalesAsync(paginationParams);
if (pagedResponse.TotalRecords == 0) return NotFound();
return Ok(pagedResponse);
}
[HttpDelete]
public async Task<IActionResult> DeleteSaleAsync([FromQuery] int saleId)
{
var success = await saleService.DeleteSaleByIdAsync(saleId);
return success switch
{
null => NotFound(),
true => NoContent(),
false => StatusCode(StatusCodes.Status500InternalServerError)
};
}
}