This GitHub Classroom lab teaches the basics of Spring Boot and Spring Data JPA using a simple 1v1 matching game server theme.
Students will work with:
- Spring Boot application structure
- REST controllers
- JPA entities and relationships
- Spring Data repositories
- a service layer
- an in-memory H2 database for local testing
By the end of this lab, you should be able to:
- explain the role of
@SpringBootApplication,@RestController,@Service,@Entity, and repository interfaces - model a simple domain using JPA relationships
- save and query entities with Spring Data JPA
- implement service-layer methods that support a small matchmaking workflow
- run tests against an H2 in-memory database
The app models a simplified 1v1 matching server:
PlayerAccount: a player with a username and ratingQueueEntry: a player waiting in the matchmaking queueMatchRecord: a 1v1 match between two players, with an optional winner
Complete the TODO methods in:
MatchmakingService.java
Required methods:
registerPlayerenqueuePlayercreateMatchfinishMatchfindRecentMatchesForPlayer
- Do not rename classes or methods.
- Do not change package names.
- Do not modify the tests.
- Keep all code in
edu.sdccd.cisc191. - Use the repositories provided in the starter.
- Throw
IllegalArgumentExceptionwhen an ID does not exist or a winner is not part of the match.
mvn spring-boot:runThe app uses an in-memory H2 database.
mvn testRegister a player:
curl -X POST "http://localhost:8080/api/players?username=alpha&rating=1200"Put a player in queue:
curl -X POST "http://localhost:8080/api/queue/1"Create a match:
curl -X POST "http://localhost:8080/api/matches?playerOneId=1&playerTwoId=2&arenaName=Volcano"Complete a match:
curl -X POST "http://localhost:8080/api/matches/1/finish?winnerId=2"- Why is the service layer useful even when repositories already exist?
- What JPA relationship is used from
QueueEntrytoPlayerAccount? - Why does
MatchRecordstore references to player entities instead of only storing usernames? - What is the benefit of using H2 for a classroom lab?