Simple library API project enabling to manage books, login and register users.
- Java 21
- Spring Boot
4.0.6 - Spring Data JPA
- Spring Security
- PostgreSQL
18.1 - JWT (JSON Web Tokens)
- Gradle
Kotlin DSL - Flyway
- Clone the repository:
git clone git@github.com:Qbiterv/library-api.git
- Navigate to the project directory:
cd library-api
-
Preferred Postgres version is
18.1 -
Preferred Java version is
21 -
To make integration tests you need Docker installed and running on your machine.
-
Then you can run tests with command:
./gradlew test -
There is a way to create default admin user by running the application with
localprofile and setting it up in properties. This is not recommended for production use, but can be useful for testing and development purposes.test.admin.create=true- This property enables the creation of a default admin user.test.admin.username=admin- This property sets the username for the default admin user.test.admin.password=admin- This property sets the password for the default admin user.
- Configure database connection and JWT settings:
- Create a
application-local.propertiesfile in thesrc/main/resourcesdirectory with the following content (application-local.properties.examplecan be used as a template):spring.datasource.url=jdbc:postgresql://localhost:5432/postgres spring.datasource.username=postgres spring.datasource.password=password jwt.expiration=8640000 jwt.secret=your_jwt_secret_key test.admin.create=true test.admin.username=admin test.admin.password=admin
- Create a
- Build the project using Gradle:
./gradlew build
- Run the application:
./gradlew bootRun --args='--spring.profiles.active=local'
-
Build the project using Gradle:
./gradlew build
-
Export environment variables for database connection and JWT settings:
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/postgres export SPRING_DATASOURCE_USERNAME=postgres export SPRING_DATASOURCE_PASSWORD=password export JWT_EXPIRATION=8640000 export JWT_SECRET=your_jwt_secret_key
-
Run the application:
java -jar build/libs/library-api-0.0.1-SNAPSHOT.jar
- User Registration:
POST /auth/register{ "username": "string", "password": "string" } - User Login:
POST /auth/login{ "username": "string", "password": "string" }- Response:
{ "code": "USER_LOGIN", "message": "token", "timestamp": "yyyy-mm-ddThh:mm:ss" }
All requests below requires Auth Bearer Header
- Get All Books:
GET /books - Get Book by ID:
GET /books/{id} - Get Book by ISBN:
GET /books/isbn/{isbn}
All requests below requires User with ADMIN role
- Create Book:
POST /books{ "title": "string", "author": "string", "publishedYear": "short", "isbn": "string", "pages": "int" } - Delete Book by ID:
DELETE /books/{id} - Delete Book by ISBN:
DELETE /books/isbn/{isbn}
Updates can be made partially
- Full Request:
{ "title": "string", "author": "string", "publishedYear": "short", "isbn": "string", "pages": "int" } - Example Request (updating pages count)
{ "pages": 103 }
- Update Book by ID:
PATCH /books/{id} - Update Book by ISBN:
PATCH /books/isbn/{isbn}