shop info

This commit is contained in:
Tizian.Breuch
2025-09-25 16:38:11 +02:00
parent 654acddf42
commit eb1f58d81f
3 changed files with 15 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
// src/Webshop.Api/Controllers/Public/ShopInfoController.cs // src/Webshop.Api/Controllers/Public/ShopInfoController.cs
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks; using System.Threading.Tasks;
using Webshop.Application.DTOs.Shop; using Webshop.Application.DTOs.Shop;
@@ -29,10 +30,12 @@ namespace Webshop.Api.Controllers.Public
/// Diese Informationen sind für jeden Besucher sichtbar und werden typischerweise im Footer, auf der Kontaktseite oder im Impressum verwendet. /// Diese Informationen sind für jeden Besucher sichtbar und werden typischerweise im Footer, auf der Kontaktseite oder im Impressum verwendet.
/// </remarks> /// </remarks>
[HttpGet] [HttpGet]
public async Task<ActionResult<PublicShopInfoDto>> GetPublicShopInfo() [ProducesResponseType(typeof(PublicShopInfoDto), StatusCodes.Status200OK)]
public async Task<IActionResult> GetPublicShopInfo()
{ {
var info = await _shopInfoService.GetPublicShopInfoAsync(); var result = await _shopInfoService.GetPublicShopInfoAsync();
return Ok(info); // Dieser Service-Aufruf ist so konzipiert, dass er immer ein erfolgreiches Ergebnis liefert.
return Ok(result.Value);
} }
} }
} }

View File

@@ -1,11 +1,12 @@
// src/Webshop.Application/Services/Public/IShopInfoService.cs // src/Webshop.Application/Services/Public/IShopInfoService.cs
using System.Threading.Tasks; using System.Threading.Tasks;
using Webshop.Application;
using Webshop.Application.DTOs.Shop; using Webshop.Application.DTOs.Shop;
namespace Webshop.Application.Services.Public namespace Webshop.Application.Services.Public
{ {
public interface IShopInfoService public interface IShopInfoService
{ {
Task<PublicShopInfoDto> GetPublicShopInfoAsync(); Task<ServiceResult<PublicShopInfoDto>> GetPublicShopInfoAsync();
} }
} }

View File

@@ -1,5 +1,6 @@
// src/Webshop.Application/Services/Public/ShopInfoService.cs // src/Webshop.Application/Services/Public/ShopInfoService.cs
using System.Threading.Tasks; using System.Threading.Tasks;
using Webshop.Application;
using Webshop.Application.DTOs.Shop; using Webshop.Application.DTOs.Shop;
using Webshop.Domain.Interfaces; using Webshop.Domain.Interfaces;
@@ -14,17 +15,18 @@ namespace Webshop.Application.Services.Public
_shopInfoRepository = shopInfoRepository; _shopInfoRepository = shopInfoRepository;
} }
public async Task<PublicShopInfoDto> GetPublicShopInfoAsync() public async Task<ServiceResult<PublicShopInfoDto>> GetPublicShopInfoAsync()
{ {
var shopInfo = await _shopInfoRepository.GetAsync(); var shopInfo = await _shopInfoRepository.GetAsync();
if (shopInfo == null) if (shopInfo == null)
{ {
// Gib Standardwerte zurück, wenn nichts konfiguriert ist // Gib Standardwerte zurück, wenn nichts konfiguriert ist
return new PublicShopInfoDto { ShopName = "Webshop" }; var defaultDto = new PublicShopInfoDto { ShopName = "Webshop" };
return ServiceResult.Ok(defaultDto);
} }
return new PublicShopInfoDto var dto = new PublicShopInfoDto
{ {
ShopName = shopInfo.ShopName, ShopName = shopInfo.ShopName,
Slogan = shopInfo.Slogan, Slogan = shopInfo.Slogan,
@@ -38,6 +40,8 @@ namespace Webshop.Application.Services.Public
InstagramUrl = shopInfo.InstagramUrl, InstagramUrl = shopInfo.InstagramUrl,
TwitterUrl = shopInfo.TwitterUrl TwitterUrl = shopInfo.TwitterUrl
}; };
return ServiceResult.Ok(dto);
} }
} }
} }