// 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; namespace Webshop.Infrastructure.Repositories { public class ReviewRepository : IReviewRepository { private readonly ApplicationDbContext _context; public ReviewRepository(ApplicationDbContext context) { _context = context; } public async Task> GetAllAsync() { return await _context.Reviews .Include(r => r.Customer) .Include(r => r.Product) .OrderByDescending(r => r.ReviewDate) .ToListAsync(); } public async Task> 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 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(); } } } }