Changeset 73b69b2 for ChapterX.Infrastructure/Repositories
- Timestamp:
- 03/24/26 22:13:36 (3 months ago)
- Branches:
- main
- Children:
- 7fbb91c
- Parents:
- acf690c
- Location:
- ChapterX.Infrastructure/Repositories
- Files:
-
- 6 edited
-
CommentRepository.cs (modified) (1 diff)
-
LikesRepository.cs (modified) (2 diffs)
-
NotificationRepository.cs (modified) (1 diff)
-
ReadingListItemsRepository.cs (modified) (1 diff)
-
ReadingListRepository.cs (modified) (2 diffs)
-
StoryRepository.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ChapterX.Infrastructure/Repositories/CommentRepository.cs
racf690c r73b69b2 19 19 20 20 public async Task<IEnumerable<Comment>> GetByChapterIdAsync(int chapterId, CancellationToken cancellationToken = default) 21 { 22 return await _dbSet 23 .Where(c => c.StoryId == chapterId) 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) 24 28 .ToListAsync(cancellationToken); 25 }26 29 } 27 30 } -
ChapterX.Infrastructure/Repositories/LikesRepository.cs
racf690c r73b69b2 2 2 using ChapterX.Domain.Repositories; 3 3 using ChapterX.Infrastructure.Data.DataContext; 4 using System; 5 using System.Collections.Generic; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 4 using Microsoft.EntityFrameworkCore; 9 5 10 6 namespace ChapterX.Infrastructure.Repositories … … 15 11 { 16 12 } 13 14 public async Task<IEnumerable<Likes>> GetByStoryIdAsync(int storyId, CancellationToken cancellationToken = default) 15 => await _dbSet.Where(l => l.StoryId == storyId).ToListAsync(cancellationToken); 16 17 public async Task<bool> ExistsAsync(int userId, int storyId, CancellationToken cancellationToken = default) 18 => await _dbSet.AnyAsync(l => l.UserId == userId && l.StoryId == storyId, cancellationToken); 19 20 public async Task<bool> DeleteByUserAndStoryAsync(int userId, int storyId, CancellationToken cancellationToken = default) 21 { 22 var like = await _dbSet.FirstOrDefaultAsync(l => l.UserId == userId && l.StoryId == storyId, cancellationToken); 23 if (like == null) return false; 24 _dbSet.Remove(like); 25 await _context.SaveChangesAsync(cancellationToken); 26 return true; 27 } 17 28 } 18 29 } -
ChapterX.Infrastructure/Repositories/NotificationRepository.cs
racf690c r73b69b2 15 15 // This method returns all notifications; adjust filter when a User relation is added. 16 16 public async Task<IEnumerable<Notification>> GetByUserIdAsync(int userId, CancellationToken cancellationToken = default) 17 { 18 return await _dbSet.ToListAsync(cancellationToken); 19 } 17 => await _dbSet 18 .Where(n => n.RecipientUserId == userId) 19 .OrderByDescending(n => n.CreatedAt) 20 .ToListAsync(cancellationToken); 20 21 } 21 22 } -
ChapterX.Infrastructure/Repositories/ReadingListItemsRepository.cs
racf690c r73b69b2 14 14 public async Task<bool> ExistsAsync(int listId, int storyId, CancellationToken cancellationToken = default) 15 15 => await _dbSet.AnyAsync(i => i.ListId == listId && i.StoryId == storyId, cancellationToken); 16 17 public async Task<bool> DeleteByListAndStoryAsync(int listId, int storyId, CancellationToken cancellationToken = default) 18 { 19 var item = await _dbSet.FirstOrDefaultAsync(i => i.ListId == listId && i.StoryId == storyId, cancellationToken); 20 if (item == null) return false; 21 _dbSet.Remove(item); 22 await _context.SaveChangesAsync(cancellationToken); 23 return true; 24 } 16 25 } 17 26 } -
ChapterX.Infrastructure/Repositories/ReadingListRepository.cs
racf690c r73b69b2 15 15 { 16 16 return await _dbSet 17 .Include(r => r.User) 17 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) 18 26 .ToListAsync(cancellationToken); 19 27 } … … 23 31 return await _dbSet 24 32 .Where(r => r.UserId == userId) 33 .Include(r => r.User) 25 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) 26 42 .ToListAsync(cancellationToken); 27 43 } -
ChapterX.Infrastructure/Repositories/StoryRepository.cs
racf690c r73b69b2 12 12 } 13 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 .ToListAsync(cancellationToken); 22 } 23 14 24 public async Task<IEnumerable<Story>> GetByWriterIdAsync(int writerId, CancellationToken cancellationToken = default) 15 25 {
Note:
See TracChangeset
for help on using the changeset viewer.
