Ignore:
Timestamp:
03/24/26 22:13:36 (3 months ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Children:
7fbb91c
Parents:
acf690c
Message:

Fixed reading lists,comments and likes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ChapterX.Infrastructure/Repositories/LikesRepository.cs

    racf690c r73b69b2  
    22using ChapterX.Domain.Repositories;
    33using 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;
     4using Microsoft.EntityFrameworkCore;
    95
    106namespace ChapterX.Infrastructure.Repositories
     
    1511        {
    1612        }
     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        }
    1728    }
    1829}
Note: See TracChangeset for help on using the changeset viewer.