- Java 21 (or newer)
- Maven 3.9+ recommended
These commands can be used to build the application and start it:
mvn clean installto buildmvn exec:javato start
npm install -g @usebruno/clito install the Bruno CLIbru runfromsrc/test/LibraryTeststo run the test cases- If you want to view the test cases themselves then you can find Bruno at https://www.usebruno.com and then use it to open the collection in
src/test. - If you want to test the rate limiter then repeatedly sending requests from Bruno in a short period should trigger it.
The API documentation can be found in two places:
http://localhost:8019/v3/api-docsfor the Open API documentationhttp://localhost:8019/swagger-ui/index.htmlfor Swagger
POST /library/borrow-bookexpects JSON:{"isbn":"..."}.POST /library/return-bookexpects JSON:{"isbn":"..."}.
- Users cannot upload the same book twice, an error is returned for this scenario.
- Errors are returned if books cannot be found by ISBN or author.
- Errors are returned if books are borrowed/returned that don't belong to the library
- Errors are returned if someone tries to borrow a book and there are no copies left
- If someone returns a book that isn't from the library but matches one that's offered then it will be accepted!
- I decided to implement the Library cache using an enum as more traditional methods such as singleton objects can be defeated using Spring's dependency injection tools.
- The Bruno collection contains tests and assertions to ensure the output of the rest API is correct.
- I implemented a validation exception handler to handle any cases where book attributes are incorrect.
- I used Spring AOP to add a logging aspect to the rest controller.
- Bucket4j is used for rate limiting.