Last active
April 19, 2020 18:36
-
-
Save celsojr/1a0c6babae9810e17221378d6da4aede to your computer and use it in GitHub Desktop.
See the blog post here: https://celsojr.com/wp/archives/576
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// POST api/v1/author/{authorId}/undo | |
/// <summary> | |
/// Undo a deleted action on Author | |
/// </summary> | |
/// <remarks>Undo a deleted action on Author</remarks> | |
/// <param name="authorId"></param> | |
[HttpPost("{authorId:length(24)}/undo", Name = nameof(UndoDeletedAuthor))] | |
[ProducesResponseType(StatusCodes.Status410Gone)] | |
[ProducesResponseType(StatusCodes.Status201Created)] | |
public async Task<IActionResult> UndoDeletedAuthor(string authorId) | |
{ | |
if (!_memoryCache.TryGetValue(authorId, out Author author)) | |
{ | |
return new StatusCodeResult(StatusCodes.Status410Gone); | |
} | |
_unitOfWork.Library.AddAuthor(author); | |
await _unitOfWork.Commit(); | |
var authorToReturn = _mapper.Map<AuthorDto>(author); | |
return CreatedAtAction(nameof(GetAuthor), new { authorId }, authorToReturn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment