source: ChapterX.Infrastructure/Repositories/StoryRepository.cs@ 0b502c2

main
Last change on this file since 0b502c2 was 0b502c2, checked in by kikisrbinoska <srbinoskakristina07@…>, 12 days ago

Fixed user profile and reading lists

  • Property mode set to 100644
File size: 1.2 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 StoryRepository : GenericRepository<Story>, IStoryRepository
9 {
10 public StoryRepository(ApplicationDbContext context) : base(context)
11 {
12 }
13
14 public override async Task<IEnumerable<Story>> GetAllAsync(CancellationToken cancellationToken = default)
15 {
16 return await _dbSet
17 .Include(s => s.HasGenres)
18 .ThenInclude(hg => hg.Genre)
19 .Include(s => s.Writer)
20 .ThenInclude(w => w!.User)
21 .Include(s => s.Likes)
22 .Include(s => s.Comments)
23 .Include(s => s.Chapters)
24 .ToListAsync(cancellationToken);
25 }
26
27 public async Task<IEnumerable<Story>> GetByWriterIdAsync(int writerId, CancellationToken cancellationToken = default)
28 {
29 return await _dbSet
30 .Include(s => s.Writer)
31 .Where(s => s.Writer != null && s.Writer.Id == writerId)
32 .ToListAsync(cancellationToken);
33 }
34 }
35}
Note: See TracBrowser for help on using the repository browser.