36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
// src/Webshop.Api/Controllers/Customer/ReviewsController.cs
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using Webshop.Application.DTOs.Reviews;
|
|
using Webshop.Application.Services.Customers;
|
|
|
|
namespace Webshop.Api.Controllers.Customer
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/customer/[controller]")]
|
|
[Authorize(Roles = "Customer")]
|
|
public class ReviewsController : ControllerBase
|
|
{
|
|
private readonly ICustomerReviewService _customerReviewService;
|
|
|
|
public ReviewsController(ICustomerReviewService customerReviewService)
|
|
{
|
|
_customerReviewService = customerReviewService;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateReview([FromBody] CreateReviewDto reviewDto)
|
|
{
|
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var result = await _customerReviewService.CreateReviewAsync(reviewDto, userId);
|
|
|
|
if (result.Type == Application.ServiceResultType.Success)
|
|
{
|
|
return Ok(result.Value);
|
|
}
|
|
return BadRequest(new { Message = result.ErrorMessage });
|
|
}
|
|
}
|
|
} |