public async Task <ActionResult <BookContent> > UpdateContentAsync(string id, string contentId, BookContentBase model) { using (await _locker.EnterAsync(id)) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } var content = book.Contents.FirstOrDefault(c => c.Id == contentId); if (content == null) { return(ResultUtilities.NotFound <BookContent>(id, contentId)); } _mapper.Map(model, content); await _books.UpdateAsync(book); await _snapshots.ModifiedAsync(book); return(content); } }
public async Task <ActionResult <Book> > RollBackAsync(string id, RollbackRequest request, [FromQuery] string reason = null) { var result = await _snapshots.GetAsync(ObjectType.Book, request.SnapshotId); if (!result.TryPickT0(out var snapshot, out _)) { return(ResultUtilities.NotFound(request.SnapshotId)); } var rollbackResult = await _snapshots.RollbackAsync <DbBook>(snapshot, new SnapshotArgs { Committer = User, Event = SnapshotEvent.AfterRollback, Reason = reason, Rollback = snapshot, Source = SnapshotSource.User }); if (!rollbackResult.TryPickT0(out var value, out _)) { return(ResultUtilities.NotFound(id)); } var(book, _) = value; return(book.Convert(_services)); }
public async Task <ActionResult <Snapshot> > GetSnapshotAsync(string id) { var result = await _snapshots.GetAsync(ObjectType.Book, id); if (!result.TryPickT0(out var snapshot, out _)) { return(ResultUtilities.NotFound(id)); } return(snapshot.Convert(_services)); }
public async Task <ActionResult <User> > GetAsync(string id) { var result = await _users.GetAsync(id); if (!result.TryPickT0(out var user, out _)) { return(ResultUtilities.NotFound(id)); } return(ProcessUser(user.Convert(_services))); }
public async Task <ActionResult <Book> > GetAsync(string id) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } return(book); }
public ActionResult <UploadState> GetUpload(string id) { var task = _uploads.GetTask <BookUpload>(id); if (task == null) { return(ResultUtilities.NotFound <UploadTask>(id)); } return(task); }
public async Task <ActionResult <Book> > RefreshContentAsync(string id, RefreshContentRequest request) { var result = await _books.RefreshAsync(id, request.ContentId); if (!result.TryPickT0(out var value, out _)) { return(ResultUtilities.NotFound(id, request.ContentId)); } return(value.Convert(_services)); }
public async Task <ActionResult <Collection> > SortItemsAsync(string id, CollectionItemsRequest request) { var result = await _collections.SortAsync(id, request.Items, CurrentConstraint); if (!result.TryPickT0(out var collection, out _)) { return(ResultUtilities.NotFound(id)); } return(collection.Convert(_services)); }
public async Task <ActionResult <Vote> > GetVoteAsync(string id) { var result = await _votes.GetAsync(UserId, new nhitomiObject(ObjectType.Book, id)); if (!result.TryPickT0(out var vote, out _)) { return(ResultUtilities.NotFound(id)); } return(vote.Convert(_services)); }
public async Task <ActionResult <DownloadSession> > GetSessionAsync(string id) { var result = await _downloads.GetSessionAsync(id); if (!result.TryPickT0(out var session, out _)) { return(ResultUtilities.NotFound(id)); } return(session.Convert()); }
public async Task <ActionResult <Book> > GetAsync(string id) { var result = await _books.GetAsync(id); if (!result.TryPickT0(out var book, out _)) { return(ResultUtilities.NotFound(id)); } return(book.Convert(_services)); }
public async Task <ActionResult <Collection> > GetAsync(string id) { var result = await _collections.GetAsync(id); if (!result.TryPickT0(out var collection, out _) || !CurrentConstraint.Test(collection)) { return(ResultUtilities.NotFound(id)); } return(collection.Convert(_services)); }
public async Task <ActionResult <Collection> > UpdateAsync(string id, CollectionBase model) { var result = await _collections.UpdateAsync(id, model, CurrentConstraint); if (!result.TryPickT0(out var collection, out _)) { return(ResultUtilities.NotFound(id)); } return(collection.Convert(_services)); }
public async Task <ActionResult <Vote> > SetVoteAsync(string id, VoteBase model) { var result = await _books.GetAsync(id); if (!result.TryPickT0(out var book, out _)) { return(ResultUtilities.NotFound(id)); } var vote = await _votes.SetAsync(UserId, book, model.Type); return(vote.Convert(_services)); }
public async Task <ActionResult <BookContent> > GetContentAsync(string id, string contentId) { var result = await _books.GetContentAsync(id, contentId); if (!result.TryPickT0(out var value, out _)) { return(ResultUtilities.NotFound(id, contentId)); } var(_, content) = value; return(content.Convert(_services)); }
public async Task <ActionResult> GetImageAsync(string id, string contentId, int index) { var file = await _storage.ReadAsync($"{id}/{contentId}/{index}"); if (file == null) { return(ResultUtilities.NotFound <StorageFile>(id, contentId, index)); } var stream = file.Stream; var mediaType = file.MediaType; return(new FileStreamResult(stream, mediaType)); }
public async Task <ActionResult <UserController.AuthenticateResponse> > AuthDirectAsync(string id) { var result = await _users.GetAsync(id); if (!result.TryPickT0(out var user, out _)) { return(ResultUtilities.NotFound(id)); } return(new UserController.AuthenticateResponse { Token = await _auth.GenerateTokenAsync(user), User = ProcessUser(user.Convert(_services)) }); }
public async Task <ActionResult <Collection> > GetSpecialCollectionAsync(string id, ObjectType type, SpecialCollection collection) { if (UserId != id && !User.HasPermissions(UserPermissions.ManageUsers)) { return(ResultUtilities.Forbidden("Insufficient permissions to see user collections.")); } var result = await _collections.GetOrCreateUserSpecialCollectionAsync(id, type, collection); if (!result.TryPickT0(out var coll, out _)) { return(ResultUtilities.NotFound(id)); } return(coll.Convert(_services)); }
public async Task <ActionResult <User> > UnrestrictAsync(string id, [FromQuery] string reason = null) { var result = await _users.UnrestrictAsync(id, new SnapshotArgs { Committer = User, Event = SnapshotEvent.AfterModification, Reason = reason, Source = SnapshotSource.User }); if (!result.TryPickT0(out var user, out _)) { return(ResultUtilities.NotFound(id)); } return(ProcessUser(user.Convert(_services))); }
public async Task <ActionResult <Book> > UpdateAsync(string id, BookBase model, [FromQuery] string reason = null) { var result = await _books.UpdateAsync(id, model, new SnapshotArgs { Committer = User, Event = SnapshotEvent.AfterModification, Reason = reason, Source = SnapshotSource.User }); if (!result.TryPickT0(out var book, out _)) { return(ResultUtilities.NotFound(id)); } return(book.Convert(_services)); }
public async Task <ActionResult> GetImageAsync(string id, string contentId, int index) { if (index < -1) { return(ResultUtilities.NotFound(id, contentId, index)); } var result = await _books.GetContentAsync(id, contentId); if (!result.TryPickT0(out var value, out _)) { return(ResultUtilities.NotFound(id, contentId)); } var(book, content) = value; return(new BookScraperImageResult(book, content, index)); }
public async Task <ActionResult <BookContent> > GetContentAsync(string id, string contentId) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } var content = book.Contents.FirstOrDefault(c => c.Id == contentId); if (content == null) { return(ResultUtilities.NotFound <BookContent>(id, contentId)); } return(content); }
public async Task <ActionResult <Collection> > AddOwnerAsync(string id, AddCollectionOwnerRequest request) { var userResult = await _users.GetAsync(request.UserId); if (!userResult.TryPickT0(out var user, out _) || !user.AllowSharedCollections) { return(ResultUtilities.NotFound(request.UserId)); } var result = await _collections.AddOwnerAsync(id, request.UserId, CurrentConstraint); if (!result.TryPickT0(out var collection, out _)) { return(ResultUtilities.NotFound(id)); } return(collection.Convert(_services)); }
public async Task <ActionResult <Book> > GetSnapshotValueAsync(string id) { var result = await _snapshots.GetAsync(ObjectType.Book, id); if (!result.TryPickT0(out var snapshot, out _)) { return(ResultUtilities.NotFound(id)); } var valueResult = await _snapshots.GetValueAsync <DbBook>(snapshot); if (!valueResult.TryPickT0(out var book, out _)) { return(ResultUtilities.NotFound(id)); } return(book.Convert(_services)); }
public async Task <ActionResult> UnsetVoteAsync(string id) { using (await _locker.EnterAsync(id)) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } await _votes.SetAsync(book, null); // score is updated await _books.UpdateAsync(book); return(Ok()); } }
public async Task <ActionResult <Vote> > SetVoteAsync(string id, VoteBase model) { using (await _locker.EnterAsync(id)) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } var vote = await _votes.SetAsync(book, model.Type); // score is updated await _books.UpdateAsync(book); return(vote); } }
public async Task <ActionResult> DeleteAsync(string id) { using (await _locker.EnterAsync(id)) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } await _books.DeleteAsync(book); await _snapshots.DeletedAsync(book); await _storage.DeleteAsync(GetFileNames(book)); } return(Ok()); }
public async Task <ActionResult <Book> > UpdateAsync(string id, BookBase model) { using (await _locker.EnterAsync(id)) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } _mapper.Map(model, book); await _books.UpdateAsync(book); await _snapshots.ModifiedAsync(book); return(book); } }
public override async Task ExecuteResultAsync(ActionContext context) { var cancellationToken = context.HttpContext.RequestAborted; var storage = context.HttpContext.RequestServices.GetService <IStorage>(); var result = await storage.ReadAsync(_name, cancellationToken); if (!result.TryPickT0(out var file, out _)) { await ResultUtilities.NotFound(_name).ExecuteResultAsync(context); return; } await using (file) { SetHeaders(context, file); await file.Stream.CopyToAsync(context.HttpContext.Response.Body, cancellationToken); } }
public async Task <ActionResult> DeleteContentAsync(string id, string contentId) { using (await _locker.EnterAsync(id)) { var book = await _books.GetAsync(id); if (book == null) { return(ResultUtilities.NotFound <Book>(id)); } var content = book.Contents.FirstOrDefault(c => c.Id == contentId); if (content == null) { return(ResultUtilities.NotFound <BookContent>(id, contentId)); } if (book.Contents.Length == 1) { // delete the entire book await _books.DeleteAsync(book); await _snapshots.DeletedAsync(book); } else { // remove the content book.Contents = book.Contents.Where(c => c != content).ToArray(); await _books.UpdateAsync(book); await _snapshots.ModifiedAsync(book); } await _storage.DeleteAsync(GetFileNames(book, content)); return(Ok()); } }