diff --git a/LibraryManagement.Api/Controllers/ReadersController.cs b/LibraryManagement.Api/Controllers/ReadersController.cs index 4c603e2..2a7fb4c 100644 --- a/LibraryManagement.Api/Controllers/ReadersController.cs +++ b/LibraryManagement.Api/Controllers/ReadersController.cs @@ -137,5 +137,43 @@ public async ValueTask> PutReaderAsync(Reader reader) return InternalServerError(readerServiceException.InnerException); } } + + [HttpDelete] + public async ValueTask> DeleteReaderAsync(Guid readerId) + { + try + { + Reader deleteReader = + await this.readerService.RemoveReaderByIdAsync(readerId); + + return Ok(deleteReader); + } + catch (ReaderValidationException readerValidationException) + when (readerValidationException.InnerException is NotFoundReaderException) + { + return NotFound(readerValidationException.InnerException); + } + catch (ReaderValidationException readerValidationException) + { + return BadRequest(readerValidationException.InnerException); + } + catch (ReaderDependencyValidationException readerDependencyValidationException) + when (readerDependencyValidationException.InnerException is LockedReaderException) + { + return Locked(readerDependencyValidationException.InnerException); + } + catch (ReaderDependencyValidationException readerDependencyValidationException) + { + return BadRequest(readerDependencyValidationException.InnerException); + } + catch (ReaderDependencyException readerDependencyException) + { + return InternalServerError(readerDependencyException.InnerException); + } + catch (ReaderServiceException readerServiceException) + { + return InternalServerError(readerServiceException.InnerException); + } + } } }