source: ChapterX.Infrastructure/Repositories/ReadingListRepository.cs

main
Last change on this file was 73b69b2, checked in by kikisrbinoska <srbinoskakristina07@…>, 3 months ago

Fixed reading lists,comments and likes

  • Property mode set to 100644
File size: 1.8 KB
Line 
1using ChapterX.Domain.Entities;
2using ChapterX.Domain.Repositories;
3using ChapterX.Infrastructure.Data.DataContext;
4using Microsoft.EntityFrameworkCore;
5
6namespace ChapterX.Infrastructure.Repositories
7{
8 public class ReadingListRepository : GenericRepository<ReadingList>, IReadingListRepository
9 {
10 public ReadingListRepository(ApplicationDbContext context) : base(context)
11 {
12 }
13
14 public override async Task<IEnumerable<ReadingList>> GetAllAsync(CancellationToken cancellationToken = default)
15 {
16 return await _dbSet
17 .Include(r => r.User)
18 .Include(r => r.ReadingListItems)
19 .ThenInclude(i => i.Story)
20 .ThenInclude(s => s.Writer)
21 .ThenInclude(w => w!.User)
22 .Include(r => r.ReadingListItems)
23 .ThenInclude(i => i.Story)
24 .ThenInclude(s => s.HasGenres)
25 .ThenInclude(hg => hg.Genre)
26 .ToListAsync(cancellationToken);
27 }
28
29 public async Task<IEnumerable<ReadingList>> GetByUserIdAsync(int userId, CancellationToken cancellationToken = default)
30 {
31 return await _dbSet
32 .Where(r => r.UserId == userId)
33 .Include(r => r.User)
34 .Include(r => r.ReadingListItems)
35 .ThenInclude(i => i.Story)
36 .ThenInclude(s => s.Writer)
37 .ThenInclude(w => w!.User)
38 .Include(r => r.ReadingListItems)
39 .ThenInclude(i => i.Story)
40 .ThenInclude(s => s.HasGenres)
41 .ThenInclude(hg => hg.Genre)
42 .ToListAsync(cancellationToken);
43 }
44 }
45}
Note: See TracBrowser for help on using the repository browser.