payment
This commit is contained in:
100
Webshop.Application/Services/Admin/AdminPaymentMethodService.cs
Normal file
100
Webshop.Application/Services/Admin/AdminPaymentMethodService.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
// src/Webshop.Application/Services/Admin/AdminPaymentMethodService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq; // Für Select
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Payments; // AdminPaymentMethodDto
|
||||
using Webshop.Domain.Entities; // PaymentMethod
|
||||
using Webshop.Domain.Interfaces; // IPaymentMethodRepository
|
||||
using Webshop.Domain.Enums;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminPaymentMethodService : IAdminPaymentMethodService
|
||||
{
|
||||
private readonly IPaymentMethodRepository _paymentMethodRepository;
|
||||
|
||||
public AdminPaymentMethodService(IPaymentMethodRepository paymentMethodRepository)
|
||||
{
|
||||
_paymentMethodRepository = paymentMethodRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AdminPaymentMethodDto>> GetAllAsync()
|
||||
{
|
||||
var paymentMethods = await _paymentMethodRepository.GetAllAsync();
|
||||
|
||||
return paymentMethods.Select(pm => new AdminPaymentMethodDto
|
||||
{
|
||||
Id = pm.Id,
|
||||
Name = pm.Name,
|
||||
Description = pm.Description,
|
||||
IsActive = pm.IsActive,
|
||||
PaymentGatewayType = pm.PaymentGatewayType,
|
||||
Configuration = pm.Configuration, // Gibt den JSON-String für den Admin zurück
|
||||
ProcessingFee = pm.ProcessingFee
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<AdminPaymentMethodDto?> GetByIdAsync(Guid id)
|
||||
{
|
||||
var paymentMethod = await _paymentMethodRepository.GetByIdAsync(id);
|
||||
if (paymentMethod == null) return null;
|
||||
|
||||
return new AdminPaymentMethodDto
|
||||
{
|
||||
Id = paymentMethod.Id,
|
||||
Name = paymentMethod.Name,
|
||||
Description = paymentMethod.Description,
|
||||
IsActive = paymentMethod.IsActive,
|
||||
PaymentGatewayType = paymentMethod.PaymentGatewayType,
|
||||
Configuration = paymentMethod.Configuration,
|
||||
ProcessingFee = paymentMethod.ProcessingFee
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<AdminPaymentMethodDto> CreateAsync(AdminPaymentMethodDto paymentMethodDto)
|
||||
{
|
||||
var newPaymentMethod = new PaymentMethod
|
||||
{
|
||||
Id = Guid.NewGuid(), // API generiert die ID
|
||||
Name = paymentMethodDto.Name,
|
||||
Description = paymentMethodDto.Description,
|
||||
IsActive = paymentMethodDto.IsActive,
|
||||
PaymentGatewayType = paymentMethodDto.PaymentGatewayType,
|
||||
Configuration = paymentMethodDto.Configuration,
|
||||
ProcessingFee = paymentMethodDto.ProcessingFee
|
||||
};
|
||||
|
||||
await _paymentMethodRepository.AddAsync(newPaymentMethod);
|
||||
|
||||
paymentMethodDto.Id = newPaymentMethod.Id; // ID zurückschreiben
|
||||
return paymentMethodDto;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(AdminPaymentMethodDto paymentMethodDto)
|
||||
{
|
||||
var existingPaymentMethod = await _paymentMethodRepository.GetByIdAsync(paymentMethodDto.Id);
|
||||
if (existingPaymentMethod == null) return false;
|
||||
|
||||
// Eigenschaften aktualisieren
|
||||
existingPaymentMethod.Name = paymentMethodDto.Name;
|
||||
existingPaymentMethod.Description = paymentMethodDto.Description;
|
||||
existingPaymentMethod.IsActive = paymentMethodDto.IsActive;
|
||||
existingPaymentMethod.PaymentGatewayType = paymentMethodDto.PaymentGatewayType;
|
||||
existingPaymentMethod.Configuration = paymentMethodDto.Configuration;
|
||||
existingPaymentMethod.ProcessingFee = paymentMethodDto.ProcessingFee;
|
||||
|
||||
await _paymentMethodRepository.UpdateAsync(existingPaymentMethod);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(Guid id)
|
||||
{
|
||||
var paymentMethod = await _paymentMethodRepository.GetByIdAsync(id);
|
||||
if (paymentMethod == null) return false;
|
||||
|
||||
await _paymentMethodRepository.DeleteAsync(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user