using System.Security.Claims; using FictionArchive.Service.UserNovelDataService.Models.DTOs; using FictionArchive.Service.UserNovelDataService.Services; using HotChocolate.Authorization; using Microsoft.EntityFrameworkCore; namespace FictionArchive.Service.UserNovelDataService.GraphQL; public class Query { [Authorize] public async Task> GetBookmarks( UserNovelDataServiceDbContext dbContext, ClaimsPrincipal claimsPrincipal, uint novelId) { var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrEmpty(oAuthProviderId)) { return new List().AsQueryable(); } var user = await dbContext.Users .AsNoTracking() .FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId); if (user == null) { return new List().AsQueryable(); } return dbContext.Bookmarks .AsNoTracking() .Where(b => b.UserId == user.Id && b.NovelId == novelId) .OrderByDescending(b => b.CreatedTime) .Select(b => new BookmarkDto { Id = b.Id, ChapterId = b.ChapterId, NovelId = b.NovelId, Description = b.Description, CreatedTime = b.CreatedTime }); } }