source: ChapterX.Infrastructure/Repositories/StoryRepository.cs@ 99c1e45

main
Last change on this file since 99c1e45 was 99c1e45, checked in by kikisrbinoska <srbinoskakristina07@…>, 11 days ago

Fixed writer section and admin management

  • Property mode set to 100644
File size: 1.7 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 override async Task<Story?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
28 {
29 return await _dbSet
30 .Include(s => s.HasGenres)
31 .ThenInclude(hg => hg.Genre)
32 .Include(s => s.Writer)
33 .ThenInclude(w => w!.User)
34 .Include(s => s.Likes)
35 .Include(s => s.Comments)
36 .Include(s => s.Chapters)
37 .FirstOrDefaultAsync(s => s.Id == id, cancellationToken);
38 }
39
40 public async Task<IEnumerable<Story>> GetByWriterIdAsync(int writerId, CancellationToken cancellationToken = default)
41 {
42 return await _dbSet
43 .Include(s => s.Writer)
44 .Where(s => s.Writer != null && s.Writer.Id == writerId)
45 .ToListAsync(cancellationToken);
46 }
47 }
48}
Note: See TracBrowser for help on using the repository browser.