supplier und migration

This commit is contained in:
Tizian.Breuch
2025-07-23 12:33:01 +02:00
parent c3292d6739
commit 1fe88fac3a
8 changed files with 195 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
// src/Webshop.Application/DTOs/SupplierDto.cs
namespace Webshop.Application.DTOs
{
public class SupplierDto
{
public Guid Id { get; set; } = Guid.NewGuid(); // Für PUT/GET, bei POST optional
public string Name { get; set; } = string.Empty;
public string? ContactPerson { get; set; }
public string? Email { get; set; }
public string? PhoneNumber { get; set; }
public Guid? AddressId { get; set; } // Wenn Sie Adressen haben, sonst null
public string? Notes { get; set; }
}
}

View File

@@ -0,0 +1,68 @@
// src/Webshop.Application/Services/Admin/AdminSupplierService.cs
using Webshop.Application.DTOs; // SupplierDto
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using System.Collections.Generic; // Für IEnumerable
namespace Webshop.Application.Services.Admin
{
public class AdminSupplierService
{
private readonly ISupplierRepository _supplierRepository;
public AdminSupplierService(ISupplierRepository supplierRepository)
{
_supplierRepository = supplierRepository;
}
public async Task<IEnumerable<SupplierDto>> GetAllSuppliersAsync()
{
var suppliers = await _supplierRepository.GetAllSuppliersAsync();
return suppliers.Select(s => new SupplierDto
{
Id = s.Id,
Name = s.Name,
ContactPerson = s.ContactPerson,
Email = s.Email,
PhoneNumber = s.PhoneNumber,
AddressId = s.AddressId,
Notes = s.Notes
}).ToList();
}
public async Task<SupplierDto?> GetSupplierByIdAsync(Guid id)
{
var supplier = await _supplierRepository.GetSupplierByIdAsync(id);
if (supplier == null) return null;
return new SupplierDto
{
Id = supplier.Id,
Name = supplier.Name,
ContactPerson = supplier.ContactPerson,
Email = supplier.Email,
PhoneNumber = supplier.PhoneNumber,
AddressId = supplier.AddressId,
Notes = supplier.Notes
};
}
public async Task<SupplierDto> CreateSupplierAsync(SupplierDto supplierDto)
{
var newSupplier = new Supplier
{
Id = Guid.NewGuid(), // API generiert die ID
Name = supplierDto.Name,
ContactPerson = supplierDto.ContactPerson,
Email = supplierDto.Email,
PhoneNumber = supplierDto.PhoneNumber,
AddressId = supplierDto.AddressId,
Notes = supplierDto.Notes
};
await _supplierRepository.AddSupplierAsync(newSupplier);
supplierDto.Id = newSupplier.Id; // ID zurückschreiben
return supplierDto;
}
// TODO: UpdateSupplierAsync, DeleteSupplierAsync
}
}