- Utilize Java 20
- Spring Command Line Runner for migrating players data
- Handle LocalDate serialize/deserialize
- Spring Web CRUD
- Spring Data JPA
- PostgreSQL
- Docker Compose
- Standard Response Codes
- Combinator Validation
- Spring Boot Test Starter (Mockito + AssertJ)
- GitHub Actions CI Pipeline
[ ] ExceptionsDeprecated[ ] Spring HATEOASDeprecated
- Java Versions and Features
- Building REST services with Spring
- Cross Site Request Forgery (CSRF)
- Unit Testing with Spring Boot
- Setup Postgres in GitHub Actions
- Adding workflow status badge
- Learn Spring Boot 3
- Java Functional Programming
- Install
Java 20, latestDocker, andIntelliJ Communitywith theIdeaVim&Dockerplugins installed - Run the database by open project with IntelliJ, open
compose.yamland hit run - Create
playerdatabase in a terminal:
docker exec -it postgres bash
psql -U postgres
create database player;- Run the backend by open
com/lavantien/restapi/RestapiApplication.java
- Install
Java 20, latestDocker, andNeovimwith theMasonplugins; UseMasonto install a Java LS - Run the database in a terminal:
docker compose up -d- Create
playerdatabase in a terminal:
docker exec -it postgres bash
psql -U postgres
create database player;- Run the backend in a terminal:
mvn install
mvn spring-boot:run- Run unit test with
mvn test, or more specificallyClassName#methodName:
mvn test -Dtest=ControllerTest#allPlayers test- Using
curlor any mock callers to test the endpoints atlocalhost:8081 - Or you can use
Kreyaand take advantage of themock-callerdirectory - There will be an existing list of players migrated to the database for testing purpose
GET /api/playersretrieves a list of all players
[
{
"id": 2,
"name": "player b",
"email": "b@b.com",
"password": "password",
"dateOfBirth": "2023-05-21"
},
{
"id": 3,
"name": "player c",
"email": "c@c.com",
"password": "password",
"dateOfBirth": "2023-05-21"
},
{
"id": 4,
"name": "player d",
"email": "d@d.com",
"password": "password",
"dateOfBirth": "2023-05-21"
}
]GET /api/players/{id}retrieves a specific player with the matchingid
{
"id": 6,
"name": "player f",
"email": "f@f.com",
"password": "password",
"dateOfBirth": "2023-05-21"
}POST /api/playerscreates a new player; returned the newly created player
{
"id": 32,
"name": "player 0",
"email": "player0@gmail.com",
"password": "12345670",
"dateOfBirth": "1990-02-01"
}PATCH /api/playerscreates a batch of new players; returned the failed players
[
{
"id": 27,
"name": "player 1",
"email": "player0gmail.com",
"password": "12345671",
"dateOfBirth": "1990-01-01"
},
{
"id": 28,
"name": "player 1",
"email": "player1@gmail.com",
"password": "12345672",
"dateOfBirth": "2020-01-02"
}
]PUT /api/players/{id}edits an existing player with the matchingid; returned the newly edited player; creates new player if not existed
{
"id": 6,
"name": "player 6",
"email": "player6@gmail.com",
"password": "12345670",
"dateOfBirth": "1990-02-01"
}DELETE /api/players/{id}deletes an existing player with the matchingid; returned nothing if success
- Based on standard HTTP status codes
- The returned error payload contains the error message relates to the root cause