|
|
@ -1,15 +1,7 @@
|
|
|
|
using Amazon.Runtime.Internal;
|
|
|
|
using BukiVedi.Shared.Entities;
|
|
|
|
using BukiVedi.Shared.Entities;
|
|
|
|
|
|
|
|
using BukiVedi.Shared.Models;
|
|
|
|
using BukiVedi.Shared.Models;
|
|
|
|
using BukiVedi.Shared.Services;
|
|
|
|
using BukiVedi.Shared.Services;
|
|
|
|
using BukiVedi.Shared.Services.Mappers;
|
|
|
|
using BukiVedi.Shared.Services.Mappers;
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Reflection.Metadata;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using ZeroLevel.Services.FileSystem;
|
|
|
|
using ZeroLevel.Services.FileSystem;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BukiVedi.Shared.Apps
|
|
|
|
namespace BukiVedi.Shared.Apps
|
|
|
@ -33,16 +25,11 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
var authors = book.AuthorIds;
|
|
|
|
var authors = book.AuthorIds;
|
|
|
|
if (!string.IsNullOrEmpty(account_id) && authors?.Count > 0)
|
|
|
|
if (!string.IsNullOrEmpty(account_id) && authors?.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var author in authors)
|
|
|
|
foreach (var author_id in authors)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var exists_fiter = Builders<FavoriteAuthor>.Filter.And
|
|
|
|
if (await Tables.FavoriteAuthors.Exists(Filters.FavoriteAuthors.Exact(author_id, account_id)) == false)
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<FavoriteAuthor>.Filter.Eq(f => f.UserId, account_id),
|
|
|
|
|
|
|
|
Builders<FavoriteAuthor>.Filter.Eq(f => f.AuthorId, author)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (await Tables.FavoriteAuthors.Exists(exists_fiter) == false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.FavoriteAuthors.Write(new FavoriteAuthor { AuthorId = author, UserId = account_id });
|
|
|
|
await Tables.FavoriteAuthors.Write(new FavoriteAuthor { AuthorId = author_id, UserId = account_id });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -56,12 +43,7 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var exists_fiter = Builders<ReadQueueItem>.Filter.And
|
|
|
|
if (await Tables.ReadQueue.Exists(Filters.BooksToRead.Exact(id, account_id)) == false)
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<ReadQueueItem>.Filter.Eq(f => f.UserId, account_id),
|
|
|
|
|
|
|
|
Builders<ReadQueueItem>.Filter.Eq(f => f.BookId, id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (await Tables.ReadQueue.Exists(exists_fiter) == false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.ReadQueue.Write(new ReadQueueItem { BookId = id, UserId = account_id, Timestamp = Timestamp.UtcNow });
|
|
|
|
await Tables.ReadQueue.Write(new ReadQueueItem { BookId = id, UserId = account_id, Timestamp = Timestamp.UtcNow });
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,12 +58,7 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var exists_fiter = Builders<FavoriteBook>.Filter.And
|
|
|
|
if (await Tables.FavoriteBooks.Exists(Filters.FavoriteBooks.ByBook(id, account_id)) == false)
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<FavoriteBook>.Filter.Eq(f => f.UserId, account_id),
|
|
|
|
|
|
|
|
Builders<FavoriteBook>.Filter.Eq(f => f.BookId, id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (await Tables.FavoriteBooks.Exists(exists_fiter) == false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.FavoriteBooks.Write(new FavoriteBook { BookId = id, UserId = account_id });
|
|
|
|
await Tables.FavoriteBooks.Write(new FavoriteBook { BookId = id, UserId = account_id });
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -96,12 +73,7 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var exists_fiter = Builders<DisgustingBook>.Filter.And
|
|
|
|
if (await Tables.DisgustingBooks.Exists(Filters.DisgustingBooks.ByBook(id, account_id)) == false)
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<DisgustingBook>.Filter.Eq(f => f.UserId, account_id),
|
|
|
|
|
|
|
|
Builders<DisgustingBook>.Filter.Eq(f => f.BookId, id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (await Tables.DisgustingBooks.Exists(exists_fiter) == false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.DisgustingBooks.Write(new DisgustingBook { BookId = id, UserId = account_id });
|
|
|
|
await Tables.DisgustingBooks.Write(new DisgustingBook { BookId = id, UserId = account_id });
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -120,12 +92,7 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var author in authors)
|
|
|
|
foreach (var author in authors)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var exists_fiter = Builders<DisgustingAuthor>.Filter.And
|
|
|
|
if (await Tables.DisgustingAuthors.Exists(Filters.DisgustingAuthors.ByAuthor(author, account_id)) == false)
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<DisgustingAuthor>.Filter.Eq(f => f.UserId, account_id),
|
|
|
|
|
|
|
|
Builders<DisgustingAuthor>.Filter.Eq(f => f.AuthorId, author)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (await Tables.DisgustingAuthors.Exists(exists_fiter) == false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.DisgustingAuthors.Write(new DisgustingAuthor { AuthorId = author, UserId = account_id });
|
|
|
|
await Tables.DisgustingAuthors.Write(new DisgustingAuthor { AuthorId = author, UserId = account_id });
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -149,13 +116,7 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
|
|
|
|
|
|
|
|
public async Task RemoveFromFavorite(string id, OperationContext context)
|
|
|
|
public async Task RemoveFromFavorite(string id, OperationContext context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (context?.OperationInitiator?.Id == null) throw new InvalidOperationException("Unauthorized");
|
|
|
|
var records = await Tables.FavoriteBooks.Get(Filters.FavoriteBooks.ByBook(id, context.OperationInitiator.Id));
|
|
|
|
var exists_fiter = Builders<FavoriteBook>.Filter.And
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<FavoriteBook>.Filter.Eq(f => f.UserId, context.OperationInitiator.Id),
|
|
|
|
|
|
|
|
Builders<FavoriteBook>.Filter.Eq(f => f.BookId, id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
var records = await Tables.FavoriteBooks.Get(exists_fiter);
|
|
|
|
|
|
|
|
foreach (var record in records)
|
|
|
|
foreach (var record in records)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.FavoriteBooks.TryRemoveById(record.Id);
|
|
|
|
await Tables.FavoriteBooks.TryRemoveById(record.Id);
|
|
|
@ -164,13 +125,7 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
|
|
|
|
|
|
|
|
public async Task RemoveFromReadingQueue(string id, OperationContext context)
|
|
|
|
public async Task RemoveFromReadingQueue(string id, OperationContext context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (context?.OperationInitiator?.Id == null) throw new InvalidOperationException("Unauthorized");
|
|
|
|
var records = await Tables.ReadQueue.Get(Filters.BooksToRead.Exact(id, context.OperationInitiator.Id));
|
|
|
|
var exists_fiter = Builders<ReadQueueItem>.Filter.And
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<ReadQueueItem>.Filter.Eq(f => f.UserId, context.OperationInitiator.Id),
|
|
|
|
|
|
|
|
Builders<ReadQueueItem>.Filter.Eq(f => f.BookId, id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
var records = await Tables.ReadQueue.Get(exists_fiter);
|
|
|
|
|
|
|
|
foreach (var record in records)
|
|
|
|
foreach (var record in records)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.ReadQueue.TryRemoveById(record.Id);
|
|
|
|
await Tables.ReadQueue.TryRemoveById(record.Id);
|
|
|
@ -186,35 +141,35 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
case "@favorites":
|
|
|
|
case "@favorites":
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = (await _library.SearchFavoritesBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
var books = (await _library.SearchFavoritesBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
return await BookEntityMapper.Map(books);
|
|
|
|
return await BookEntityMapper.Map(books, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "@favoriteauthors":
|
|
|
|
case "@favoriteauthors":
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = (await _library.SearchFavoriteAuthorsBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
var books = (await _library.SearchFavoriteAuthorsBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
return await BookEntityMapper.Map(books);
|
|
|
|
return await BookEntityMapper.Map(books, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "@tagged":
|
|
|
|
case "@tagged":
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = (await _library.SearchTaggedBooks(context.OperationInitiator.Id, tag: tag!)).ToArray();
|
|
|
|
var books = (await _library.SearchTaggedBooks(context.OperationInitiator.Id, tag: tag!)).ToArray();
|
|
|
|
return await BookEntityMapper.Map(books);
|
|
|
|
return await BookEntityMapper.Map(books, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "@blocked":
|
|
|
|
case "@blocked":
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = (await _library.SearchBlockedBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
var books = (await _library.SearchBlockedBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
return await BookEntityMapper.Map(books);
|
|
|
|
return await BookEntityMapper.Map(books, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "@toread":
|
|
|
|
case "@toread":
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = (await _library.SearchToReadBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
var books = (await _library.SearchToReadBooks(context.OperationInitiator.Id)).ToArray();
|
|
|
|
return await BookEntityMapper.Map(books);
|
|
|
|
return await BookEntityMapper.Map(books, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = (await _library.SearchBooks(query)).ToArray();
|
|
|
|
var books = (await _library.SearchBooks(query)).ToArray();
|
|
|
|
return await BookEntityMapper.Map(books);
|
|
|
|
return await BookEntityMapper.Map(books, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -223,16 +178,10 @@ namespace BukiVedi.Shared.Apps
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UnblockBook(string id, OperationContext context)
|
|
|
|
public async Task UnblockBook(string id, OperationContext context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (context?.OperationInitiator?.Id == null) throw new InvalidOperationException("Unauthorized");
|
|
|
|
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
var account_id = context.OperationInitiator.Id;
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
if (!string.IsNullOrEmpty(account_id))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var exists_fiter = Builders<DisgustingBook>.Filter.And
|
|
|
|
var records = await Tables.DisgustingBooks.Get(Filters.DisgustingBooks.ByBook(id, account_id));
|
|
|
|
(
|
|
|
|
|
|
|
|
Builders<DisgustingBook>.Filter.Eq(f => f.UserId, account_id),
|
|
|
|
|
|
|
|
Builders<DisgustingBook>.Filter.Eq(f => f.BookId, id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
var records = await Tables.DisgustingBooks.Get(exists_fiter);
|
|
|
|
|
|
|
|
foreach (var record in records)
|
|
|
|
foreach (var record in records)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Tables.DisgustingBooks.TryRemoveById(record.Id);
|
|
|
|
await Tables.DisgustingBooks.TryRemoveById(record.Id);
|
|
|
|