customerreviwew

This commit is contained in:
Tizian.Breuch
2025-09-25 16:25:36 +02:00
parent 1f28c189ce
commit 32d6f4508f
3 changed files with 55 additions and 13 deletions

View File

@@ -1,8 +1,10 @@
// src/Webshop.Api/Controllers/Customer/ReviewsController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using System.Threading.Tasks;
using Webshop.Application;
using Webshop.Application.DTOs.Reviews;
using Webshop.Application.Services.Customers;
@@ -21,16 +23,34 @@ namespace Webshop.Api.Controllers.Customer
}
[HttpPost]
[ProducesResponseType(typeof(ReviewDto), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)]
public async Task<IActionResult> CreateReview([FromBody] CreateReviewDto reviewDto)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrEmpty(userId))
{
return Unauthorized(new { Message = "Benutzer konnte nicht identifiziert werden." });
}
var result = await _customerReviewService.CreateReviewAsync(reviewDto, userId);
if (result.Type == Application.ServiceResultType.Success)
return result.Type switch
{
return Ok(result.Value);
}
return BadRequest(new { Message = result.ErrorMessage });
ServiceResultType.Success => CreatedAtAction(null, new { id = result.Value!.Id }, result.Value), // 201 Created
ServiceResultType.Unauthorized => Unauthorized(new { Message = result.ErrorMessage }),
ServiceResultType.Forbidden => Forbid(), // 403 Forbidden
ServiceResultType.Conflict => Conflict(new { Message = result.ErrorMessage }), // 409 Conflict
_ => BadRequest(new { Message = result.ErrorMessage }) // 400 for InvalidInput or other failures
};
}
}
}