- Timestamp:
- 03/24/26 22:13:36 (3 months ago)
- Branches:
- main
- Children:
- 7fbb91c
- Parents:
- acf690c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
