shop info

This commit is contained in:
Tizian.Breuch
2025-08-12 11:07:15 +02:00
parent 0a43b1d7e8
commit 1692fe198e
13 changed files with 387 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
// src/Webshop.Application/Services/Admin/AdminShopInfoService.cs
using System;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Shop;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Admin
{
public class AdminShopInfoService : IAdminShopInfoService
{
private readonly IShopInfoRepository _shopInfoRepository;
public AdminShopInfoService(IShopInfoRepository shopInfoRepository)
{
_shopInfoRepository = shopInfoRepository;
}
public async Task<AdminShopInfoDto> GetShopInfoAsync()
{
var shopInfo = await _shopInfoRepository.GetAsync();
if (shopInfo == null)
{
// Erstelle einen Standardeintrag, falls keiner existiert
shopInfo = new ShopInfo { Id = Guid.NewGuid(), ShopName = "Mein Webshop", ContactEmail = "admin@example.com" };
await _shopInfoRepository.AddAsync(shopInfo);
}
return new AdminShopInfoDto
{
ShopName = shopInfo.ShopName,
Slogan = shopInfo.Slogan,
ContactEmail = shopInfo.ContactEmail,
PhoneNumber = shopInfo.PhoneNumber,
Street = shopInfo.Street,
City = shopInfo.City,
PostalCode = shopInfo.PostalCode,
Country = shopInfo.Country,
VatNumber = shopInfo.VatNumber,
CompanyRegistrationNumber = shopInfo.CompanyRegistrationNumber,
FacebookUrl = shopInfo.FacebookUrl,
InstagramUrl = shopInfo.InstagramUrl,
TwitterUrl = shopInfo.TwitterUrl
};
}
public async Task UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto)
{
var shopInfo = await _shopInfoRepository.GetAsync();
if (shopInfo == null)
{
throw new InvalidOperationException("ShopInfo entity does not exist and cannot be updated.");
}
// Mappe die Werte vom DTO auf die Entität
shopInfo.ShopName = shopInfoDto.ShopName;
shopInfo.Slogan = shopInfoDto.Slogan;
shopInfo.ContactEmail = shopInfoDto.ContactEmail;
shopInfo.PhoneNumber = shopInfoDto.PhoneNumber;
shopInfo.Street = shopInfoDto.Street;
shopInfo.City = shopInfoDto.City;
shopInfo.PostalCode = shopInfoDto.PostalCode;
shopInfo.Country = shopInfoDto.Country;
shopInfo.VatNumber = shopInfoDto.VatNumber;
shopInfo.CompanyRegistrationNumber = shopInfoDto.CompanyRegistrationNumber;
shopInfo.FacebookUrl = shopInfoDto.FacebookUrl;
shopInfo.InstagramUrl = shopInfoDto.InstagramUrl;
shopInfo.TwitterUrl = shopInfoDto.TwitterUrl;
await _shopInfoRepository.UpdateAsync(shopInfo);
}
}
}

View File

@@ -0,0 +1,12 @@
// src/Webshop.Application/Services/Admin/IAdminShopInfoService.cs
using System.Threading.Tasks;
using Webshop.Application.DTOs.Shop;
namespace Webshop.Application.Services.Admin
{
public interface IAdminShopInfoService
{
Task<AdminShopInfoDto> GetShopInfoAsync();
Task UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto);
}
}

View File

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

View File

@@ -0,0 +1,43 @@
// src/Webshop.Application/Services/Public/ShopInfoService.cs
using System.Threading.Tasks;
using Webshop.Application.DTOs.Shop;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Public
{
public class ShopInfoService : IShopInfoService
{
private readonly IShopInfoRepository _shopInfoRepository;
public ShopInfoService(IShopInfoRepository shopInfoRepository)
{
_shopInfoRepository = shopInfoRepository;
}
public async Task<PublicShopInfoDto> GetPublicShopInfoAsync()
{
var shopInfo = await _shopInfoRepository.GetAsync();
if (shopInfo == null)
{
// Gib Standardwerte zurück, wenn nichts konfiguriert ist
return new PublicShopInfoDto { ShopName = "Webshop" };
}
return new PublicShopInfoDto
{
ShopName = shopInfo.ShopName,
Slogan = shopInfo.Slogan,
ContactEmail = shopInfo.ContactEmail,
PhoneNumber = shopInfo.PhoneNumber,
Street = shopInfo.Street,
City = shopInfo.City,
PostalCode = shopInfo.PostalCode,
Country = shopInfo.Country,
FacebookUrl = shopInfo.FacebookUrl,
InstagramUrl = shopInfo.InstagramUrl,
TwitterUrl = shopInfo.TwitterUrl
};
}
}
}