Skip to content

Commit 138c24a

Browse files
Merge pull request #55 from DilmurodDeveloper/users/DilmurodDeveloper/exposers-reader-get
EXPOSERS: Get Reader
2 parents 31002ef + c202b3e commit 138c24a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

LibraryManagement.Api/Controllers/ReadersController.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,55 @@ public async ValueTask<ActionResult<Reader>> PostReaderAsync(Reader reader)
5454
return InternalServerError(readerServiceException.InnerException);
5555
}
5656
}
57+
58+
[HttpGet("all")]
59+
public ActionResult<IQueryable<Reader>> GetAllReaders()
60+
{
61+
try
62+
{
63+
IQueryable<Reader> allReaders =
64+
this.readerService.RetrieveAllReaders();
65+
66+
return Ok(allReaders);
67+
}
68+
catch (ReaderDependencyException readerDependencyException)
69+
{
70+
return InternalServerError(readerDependencyException.InnerException);
71+
}
72+
catch (ReaderServiceException readerServiceException)
73+
{
74+
return InternalServerError(readerServiceException.InnerException);
75+
}
76+
}
77+
78+
[HttpGet("{readerId}")]
79+
public async ValueTask<ActionResult<Reader>> GetReaderByIdAsync(Guid readerId)
80+
{
81+
try
82+
{
83+
Reader getReaderById =
84+
await this.readerService.RetrieveReaderByIdAsync(readerId);
85+
86+
return Ok(getReaderById);
87+
}
88+
catch (ReaderValidationException readerValidationException)
89+
when (readerValidationException.InnerException is InvalidReaderException)
90+
{
91+
return BadRequest(readerValidationException.InnerException);
92+
}
93+
catch (ReaderValidationException readerValidationException)
94+
when (readerValidationException.InnerException is NotFoundReaderException)
95+
{
96+
return NotFound(readerValidationException.InnerException);
97+
}
98+
catch (ReaderDependencyException readerDependencyException)
99+
{
100+
return InternalServerError(readerDependencyException.InnerException);
101+
}
102+
catch (ReaderServiceException readerServiceException)
103+
{
104+
return InternalServerError(readerServiceException.InnerException);
105+
}
106+
}
57107
}
58108
}

0 commit comments

Comments
 (0)