This commit is contained in:
Tizian.Breuch
2025-09-08 11:24:10 +02:00
parent 471f4a2e7a
commit 5b84ccc575
15 changed files with 352 additions and 63 deletions

View File

@@ -33,6 +33,7 @@ namespace Webshop.Infrastructure.Data
public DbSet<ShopInfo> ShopInfos { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

View File

@@ -1,11 +1,12 @@
// Auto-generiert von CreateWebshopFiles.ps1
// src/Webshop.Infrastructure/Repositories/ReviewRepository.cs
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Infrastructure.Repositories
{
@@ -18,12 +19,49 @@ namespace Webshop.Infrastructure.Repositories
_context = context;
}
// Fügen Sie hier Repository-Methoden hinzu
// Beispiel:
// public async Task<IEnumerable<T>> GetAllAsync() { return await _context.Set<T>().ToListAsync(); }
// public async Task<T?> GetByIdAsync(Guid id) { return await _context.Set<T>().FindAsync(id); }
// public async Task AddAsync(T entity) { _context.Set<T>().Add(entity); await _context.SaveChangesAsync(); }
// public async Task UpdateAsync(T entity) { _context.Set<T>().Update(entity); await _context.SaveChangesAsync(); }
// public async Task DeleteAsync(Guid id) { var entity = await _context.Set<T>().FindAsync(id); if (entity != null) { _context.Set<T>().Remove(entity); await _context.SaveChangesAsync(); } }
public async Task<IEnumerable<Review>> GetAllAsync()
{
return await _context.Reviews
.Include(r => r.Customer)
.Include(r => r.Product)
.OrderByDescending(r => r.ReviewDate)
.ToListAsync();
}
public async Task<IEnumerable<Review>> GetApprovedByProductIdAsync(Guid productId)
{
return await _context.Reviews
.Include(r => r.Customer)
.Where(r => r.ProductId == productId && r.IsApproved)
.OrderByDescending(r => r.ReviewDate)
.ToListAsync();
}
public async Task<Review?> GetByIdAsync(Guid id)
{
return await _context.Reviews.FindAsync(id);
}
public async Task AddAsync(Review review)
{
await _context.Reviews.AddAsync(review);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(Review review)
{
_context.Reviews.Update(review);
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(Guid id)
{
var review = await _context.Reviews.FindAsync(id);
if (review != null)
{
_context.Reviews.Remove(review);
await _context.SaveChangesAsync();
}
}
}
}
}