source: ChapterX.Infrastructure/Repositories/CommentRepository.cs@ 3ae4bab

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

Fixed reading lists,comments and likes

  • Property mode set to 100644
File size: 1.1 KB
Line 
1using ChapterX.Domain.Entities;
2using ChapterX.Domain.Repositories;
3using ChapterX.Infrastructure.Data.DataContext;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9
10using Microsoft.EntityFrameworkCore;
11
12namespace ChapterX.Infrastructure.Repositories
13{
14 public class CommentRepository : GenericRepository<Comment>, ICommentRepository
15 {
16 public CommentRepository(ApplicationDbContext context) : base(context)
17 {
18 }
19
20 public async Task<IEnumerable<Comment>> GetByChapterIdAsync(int chapterId, CancellationToken cancellationToken = default)
21 => await _dbSet.Where(c => c.StoryId == chapterId).ToListAsync(cancellationToken);
22
23 public async Task<IEnumerable<Comment>> GetByStoryIdAsync(int storyId, CancellationToken cancellationToken = default)
24 => await _dbSet
25 .Include(c => c.User)
26 .Where(c => c.StoryId == storyId)
27 .OrderByDescending(c => c.CreatedAt)
28 .ToListAsync(cancellationToken);
29 }
30}
Note: See TracBrowser for help on using the repository browser.