[FA-27] Bookmark implementation
This commit is contained in:
@@ -1,6 +1,45 @@
|
||||
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<IQueryable<BookmarkDto>> GetBookmarks(
|
||||
UserNovelDataServiceDbContext dbContext,
|
||||
ClaimsPrincipal claimsPrincipal,
|
||||
uint novelId)
|
||||
{
|
||||
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||
{
|
||||
return new List<BookmarkDto>().AsQueryable();
|
||||
}
|
||||
|
||||
var user = await dbContext.Users
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return new List<BookmarkDto>().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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user