Compare commits

..

3 Commits

Author SHA1 Message Date
Tizian.Breuch
c4d4a27798 Merge branch 'test' of https://gitea.tzbre.dev/admin/ShopSolution-backend into test
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 28s
2025-11-26 17:17:00 +01:00
Tizian.Breuch
3a2ea2c307 migration 2025-11-26 17:16:47 +01:00
Tizian.Breuch
5510ffa836 pfad 2025-11-26 17:09:41 +01:00
7 changed files with 85 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ using Webshop.Application.DTOs.Auth;
using Webshop.Application.DTOs.Customers;
using Webshop.Application.DTOs.Email;
using Webshop.Application.Services.Customers;
using Webshop.Application.Services.Customers.Interfaces;
namespace Webshop.Api.Controllers.Customer
{

View File

@@ -27,6 +27,7 @@ using Webshop.Infrastructure.Data;
using Webshop.Infrastructure.Repositories;
using Webshop.Infrastructure.Services;
var options = new WebApplicationOptions
{
Args = args,

View File

@@ -16,7 +16,19 @@
"ExpirationMinutes": 120
},
"Resend": {
"ApiToken": "re_Zd6aFcvz_CqSa9Krs7WCHXjngDVLTYhGv"
"ApiToken": "re_Zd6aFcvz_CqSa9Krs7WCHXjngDVLTYhGv",
"FromEmail": "onboarding@resend.dev"
},
"App:BaseUrl": "https://shopsolution-backend.tzbre.dev"
"App": {
"BaseUrl": "https://shopsolution-backend.tzbre.dev",
"ClientUrl": "https://shopsolution-frontend.tzbre.dev",
"FrontendUrl": "https://shopsolution-frontend.tzbre.dev"
},
"ShopInfo": {
"Name": "Mein Webshop"
},
"EmailSettings": {
"SenderName": "Mein Webshop Support",
"SenderEmail": "noreply@shopsolution-frontend.tzbre.dev"
}
}

View File

@@ -103,7 +103,7 @@ namespace Webshop.Application.Services.Public
private async Task<string> LoadAndFormatTemplate(string title, string body, string btnText, string btnLink)
{
// Pfad: wwwroot/templates/email-template.html
var templatePath = Path.Combine(_env.WebRootPath ?? _env.ContentRootPath, "templates", "email-template.html");
var templatePath = Path.Combine(AppContext.BaseDirectory, "Templates", "_EmailTemplate.html");
string template;

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Webshop.Domain.Entities
{
public class Cart
{
[Key]
public Guid Id { get; set; }
// Verknüpfung zum User (String, da Identity User Id ein String ist)
public string? UserId { get; set; }
// Falls du auch Gast-Warenkörbe ohne Login unterstützt:
public string? SessionId { get; set; }
public DateTime LastModified { get; set; } = DateTime.UtcNow;
public virtual ICollection<CartItem> Items { get; set; } = new List<CartItem>();
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Webshop.Domain.Entities
{
public class CartItem
{
[Key]
public Guid Id { get; set; }
public Guid CartId { get; set; }
[ForeignKey("CartId")]
public virtual Cart Cart { get; set; } = default!;
public Guid ProductId { get; set; }
[ForeignKey("ProductId")]
public virtual Product Product { get; set; } = default!;
public Guid? ProductVariantId { get; set; } // Optional, falls du Varianten nutzt
public int Quantity { get; set; }
}
}

View File

@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Webshop.Domain.Entities;
using Webshop.Domain.Identity;
@@ -26,12 +25,16 @@ namespace Webshop.Infrastructure.Data
public DbSet<PaymentMethod> PaymentMethods { get; set; } = default!;
public DbSet<Setting> Settings { get; set; } = default!;
// Verknüpfungstabellen und Details
public DbSet<Productcategorie> Productcategories { get; set; } = default!;
public DbSet<ProductDiscount> ProductDiscounts { get; set; } = default!;
public DbSet<CategorieDiscount> categorieDiscounts { get; set; } = default!;
public DbSet<ProductImage> ProductImages { get; set; } = default!;
public DbSet<ShopInfo> ShopInfos { get; set; } = default!;
// +++ NEU: Warenkorb Tabellen +++
public DbSet<Cart> Carts { get; set; } = default!;
public DbSet<CartItem> CartItems { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
@@ -48,6 +51,17 @@ namespace Webshop.Infrastructure.Data
}
}
// +++ NEU: Warenkorb Konfiguration +++
modelBuilder.Entity<Cart>(entity =>
{
// Wenn ein Warenkorb gelöscht wird, lösche alle Items darin automatisch
entity.HasMany(c => c.Items)
.WithOne(i => i.Cart)
.HasForeignKey(i => i.CartId)
.OnDelete(DeleteBehavior.Cascade);
});
// Bestehende Konfigurationen (bleiben unverändert)
modelBuilder.Entity<Productcategorie>().HasKey(pc => new { pc.ProductId, pc.categorieId });
modelBuilder.Entity<ProductDiscount>().HasKey(pd => new { pd.ProductId, pd.DiscountId });
modelBuilder.Entity<CategorieDiscount>().HasKey(cd => new { cd.categorieId, cd.DiscountId });
@@ -143,8 +157,8 @@ namespace Webshop.Infrastructure.Data
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<ApplicationUser>()
.HasOne(a => a.Customer) // Ein ApplicationUser hat ein optionales Customer-Profil
.WithOne(c => c.User) // Ein Customer-Profil ist mit genau einem User verknüpft
.HasOne(a => a.Customer)
.WithOne(c => c.User)
.HasForeignKey<Customer>(c => c.AspNetUserId);
modelBuilder.Entity<ProductDiscount>(entity =>
@@ -158,8 +172,6 @@ namespace Webshop.Infrastructure.Data
.HasForeignKey(pd => pd.DiscountId);
});
// << NEU: Beziehungskonfiguration für CategorieDiscount >>
modelBuilder.Entity<CategorieDiscount>(entity =>
{
entity.HasOne(cd => cd.categorie)
@@ -173,20 +185,16 @@ namespace Webshop.Infrastructure.Data
modelBuilder.Entity<Review>(entity =>
{
// Beziehung zu Product
entity.HasOne(r => r.Product)
.WithMany(p => p.Reviews)
.HasForeignKey(r => r.ProductId)
.OnDelete(DeleteBehavior.Cascade); // Lösche Bewertungen, wenn das Produkt gelöscht wird
.OnDelete(DeleteBehavior.Cascade);
// Beziehung zu Customer
entity.HasOne(r => r.Customer)
.WithMany(c => c.Reviews)
.HasForeignKey(r => r.CustomerId)
.OnDelete(DeleteBehavior.SetNull); // Setze CustomerId auf NULL, wenn der Kunde gelöscht wird
.OnDelete(DeleteBehavior.SetNull);
});
}
}
}