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

Location:
ChapterX.Infrastructure/Repositories
Files:
6 edited

Legend:

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

    racf690c r73b69b2  
    1919
    2020        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)
    2428                .ToListAsync(cancellationToken);
    25         }
    2629    }
    2730}
  • 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}
  • ChapterX.Infrastructure/Repositories/NotificationRepository.cs

    racf690c r73b69b2  
    1515        // This method returns all notifications; adjust filter when a User relation is added.
    1616        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);
    2021    }
    2122}
  • ChapterX.Infrastructure/Repositories/ReadingListItemsRepository.cs

    racf690c r73b69b2  
    1414        public async Task<bool> ExistsAsync(int listId, int storyId, CancellationToken cancellationToken = default)
    1515            => 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        }
    1625    }
    1726}
  • ChapterX.Infrastructure/Repositories/ReadingListRepository.cs

    racf690c r73b69b2  
    1515        {
    1616            return await _dbSet
     17                .Include(r => r.User)
    1718                .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)
    1826                .ToListAsync(cancellationToken);
    1927        }
     
    2331            return await _dbSet
    2432                .Where(r => r.UserId == userId)
     33                .Include(r => r.User)
    2534                .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)
    2642                .ToListAsync(cancellationToken);
    2743        }
  • ChapterX.Infrastructure/Repositories/StoryRepository.cs

    racf690c r73b69b2  
    1212        }
    1313
     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
    1424        public async Task<IEnumerable<Story>> GetByWriterIdAsync(int writerId, CancellationToken cancellationToken = default)
    1525        {
Note: See TracChangeset for help on using the changeset viewer.