AdminShopInfo
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
// src/Webshop.Api/Controllers/Admin/AdminShopInfoController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application;
|
||||
using Webshop.Application.DTOs.Shop;
|
||||
using Webshop.Application.Services.Admin;
|
||||
|
||||
@@ -29,10 +31,13 @@ namespace Webshop.Api.Controllers.Admin
|
||||
/// Diese Daten werden typischerweise in einem "Stammdaten"- oder "Shop-Einstellungen"-Formular im Admin-Dashboard angezeigt.
|
||||
/// </remarks>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<AdminShopInfoDto>> GetShopInfo()
|
||||
[ProducesResponseType(typeof(AdminShopInfoDto), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetShopInfo()
|
||||
{
|
||||
var info = await _shopInfoService.GetShopInfoAsync();
|
||||
return Ok(info);
|
||||
var result = await _shopInfoService.GetShopInfoAsync();
|
||||
// GetShopInfoAsync erstellt einen Standardeintrag, wenn keiner vorhanden ist,
|
||||
// daher sollte es im Normalbetrieb immer erfolgreich sein.
|
||||
return Ok(result.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,14 +48,24 @@ namespace Webshop.Api.Controllers.Admin
|
||||
/// </remarks>
|
||||
/// <param name="shopInfoDto">Das Datenobjekt mit den neuen Shop-Informationen.</param>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> UpdateShopInfo([FromBody] AdminShopInfoDto shopInfoDto)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
await _shopInfoService.UpdateShopInfoAsync(shopInfoDto);
|
||||
return NoContent();
|
||||
|
||||
var result = await _shopInfoService.UpdateShopInfoAsync(shopInfoDto);
|
||||
|
||||
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