AdminShopInfo
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
// src/Webshop.Application/Services/Admin/IAdminShopInfoService.cs
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application;
|
||||
using Webshop.Application.DTOs.Shop;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public interface IAdminShopInfoService
|
||||
{
|
||||
Task<AdminShopInfoDto> GetShopInfoAsync();
|
||||
Task UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto);
|
||||
Task<ServiceResult<AdminShopInfoDto>> GetShopInfoAsync();
|
||||
Task<ServiceResult> UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user