diff --git a/LibraryManagement.Api/Controllers/ReadersController.cs b/LibraryManagement.Api/Controllers/ReadersController.cs index e2ad32c..798cbe9 100644 --- a/LibraryManagement.Api/Controllers/ReadersController.cs +++ b/LibraryManagement.Api/Controllers/ReadersController.cs @@ -54,5 +54,55 @@ public async ValueTask> PostReaderAsync(Reader reader) return InternalServerError(readerServiceException.InnerException); } } + + [HttpGet("all")] + public ActionResult> GetAllReaders() + { + try + { + IQueryable allReaders = + this.readerService.RetrieveAllReaders(); + + return Ok(allReaders); + } + catch (ReaderDependencyException readerDependencyException) + { + return InternalServerError(readerDependencyException.InnerException); + } + catch (ReaderServiceException readerServiceException) + { + return InternalServerError(readerServiceException.InnerException); + } + } + + [HttpGet("{readerId}")] + public async ValueTask> GetReaderByIdAsync(Guid readerId) + { + try + { + Reader getReaderById = + await this.readerService.RetrieveReaderByIdAsync(readerId); + + return Ok(getReaderById); + } + catch (ReaderValidationException readerValidationException) + when (readerValidationException.InnerException is InvalidReaderException) + { + return BadRequest(readerValidationException.InnerException); + } + catch (ReaderValidationException readerValidationException) + when (readerValidationException.InnerException is NotFoundReaderException) + { + return NotFound(readerValidationException.InnerException); + } + catch (ReaderDependencyException readerDependencyException) + { + return InternalServerError(readerDependencyException.InnerException); + } + catch (ReaderServiceException readerServiceException) + { + return InternalServerError(readerServiceException.InnerException); + } + } } }