Checkpoint - changing PCs

This commit contains broken code
This commit is contained in:
Amelia 2025-05-17 15:27:18 +02:00
parent 06914d1135
commit 616916548a
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
5 changed files with 128 additions and 45 deletions

View file

@ -3,9 +3,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using API.DTOs;
using API.Entities;
using API.Extensions.QueryExtensions;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
namespace API.Data.Repositories;
@ -22,8 +24,11 @@ public interface IAppUserReadingProfileRepository
{
Task<IList<AppUserReadingProfile>> GetProfilesForUser(int userId);
Task<AppUserReadingProfile?> GetProfileForSeries(int userId, int seriesId);
Task<UserReadingProfileDto?> GetProfileDtoForSeries(int userId, int seriesId);
Task<AppUserReadingProfile?> GetProfileForLibrary(int userId, int libraryId);
Task<UserReadingProfileDto?> GetProfileDtoForLibrary(int userId, int libraryId);
Task<AppUserReadingProfile?> GetProfile(int profileId, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
Task<UserReadingProfileDto?> GetProfileDto(int profileId);
void Add(AppUserReadingProfile readingProfile);
void Update(AppUserReadingProfile readingProfile);
@ -47,6 +52,14 @@ public class AppUserReadingProfileRepository(DataContext context, IMapper mapper
.FirstOrDefaultAsync();
}
public async Task<UserReadingProfileDto?> GetProfileDtoForSeries(int userId, int seriesId)
{
return await context.AppUserReadingProfile
.Where(rp => rp.UserId == userId && rp.Series.Any(s => s.Id == seriesId))
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
.FirstOrDefaultAsync();
}
public async Task<AppUserReadingProfile?> GetProfileForLibrary(int userId, int libraryId)
{
return await context.AppUserReadingProfile
@ -54,6 +67,14 @@ public class AppUserReadingProfileRepository(DataContext context, IMapper mapper
.FirstOrDefaultAsync();
}
public async Task<UserReadingProfileDto?> GetProfileDtoForLibrary(int userId, int libraryId)
{
return await context.AppUserReadingProfile
.Where(rp => rp.UserId == userId && rp.Libraries.Any(s => s.Id == libraryId))
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
.FirstOrDefaultAsync();
}
public async Task<AppUserReadingProfile?> GetProfile(int profileId, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
{
return await context.AppUserReadingProfile
@ -61,6 +82,13 @@ public class AppUserReadingProfileRepository(DataContext context, IMapper mapper
.Includes(includes)
.FirstOrDefaultAsync();
}
public async Task<UserReadingProfileDto?> GetProfileDto(int profileId)
{
return await context.AppUserReadingProfile
.Where(rp => rp.Id == profileId)
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
.FirstOrDefaultAsync();
}
public void Add(AppUserReadingProfile readingProfile)
{