AdminShopInfo

This commit is contained in:
Tizian.Breuch
2025-09-25 14:47:00 +02:00
parent 8f222ef4aa
commit 910cab656b
3 changed files with 33 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
// src/Webshop.Application/Services/Admin/AdminShopInfoService.cs
using System;
using System.Threading.Tasks;
using Webshop.Application;
using Webshop.Application.DTOs.Shop;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
@@ -16,7 +17,7 @@ namespace Webshop.Application.Services.Admin
_shopInfoRepository = shopInfoRepository;
}
public async Task<AdminShopInfoDto> GetShopInfoAsync()
public async Task<ServiceResult<AdminShopInfoDto>> GetShopInfoAsync()
{
var shopInfo = await _shopInfoRepository.GetAsync();
@@ -27,7 +28,7 @@ namespace Webshop.Application.Services.Admin
await _shopInfoRepository.AddAsync(shopInfo);
}
return new AdminShopInfoDto
var dto = new AdminShopInfoDto
{
ShopName = shopInfo.ShopName,
Slogan = shopInfo.Slogan,
@@ -43,14 +44,18 @@ namespace Webshop.Application.Services.Admin
InstagramUrl = shopInfo.InstagramUrl,
TwitterUrl = shopInfo.TwitterUrl
};
return ServiceResult.Ok(dto);
}
public async Task UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto)
public async Task<ServiceResult> UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto)
{
var shopInfo = await _shopInfoRepository.GetAsync();
if (shopInfo == null)
{
throw new InvalidOperationException("ShopInfo entity does not exist and cannot be updated.");
// Dieser Fall sollte theoretisch nie eintreten, da GetShopInfoAsync die Entität erstellt.
// Zur Sicherheit fangen wir ihn trotzdem ab.
return ServiceResult.Fail(ServiceResultType.NotFound, "ShopInfo-Entität existiert nicht und kann nicht aktualisiert werden.");
}
// Mappe die Werte vom DTO auf die Entität
@@ -69,6 +74,7 @@ namespace Webshop.Application.Services.Admin
shopInfo.TwitterUrl = shopInfoDto.TwitterUrl;
await _shopInfoRepository.UpdateAsync(shopInfo);
return ServiceResult.Ok();
}
}
}