53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
// src/Webshop.Api/Controllers/Admin/AdminSettingsController.cs
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Webshop.Application;
|
|
using Webshop.Application.DTOs.Settings;
|
|
using Webshop.Application.Services.Admin.Interfaces;
|
|
|
|
namespace Webshop.Api.Controllers.Admin
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/admin/[controller]")]
|
|
[Authorize(Roles = "Admin")]
|
|
public class AdminSettingsController : ControllerBase
|
|
{
|
|
private readonly IAdminSettingService _adminSettingService;
|
|
|
|
public AdminSettingsController(IAdminSettingService adminSettingService)
|
|
{
|
|
_adminSettingService = adminSettingService;
|
|
}
|
|
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(Dictionary<string, List<SettingDto>>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> GetAllSettings()
|
|
{
|
|
var result = await _adminSettingService.GetAllGroupedAsync();
|
|
return Ok(result.Value);
|
|
}
|
|
|
|
[HttpPut]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> UpdateSettings([FromBody] List<SettingDto> settings)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
var result = await _adminSettingService.UpdateSettingsAsync(settings);
|
|
|
|
return result.Type switch
|
|
{
|
|
ServiceResultType.Success => NoContent(),
|
|
ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }),
|
|
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." })
|
|
};
|
|
}
|
|
}
|
|
} |