65 lines
2.5 KiB
C#
65 lines
2.5 KiB
C#
// 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
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/admin/[controller]")]
|
|
[Authorize(Roles = "Admin")]
|
|
public class AdminReviewsController : ControllerBase
|
|
{
|
|
private readonly IAdminReviewService _adminReviewService;
|
|
|
|
public AdminReviewsController(IAdminReviewService adminReviewService)
|
|
{
|
|
_adminReviewService = adminReviewService;
|
|
}
|
|
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(IEnumerable<ReviewDto>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> GetAllReviews()
|
|
{
|
|
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);
|
|
|
|
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);
|
|
|
|
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." })
|
|
};
|
|
}
|
|
}
|
|
} |