-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductsController.cs
More file actions
134 lines (121 loc) · 6.39 KB
/
ProductsController.cs
File metadata and controls
134 lines (121 loc) · 6.39 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using ECommerceAPI.Application.Abstractions.Services;
using ECommerceAPI.Application.Consts;
using ECommerceAPI.Application.CustomAttributes;
using ECommerceAPI.Application.Enums;
using ECommerceAPI.Application.Features.Commands.Product.ChangeShowcase;
using ECommerceAPI.Application.Features.Commands.Product.CreateProduct;
using ECommerceAPI.Application.Features.Commands.Product.RemoveProduct;
using ECommerceAPI.Application.Features.Commands.Product.UpdateProduct;
using ECommerceAPI.Application.Features.Commands.Product.UpdateQrCodeProductStock;
using ECommerceAPI.Application.Features.Commands.ProductImageFile.RemoveProductImage;
using ECommerceAPI.Application.Features.Commands.ProductImageFile.UploadProductImage;
using ECommerceAPI.Application.Features.Queries.Product.GetAllProduct;
using ECommerceAPI.Application.Features.Queries.Product.GetByIdProduct;
using ECommerceAPI.Application.Features.Queries.ProductImageFile.GetProductImages;
using ECommerceAPI.Application.Features.Queries.ProductImageFile.GetProductShowCaseImage;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Net;
namespace ECommerceAPI.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ProductsController : ControllerBase
{
readonly IMediator _mediator;
readonly IProductService _productService;
public ProductsController(IMediator mediator, IProductService productService)
{
_mediator = mediator;
_productService = productService;
}
[HttpGet]
public async Task<IActionResult> Get([FromQuery] GetAllProductQueryRequest getAllProductQueryRequest)
{
var response = await _mediator.Send(getAllProductQueryRequest);
return Ok(response);
}
[HttpGet("qrcode/{productId}")]
public async Task<IActionResult> GetProductQrCode([FromRoute] string productId)
{
var qrCode = await _productService.ProductQrCodeAsync(productId);
return File(qrCode, "image/png");
}
[HttpPut("qrcode")]
public async Task<IActionResult> UpdateQrCodeProductStock(UpdateQrCodeProductStockCommandRequest updateQrCodeProductStockCommandRequest)
{
var response = await _mediator.Send(updateQrCodeProductStockCommandRequest);
return Ok(response);
}
[HttpGet("{id}")]
public async Task<IActionResult> Get([FromRoute] GetByIdProductQueryRequest getByIdProductQueryRequest)
{
var response = await _mediator.Send(getByIdProductQueryRequest);
return Ok(response);
}
[HttpPost]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Writing, Definition = "Create Product")]
public async Task<IActionResult> Post(CreateProductCommandRequest createProductCommandRequest)
{
var response = await _mediator.Send(createProductCommandRequest);
return StatusCode((int)HttpStatusCode.Created);
}
[HttpPut]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Updating, Definition = "Update Product")]
public async Task<IActionResult> Put([FromBody] UpdateProductCommandRequest updateProductCommandRequest)
{
var response = await _mediator.Send(updateProductCommandRequest);
return Ok();
}
[HttpDelete("{id}")]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Deleting, Definition = "Delete Product")]
public async Task<IActionResult> Delete([FromRoute] RemoveProductCommandRequest removeProductCommandRequest)
{
var response = await _mediator.Send(removeProductCommandRequest);
return Ok();
}
[HttpPost("[action]")]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Writing, Definition = "Upload Product File")]
public async Task<IActionResult> Upload([FromQuery] UploadProductImageCommandRequest uploadProductImageCommandRequest)
{
uploadProductImageCommandRequest.Files = Request.Form.Files;
var response = await _mediator.Send(uploadProductImageCommandRequest);
return Ok();
}
[HttpGet("[action]/{id}")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Reading, Definition = "Get Products Images")]
public async Task<IActionResult> GetProductImages([FromRoute] GetProductImagesQueryRequest getProductImagesQueryRequest)
{
var response = await _mediator.Send(getProductImagesQueryRequest);
return Ok(response);
}
[HttpDelete("[action]/{id}")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Deleting, Definition = "Delete Product Image")]
public async Task<IActionResult> DeleteProductImage([FromRoute] RemoveProductImageCommandRequest removeProductImageCommandRequest)
{
var response = await _mediator.Send(removeProductImageCommandRequest);
return Ok();
}
[HttpGet("[action]")]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Updating, Definition = "Change Showcase Image")]
public async Task<IActionResult> ChangeShowcaseImage([FromQuery] ChangeShowcaseCommandRequest changeShowcaseCommandRequest)
{
var response = await _mediator.Send(changeShowcaseCommandRequest);
return Ok(response);
}
[HttpGet("[action]")]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Products, ActionType = ActionType.Reading, Definition = "Get Showcase Image")]
public async Task<IActionResult> GetShowcaseImage([FromQuery] GetProductShowCaseImageQueryRequest getProductShowCaseImageQueryRequest)
{
var response = await _mediator.Send(getProductShowCaseImageQueryRequest);
return Ok(response);
}
}
}