Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions LibraryManagement.Api/Controllers/ReadersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,55 @@ public async ValueTask<ActionResult<Reader>> PostReaderAsync(Reader reader)
return InternalServerError(readerServiceException.InnerException);
}
}

[HttpGet("all")]
public ActionResult<IQueryable<Reader>> GetAllReaders()
{
try
{
IQueryable<Reader> 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<ActionResult<Reader>> 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);
}
}
}
}
Loading