// 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> 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 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 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 } }