adminreview
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
// src/Webshop.Api/Controllers/Admin/AdminReviewsController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application;
|
||||
using Webshop.Application.DTOs.Reviews;
|
||||
using Webshop.Application.Services.Admin;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
@@ -20,26 +24,42 @@ namespace Webshop.Api.Controllers.Admin
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<ReviewDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAllReviews()
|
||||
{
|
||||
var reviews = await _adminReviewService.GetAllReviewsAsync();
|
||||
return Ok(reviews);
|
||||
var result = await _adminReviewService.GetAllReviewsAsync();
|
||||
// In a simple GetAll, we typically just return the value on success.
|
||||
return Ok(result.Value);
|
||||
}
|
||||
|
||||
[HttpPost("{id}/approve")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> ApproveReview(Guid id)
|
||||
{
|
||||
var result = await _adminReviewService.ApproveReviewAsync(id);
|
||||
if (result.Type == Application.ServiceResultType.Success) return NoContent();
|
||||
return NotFound(new { Message = result.ErrorMessage });
|
||||
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => NoContent(),
|
||||
ServiceResultType.NotFound => NotFound(new { Message = result.ErrorMessage }),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." })
|
||||
};
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> DeleteReview(Guid id)
|
||||
{
|
||||
var result = await _adminReviewService.DeleteReviewAsync(id);
|
||||
if (result.Type == Application.ServiceResultType.Success) return NoContent();
|
||||
return NotFound(new { Message = result.ErrorMessage });
|
||||
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => NoContent(),
|
||||
ServiceResultType.NotFound => NotFound(new { Message = result.ErrorMessage }),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." })
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user