aufrüumen

This commit is contained in:
Tizian.Breuch
2025-07-25 15:46:31 +02:00
parent 8218b860ca
commit 9e298a0458
74 changed files with 453 additions and 3557 deletions

View File

@@ -9,19 +9,10 @@ namespace Webshop.Application.DTOs.Auth
{
public class RegisterRequestDto
{
[Required(ErrorMessage = "E-Mail ist erforderlich.")]
[EmailAddress(ErrorMessage = "Ungültiges E-Mail-Format.")]
public string Email { get; set; } = string.Empty;
[Required(ErrorMessage = "Passwort ist erforderlich.")]
[MinLength(6, ErrorMessage = "Passwort muss mindestens 6 Zeichen lang sein.")]
public string Password { get; set; } = string.Empty;
[Required(ErrorMessage = "Passwortbestätigung ist erforderlich.")]
[Compare("Password", ErrorMessage = "Passwörter stimmen nicht überein.")]
public string ConfirmPassword { get; set; } = string.Empty;
public string? FirstName { get; set; }
public string? LastName { get; set; }
[Required][EmailAddress] public string Email { get; set; } = string.Empty;
[Required][MinLength(6)] public string Password { get; set; } = string.Empty;
[Required][Compare("Password")] public string ConfirmPassword { get; set; } = string.Empty;
[Required] public string FirstName { get; set; } = string.Empty;
[Required] public string LastName { get; set; } = string.Empty;
}
}

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Categorys
{
public class CategoryDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Categorys
{
public class CreateCategoryDto
{

View File

@@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Customers
{
public class AddressDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Customers
{
public class CustomerDto
{

View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace Webshop.Application.DTOs.Customers
{
public class UpdateCustomerProfileDto
{
[Required]
[MaxLength(100)]
public string FirstName { get; set; } = string.Empty;
[Required]
[MaxLength(100)]
public string LastName { get; set; } = string.Empty;
// PhoneNumber könnte auch hier sein, falls der User das ändern darf
// public string? PhoneNumber { get; set; }
}
}

View File

@@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Discounts
{
public class DiscountDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Orders
{
public class CreateOrderDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Orders
{
public class CreateOrderItemDto
{

View File

@@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Orders
{
public class OrderDetailDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Orders
{
public class OrderItemDto
{

View File

@@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Orders
{
public class OrderSummaryDto
{

View File

@@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Payments
{
public class PaymentMethodDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Products
{
public class AdminProductDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Products
{
public class ProductDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Products
{
public class ProductVariantDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Reviews
{
public class CreateReviewDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Reviews
{
public class ReviewDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Shipping
{
public class ShippingMethodDto
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.DTOs
namespace Webshop.Application.DTOs.Suppliers
{
public class SupplierDto
{

View File

@@ -1,9 +1,4 @@
// Auto-generiert von CreateWebshopFiles.ps1
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
// src/Webshop.Application/DTOs/Users/UserDto.cs
namespace Webshop.Application.DTOs.Users
{
public class UserDto
@@ -14,5 +9,10 @@ namespace Webshop.Application.DTOs.Users
public List<string> Roles { get; set; } = new List<string>();
public DateTimeOffset CreatedDate { get; set; }
public bool EmailConfirmed { get; set; }
// Hinzugef<65>gte Felder
public DateTimeOffset? LastActive { get; set; }
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
}
}
}

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Admin.Interfaces;
namespace Webshop.Application.Services.Admin

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Admin.Interfaces;
namespace Webshop.Application.Services.Admin

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Admin.Interfaces;
namespace Webshop.Application.Services.Admin

View File

@@ -1,11 +1,12 @@
// src/Webshop.Application/Services/Admin/AdminProductService.cs
using Webshop.Application.DTOs; // AdminProductDto
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using System.Collections.Generic;
using System.Threading.Tasks;
using System; // F<>r Guid
using System.Linq; // F<>r Select
using System.Linq;
using Webshop.Application.DTOs.Products;
using Webshop.Application.Services.Admin.Interfaces; // F<>r Select
namespace Webshop.Application.Services.Admin
{

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Admin.Interfaces;
namespace Webshop.Application.Services.Admin

View File

@@ -1,11 +1,12 @@
// src/Webshop.Application/Services/Admin/AdminSupplierService.cs
using Webshop.Application.DTOs;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces; // Wichtig für ISupplierRepository
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Suppliers;
using Webshop.Application.Services.Admin.Interfaces;
namespace Webshop.Application.Services.Admin
{

View File

@@ -5,27 +5,34 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Users;
using Webshop.Domain.Entities; // Wichtiges using für ApplicationUser
using Webshop.Application.Services.Admin.Interfaces;
using Webshop.Domain.Entities;
using Webshop.Infrastructure.Data; // WICHTIG: Stellt sicher, dass ApplicationDbContext gefunden wird.
namespace Webshop.Application.Services.Admin
{
// --- SCHRITT 1: Die fehlende Klassendeklaration ---
public class AdminUserService : IAdminUserService
{
// Wir verwenden nun den UserManager mit unserer neuen ApplicationUser-Klasse
// --- SCHRITT 2: Die fehlenden Feld-Deklarationen ---
private readonly UserManager<ApplicationUser> _userManager;
private readonly ApplicationDbContext _context;
public AdminUserService(UserManager<ApplicationUser> userManager)
// --- SCHRITT 3: Der Konstruktor, der die Felder zuweist ---
public AdminUserService(UserManager<ApplicationUser> userManager, ApplicationDbContext context)
{
_userManager = userManager;
_context = context;
}
// --- AB HIER: Alle Ihre Methoden, unverändert ---
public async Task<IEnumerable<UserDto>> GetAllUsersAsync()
{
// Alle Benutzer aus der Datenbank laden
var users = await _userManager.Users.ToListAsync();
var userDtos = new List<UserDto>();
var users = await _userManager.Users
.Include(u => u.Customer)
.ToListAsync();
// Für jeden Benutzer ein DTO erstellen und die Daten mappen
var userDtos = new List<UserDto>();
foreach (var user in users)
{
userDtos.Add(new UserDto
@@ -33,24 +40,28 @@ namespace Webshop.Application.Services.Admin
Id = user.Id,
Email = user.Email ?? string.Empty,
UserName = user.UserName ?? string.Empty,
CreatedDate = user.CreatedDate, // Dieses Feld ist jetzt verfügbar!
CreatedDate = user.CreatedDate,
EmailConfirmed = user.EmailConfirmed,
Roles = (await _userManager.GetRolesAsync(user)).ToList() // Rollen des Benutzers abrufen
Roles = (await _userManager.GetRolesAsync(user)).ToList(),
LastActive = user.LastActive,
FirstName = user.Customer?.FirstName ?? string.Empty,
LastName = user.Customer?.LastName ?? string.Empty
});
}
return userDtos;
}
public async Task<UserDto?> GetUserByIdAsync(string userId)
{
var user = await _userManager.FindByIdAsync(userId);
var user = await _userManager.Users
.Include(u => u.Customer)
.FirstOrDefaultAsync(u => u.Id == userId);
if (user == null)
{
return null;
}
// Den gefundenen Benutzer in ein DTO umwandeln
return new UserDto
{
Id = user.Id,
@@ -58,8 +69,60 @@ namespace Webshop.Application.Services.Admin
UserName = user.UserName ?? string.Empty,
CreatedDate = user.CreatedDate,
EmailConfirmed = user.EmailConfirmed,
Roles = (await _userManager.GetRolesAsync(user)).ToList()
Roles = (await _userManager.GetRolesAsync(user)).ToList(),
LastActive = user.LastActive,
FirstName = user.Customer?.FirstName ?? string.Empty,
LastName = user.Customer?.LastName ?? string.Empty
};
}
}
}
public async Task<bool> UpdateUserRolesAsync(string userId, List<string> newRoles)
{
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return false;
}
var existingRoles = await _userManager.GetRolesAsync(user);
var removeResult = await _userManager.RemoveFromRolesAsync(user, existingRoles);
if (!removeResult.Succeeded)
{
return false;
}
var addResult = await _userManager.AddToRolesAsync(user, newRoles);
return addResult.Succeeded;
}
public async Task<bool> DeleteUserAsync(string userId)
{
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return false;
}
// Kaskadierendes Löschen der abhängigen Daten
var customer = await _context.Customers
.Include(c => c.Orders)
.Include(c => c.Reviews)
.Include(c => c.Addresses)
.FirstOrDefaultAsync(c => c.AspNetUserId == userId);
if (customer != null)
{
_context.Reviews.RemoveRange(customer.Reviews);
_context.Orders.RemoveRange(customer.Orders);
_context.Addresses.RemoveRange(customer.Addresses);
_context.Customers.Remove(customer);
await _context.SaveChangesAsync();
}
// Zum Schluss den Identity-Benutzer löschen
var result = await _userManager.DeleteAsync(user);
return result.Succeeded;
}
} // <-- Schließende Klammer für die Klasse
} // <-- Schließende Klammer für den Namespace

View File

@@ -1,15 +0,0 @@
// src/Webshop.Application/Services/Admin/IAdminUserService.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Users; // UserDto
namespace Webshop.Application.Services.Admin
{
public interface IAdminUserService
{
Task<IEnumerable<UserDto>> GetAllUsersAsync();
Task<UserDto?> GetUserByIdAsync(string userId);
// Task<bool> UpdateUserRolesAsync(string userId, List<string> newRoles); // Beispiel für zukünftige Methode
// Task<bool> DeleteUserAsync(string userId); // Beispiel für zukünftige Methode
}
}

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Admin
namespace Webshop.Application.Services.Admin.Interfaces
{
public interface IAdminCategoryService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Admin
namespace Webshop.Application.Services.Admin.Interfaces
{
public interface IAdminDiscountService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Admin
namespace Webshop.Application.Services.Admin.Interfaces
{
public interface IAdminOrderService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -1,9 +1,9 @@
// src/Webshop.Application/Services/Admin/IAdminProductService.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs; // AdminProductDto
using Webshop.Application.DTOs.Products;
namespace Webshop.Application.Services.Admin
namespace Webshop.Application.Services.Admin.Interfaces
{
public interface IAdminProductService
{

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Admin
namespace Webshop.Application.Services.Admin.Interfaces
{
public interface IAdminSettingService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -3,9 +3,9 @@
using System; // Für Guid
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs; // Für SupplierDto
using Webshop.Application.DTOs.Suppliers;
namespace Webshop.Application.Services.Admin
namespace Webshop.Application.Services.Admin.Interfaces
{
public interface IAdminSupplierService
{

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Admin.Interfaces
{
/// <summary>
/// Definiert den Vertrag für den Dienst zur Verwaltung von Benutzern durch einen Admin.
/// </summary>
public interface IAdminUserService
{
/// <summary>
/// Ruft eine Liste aller Benutzer mit ihren zugehörigen Daten ab.
/// </summary>
Task<IEnumerable<UserDto>> GetAllUsersAsync();
/// <summary>
/// Ruft einen einzelnen Benutzer anhand seiner ID ab.
/// </summary>
Task<UserDto?> GetUserByIdAsync(string userId);
/// <summary>
/// Aktualisiert die Rollen eines bestimmten Benutzers.
/// </summary>
Task<bool> UpdateUserRolesAsync(string userId, List<string> newRoles);
/// <summary>
/// Löscht einen Benutzer und alle seine abhängigen Daten (Kundenprofil, Bestellungen etc.).
/// </summary>
Task<bool> DeleteUserAsync(string userId);
}
}

View File

@@ -1,36 +1,36 @@
// src/Webshop.Application/Services/Auth/AuthService.cs
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Webshop.Application.DTOs.Auth;
using System.Threading.Tasks;
using System.Collections.Generic;
using Webshop.Domain.Entities; // <-- WICHTIG: Das Using für Ihre neue Klasse hinzufügen
using Webshop.Domain.Entities;
using Webshop.Infrastructure.Data;
namespace Webshop.Application.Services.Auth
{
public class AuthService : IAuthService
{
// Ändern Sie hier IdentityUser zu ApplicationUser
private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly IConfiguration _configuration;
private readonly RoleManager<IdentityRole> _roleManager;
private readonly ApplicationDbContext _context;
public AuthService(
// Ändern Sie auch hier die Typen im Konstruktor
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager,
IConfiguration configuration,
RoleManager<IdentityRole> roleManager)
RoleManager<IdentityRole> roleManager,
ApplicationDbContext context)
{
_userManager = userManager;
_signInManager = signInManager;
_configuration = configuration;
_roleManager = roleManager;
_context = context;
}
public async Task<AuthResponseDto> RegisterUserAsync(RegisterRequestDto request)
@@ -41,12 +41,11 @@ namespace Webshop.Application.Services.Auth
return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = "E-Mail ist bereits registriert." };
}
// Erstellen Sie hier eine Instanz Ihrer neuen ApplicationUser-Klasse
var user = new ApplicationUser
{
Email = request.Email,
UserName = request.Email,
CreatedDate = DateTimeOffset.UtcNow // Setzen Sie das neue Feld!
CreatedDate = DateTimeOffset.UtcNow
};
var result = await _userManager.CreateAsync(user, request.Password);
@@ -56,7 +55,17 @@ namespace Webshop.Application.Services.Auth
return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = errors };
}
// Der Rest der Logik bleibt gleich, da die Rollenverwaltung nicht vom User-Typ abhängt
// Zugehöriges kaufmännisches Kundenprofil erstellen
var customer = new Customer
{
AspNetUserId = user.Id,
FirstName = request.FirstName,
LastName = request.LastName
};
_context.Customers.Add(customer);
await _context.SaveChangesAsync();
// Dem Benutzer die "Customer"-Rolle zuweisen
if (!await _roleManager.RoleExistsAsync("Customer"))
{
await _roleManager.CreateAsync(new IdentityRole("Customer"));
@@ -78,7 +87,6 @@ namespace Webshop.Application.Services.Auth
public async Task<AuthResponseDto> LoginUserAsync(LoginRequestDto request)
{
// Diese Methode funktioniert ohne Änderungen, da der _userManager jetzt vom richtigen Typ ist.
var user = await _userManager.FindByEmailAsync(request.Email);
if (user == null)
{
@@ -91,6 +99,10 @@ namespace Webshop.Application.Services.Auth
return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = "Ungültige Anmeldeinformationen." };
}
// Zeitstempel für "Zuletzt aktiv" aktualisieren
user.LastActive = DateTimeOffset.UtcNow;
await _userManager.UpdateAsync(user);
var roles = await _userManager.GetRolesAsync(user);
var token = await GenerateJwtToken(user, roles);
@@ -106,7 +118,6 @@ namespace Webshop.Application.Services.Auth
public async Task<AuthResponseDto> LoginAdminAsync(LoginRequestDto request)
{
// Diese Methode profitiert direkt von der Korrektur in LoginUserAsync.
var authResponse = await LoginUserAsync(request);
if (!authResponse.IsAuthSuccessful)
{
@@ -114,7 +125,6 @@ namespace Webshop.Application.Services.Auth
}
var user = await _userManager.FindByEmailAsync(request.Email);
// Stellt sicher, dass der User gefunden wurde und die Rolle "Admin" hat.
if (user == null || !await _userManager.IsInRoleAsync(user, "Admin"))
{
return new AuthResponseDto { IsAuthSuccessful = false, ErrorMessage = "Keine Berechtigung." };
@@ -123,7 +133,6 @@ namespace Webshop.Application.Services.Auth
return authResponse;
}
// Ändern Sie hier den Parameter-Typ zu ApplicationUser
private async Task<string> GenerateJwtToken(ApplicationUser user, IList<string> roles)
{
var claims = new List<Claim>

View File

@@ -1,14 +1,26 @@
// src/Webshop.Application/Services/Auth/IAuthService.cs
using System.Threading.Tasks;
using Webshop.Application.DTOs.Auth;
using System.Threading.Tasks; // Sicherstellen, dass für Task vorhanden
using System.Collections.Generic; // Sicherstellen, dass für IList<string> vorhanden
namespace Webshop.Application.Services.Auth
{
/// <summary>
/// Definiert den Vertrag für den Authentifizierungsdienst.
/// </summary>
public interface IAuthService
{
/// <summary>
/// Registriert einen neuen Benutzer und erstellt ein zugehöriges Kundenprofil.
/// </summary>
Task<AuthResponseDto> RegisterUserAsync(RegisterRequestDto request);
/// <summary>
/// Meldet einen Benutzer an und gibt einen JWT zurück.
/// </summary>
Task<AuthResponseDto> LoginUserAsync(LoginRequestDto request);
/// <summary>
/// Meldet einen Benutzer an und überprüft, ob er die Admin-Rolle hat.
/// </summary>
Task<AuthResponseDto> LoginAdminAsync(LoginRequestDto request);
}
}

View File

@@ -1,17 +0,0 @@
// Auto-generiert von CreateWebshopFiles.ps1
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Application.Services.Customer
{
public class CustomerService : ICustomerService
{
// Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories)
// public CustomerService(IYourRepository repository) { }
// Fügen Sie hier Service-Methoden hinzu
}
}

View File

@@ -1,16 +0,0 @@
// Auto-generiert von CreateWebshopFiles.ps1
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs;
using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Customer
{
public interface ICustomerService
{
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -2,9 +2,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Customers.Interfaces;
namespace Webshop.Application.Services.Customer
namespace Webshop.Application.Services.Customers
{
public class CheckoutService : ICheckoutService
{

View File

@@ -0,0 +1,52 @@
using System.Threading.Tasks;
using Webshop.Application.DTOs.Customers;
using Webshop.Application.Services.Customers.Interfaces;
using Webshop.Domain.Interfaces; // Wichtig für ICustomerRepository
namespace Webshop.Application.Services.Customers
{
public class CustomerService : ICustomerService
{
private readonly ICustomerRepository _customerRepository;
public CustomerService(ICustomerRepository customerRepository)
{
_customerRepository = customerRepository;
}
public async Task<CustomerDto?> GetMyProfileAsync(string userId)
{
var customer = await _customerRepository.GetByUserIdAsync(userId);
if (customer == null)
{
return null;
}
// Mappe die Entity auf das CustomerDto
return new CustomerDto
{
Id = customer.Id,
UserId = customer.AspNetUserId,
FirstName = customer.FirstName,
LastName = customer.LastName,
// Fügen Sie hier weitere Felder hinzu, die der Kunde sehen soll (Email, Phone etc.)
};
}
public async Task<bool> UpdateMyProfileAsync(string userId, UpdateCustomerProfileDto profileDto)
{
var customer = await _customerRepository.GetByUserIdAsync(userId);
if (customer == null)
{
return false; // Kunde nicht gefunden
}
// Aktualisiere die Felder
customer.FirstName = profileDto.FirstName;
customer.LastName = profileDto.LastName;
await _customerRepository.UpdateAsync(customer);
return true;
}
}
}

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Customer
namespace Webshop.Application.Services.Customers.Interfaces
{
public interface ICheckoutService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Webshop.Application.DTOs.Customers; // Korrektes Using für DTOs
namespace Webshop.Application.Services.Customers.Interfaces
{
public interface ICustomerService
{
Task<CustomerDto?> GetMyProfileAsync(string userId);
Task<bool> UpdateMyProfileAsync(string userId, UpdateCustomerProfileDto profileDto);
}
}

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Customer
namespace Webshop.Application.Services.Customers.Interfaces
{
public interface IOrderService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Customer
namespace Webshop.Application.Services.Customers.Interfaces
{
public interface IReviewService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -2,9 +2,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Customers.Interfaces;
namespace Webshop.Application.Services.Customer
namespace Webshop.Application.Services.Customers
{
public class OrderService : IOrderService
{

View File

@@ -2,9 +2,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Customers.Interfaces;
namespace Webshop.Application.Services.Customer
namespace Webshop.Application.Services.Customers
{
public class ReviewService : IReviewService
{

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.Services.Public.Interfaces;
namespace Webshop.Application.Services.Public

View File

@@ -7,10 +7,10 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Users;
namespace Webshop.Application.Services.Public
namespace Webshop.Application.Services.Public.Interfaces
{
public interface ICategoryService
{
// Fügen Sie hier Methodensignaturen hinzu
// Fügen Sie hier Methodensignaturen hinzu
}
}

View File

@@ -1,9 +1,9 @@
// src/Webshop.Application/Services/Public/IProductService.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs; // ProductDto
using Webshop.Application.DTOs.Products;
namespace Webshop.Application.Services.Public
namespace Webshop.Application.Services.Public.Interfaces
{
public interface IProductService
{

View File

@@ -2,9 +2,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs;
using Webshop.Domain.Interfaces;
using Webshop.Domain.Entities;
using Webshop.Application.DTOs.Products;
using Webshop.Application.Services.Public.Interfaces;
namespace Webshop.Application.Services.Public

View File

@@ -1,32 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.13.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.13.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.18" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.18" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.0.18" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.18" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Webshop.Domain\Webshop.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\Customer\" />
</ItemGroup>
</Project>
<ProjectReference Include="..\Webshop.Domain\Webshop.Domain.csproj" />
<ProjectReference Include="..\Webshop.Infrastructure\Webshop.Infrastructure.csproj" />
</ItemGroup>
</Project>