1- // using Mediator;
2- // using Microsoft.AspNetCore.Authorization;
3- // using Microsoft.AspNetCore.Http.Timeouts;
4- // using Microsoft.AspNetCore.Mvc;
5- // using Riber.Api.Attributes;
6- // using Riber.Api.Requests;
7- // using Riber.Application.Common;
8- // using Riber.Application.Features.Products.Commands;
9- // using Riber.Infrastructure.Settings;
10- //
11- // namespace Riber.Api.Controllers;
12- //
13- // [ApiController]
14- // [Authorize]
15- // [Route("api/v{version:apiVersion}/product")]
16- // [ApiVersion("1.0")]
17- // [Produces("application/json")]
18- // [Consumes("application/json", "multipart/form-data")]
19- // public sealed class ProductController(IMediator mediator) : ControllerBase
20- // {
21- // [HttpPost]
22- // [RequestSizeLimit(3_145_728)]
23- // [RequestFormLimits(MultipartBodyLengthLimit = 3_145_728)]
24- // [RequirePermission(PermissionsSettings.Products.Create)]
25- // [RequestTimeout("standard")]
26- // [ProducesResponseType<Result<CreateProductCommandResponse>>(StatusCodes.Status201Created)]
27- // public async Task<IActionResult> CreateProduct(
28- // [FromForm] CreateProductRequest request,
29- // CancellationToken cancellationToken)
30- // {
31- // var response = await mediator.Send(new CreateProductCommand(
32- // Name: request.Name,
33- // Description: request.Description,
34- // Price: request.Price,
35- // CategoryId: request.CategoryId,
36- // ImageStream: request.Image?.OpenReadStream(),
37- // ImageName: request.Image?.FileName ?? string.Empty,
38- // ImageContent: request.Image?.ContentType ?? string.Empty
39- // ), cancellationToken);
40- // return Created($"api/product/{response.Value.ProductId}", response);
41- // }
42- // }
1+ using Asp . Versioning ;
2+ using Mediator ;
3+ using Microsoft . AspNetCore . Authorization ;
4+ using Microsoft . AspNetCore . Http . Timeouts ;
5+ using Microsoft . AspNetCore . Mvc ;
6+ using Riber . Api . Attributes ;
7+ using Riber . Api . Extensions ;
8+ using Riber . Api . Requests . Product ;
9+ using Riber . Application . Common ;
10+ using Riber . Application . Features . Products . Commands ;
11+ using Riber . Infrastructure . Settings ;
12+
13+ namespace Riber . Api . Controllers ;
14+
15+ [ ApiController ]
16+ [ Authorize ]
17+ [ Route ( "api/v{version:apiVersion}/product" ) ]
18+ [ ApiVersion ( "1.0" ) ]
19+ [ Produces ( "application/json" ) ]
20+ [ Consumes ( "application/json" , "multipart/form-data" ) ]
21+ public sealed class ProductController ( IMediator mediator ) : ControllerBase
22+ {
23+ [ HttpPost ]
24+ [ RequestSizeLimit ( 3_145_728 ) ]
25+ [ RequestFormLimits ( MultipartBodyLengthLimit = 3_145_728 ) ]
26+ [ RequirePermission ( PermissionsSettings . Products . Create ) ]
27+ [ RequestTimeout ( "standard" ) ]
28+ [ ProducesResponseType < Result < CreateProductCommandResponse > > ( StatusCodes . Status201Created ) ]
29+ public async Task < IActionResult > CreateProduct (
30+ [ FromForm ] CreateProductRequest request ,
31+ CancellationToken cancellationToken )
32+ {
33+ var response = await mediator . Send ( request . ToCommand ( ) , cancellationToken ) ;
34+ return response . ToHttpResult ( $ "/api/product/{ response . Value ? . ProductId } ") ;
35+ }
36+ }
0 commit comments