Implement UC-01: Backend service for managing players with full CRUD operations, OpenAPI documentation, and Flyway migrations#3
Conversation
…anagement Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
| @@ -0,0 +1,60 @@ | |||
| package com.skat.backend.domain.entities; | |||
There was a problem hiding this comment.
Use Lombok see ADR-004-Lombok.md
There was a problem hiding this comment.
Updated all entity classes to use Lombok (@DaTa, @NoArgsConstructor, @AllArgsConstructor) as per ADR-004. Commit: 485c14a
|
|
||
| boolean existsByFirstNameIgnoreCaseAndLastNameIgnoreCaseAndIdNot(String firstName, String lastName, UUID id); | ||
|
|
||
| @Query(value = """ |
There was a problem hiding this comment.
Use List of PlayerENtity as return type. Score will be loaded in the mapper for the fetched players. See alos ADR-005
There was a problem hiding this comment.
Refactored PlayerRepository to return List instead of Object[]. Added separate method findLatestScoresForPlayers in PlayerScoreRepository to fetch scores. Scores are now loaded separately after fetching players as per ADR-005. Commit: 485c14a
| public class PlayersServiceImpl implements PlayersService { | ||
|
|
||
| private final PlayerRepository playerRepository; | ||
| private final GameRepository gameRepository; |
There was a problem hiding this comment.
Use @Autoried on private members (no injection with construcotrs) see adr-007
There was a problem hiding this comment.
Changed to use @Autowired on private members for all dependencies (playerRepository, gameRepository, playerScoreRepository) as per ADR-007. Removed constructor injection. Commit: 485c14a
| @Transactional(readOnly = true) | ||
| public PlayerListResponseTO listPlayers(PlayersQuery query) { | ||
| String sortValue = query.sort().name(); | ||
| List<Object[]> results = playerRepository.findPlayersWithLatestScore( |
There was a problem hiding this comment.
playerRepository.findPlayersWithLatestScore should return a list of PlayerEntities. Themn the IDs of the players should be extrected as a set. The with this list the scores of the players are fetched and the result is us used in the mapping.
There was a problem hiding this comment.
Refactored listPlayers method to:
- Fetch List from repository
- Extract player IDs as a Set
- Fetch latest scores using PlayerScoreRepository.findLatestScoresForPlayers(playerIds)
- Map entities and scores to DTOs in the service layer
Commit: 485c14a
|
@copilot update the code based on my review comments and the new adr in the doc(architecure/decision folder |
- Add Lombok dependency and use @DaTa, @NoArgsConstructor, @AllArgsConstructor for entities - Change PlayerRepository to return List<PlayerEntity> instead of Object[] - Add findLatestScoresForPlayers method to PlayerScoreRepository - Refactor PlayersServiceImpl to use @Autowired on private members instead of constructor injection - Update listPlayers to fetch entities first, then load scores separately as per ADR-005 - Update PlayersController to use @Autowired on private members - Update unit tests to match new repository methods Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
|
@copilot beachte regel ADR-006-var.md immer var anstelle Klassennamen |
- Replace explicit type declarations with var throughout PlayersServiceImpl as per ADR-006 - Replace @MockMvc with TestRestTemplate in PlayersControllerIT as per ADR-008 - Update integration tests to use @SpringBootTest with RANDOM_PORT and TestRestTemplate - Convert all test assertions to use AssertJ instead of jsonPath matchers - All 35 tests still passing (16 unit + 19 integration) Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
Updated code according to ADR-006 and ADR-008: ADR-006 (var): Replaced all explicit type declarations with ADR-008 (TestRestTemplate instead of MockMvc): Completely refactored PlayersControllerIT to use TestRestTemplate instead of MockMvc. Changed from All 35 tests (16 unit + 19 integration) passing. Commit: 4b2a91b |
|
@copilot ergänze openapi/swagger annotations. beachte adr-010-openapi.md |
- Add springdoc-openapi-starter-webmvc-ui dependency (version 2.1.0) - Annotate PlayersController with @tag for API grouping - Add @operation annotations with summaries and descriptions for all endpoints - Add @ApiResponses documenting all response codes (200, 201, 204, 400, 404, 409) - Add @parameter annotations with descriptions and examples - Swagger UI automatically available at /swagger-ui.html - OpenAPI spec available at /v3/api-docs - All 35 tests still passing Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
Added OpenAPI/Swagger annotations as per ADR-010:
Swagger UI is now automatically available at Commit: 393fd38 |
@TestConfiguration(proxyBeanMethods = false) @bean |
…d ADR-012 - Add Flyway dependencies (flyway-core and flyway-database-postgresql) - Add spring-boot-testcontainers dependency for @Serviceconnection support - Configure Flyway in application.properties (enabled, baseline-on-migrate) - Change JPA ddl-auto from 'update' to 'none' (Flyway manages schema now) - Create Flyway migration scripts: - V1__Create_player_table.sql with indexes and constraints - V2__Create_game_table.sql with foreign keys and indexes - V3__Create_player_score_table.sql with indexes - Create PostgresTestcontainersConfig for integration tests - Create application-test.properties with Flyway enabled - Update PlayersControllerIT to use @import(PostgresTestcontainersConfig.class) and @activeprofiles("test") - Remove manual container configuration from tests - All 35 tests passing (16 unit + 19 integration) Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com>
Implemented Flyway migrations and Testcontainers configuration per ADR-011 and ADR-012: Flyway Migrations (ADR-011):
Testcontainers Configuration (ADR-012):
All 35 tests (16 unit + 19 integration) passing. Commit: 5836a42 |
* Architecture * Architecture * UC-01: Backend service for managing players with full CRUD operations, OpenAPI documentation, and Flyway migrations (#3) * Initial plan * Add entities, repositories, DTOs, service and controller for player management Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * Add integration tests and fix parameter binding issue Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * Add unit tests for PlayersService with Mockito Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * Add implementation summary document for UC-01 Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * ADR * Refactor according to ADR-004, ADR-005, and ADR-007 - Add Lombok dependency and use @DaTa, @NoArgsConstructor, @AllArgsConstructor for entities - Change PlayerRepository to return List<PlayerEntity> instead of Object[] - Add findLatestScoresForPlayers method to PlayerScoreRepository - Refactor PlayersServiceImpl to use @Autowired on private members instead of constructor injection - Update listPlayers to fetch entities first, then load scores separately as per ADR-005 - Update PlayersController to use @Autowired on private members - Update unit tests to match new repository methods Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * ADR * Apply ADR-006 (var) and ADR-008 (TestRestTemplate) - Replace explicit type declarations with var throughout PlayersServiceImpl as per ADR-006 - Replace @MockMvc with TestRestTemplate in PlayersControllerIT as per ADR-008 - Update integration tests to use @SpringBootTest with RANDOM_PORT and TestRestTemplate - Convert all test assertions to use AssertJ instead of jsonPath matchers - All 35 tests still passing (16 unit + 19 integration) Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * Cleanup * ADR * Add OpenAPI/Swagger annotations as per ADR-010 - Add springdoc-openapi-starter-webmvc-ui dependency (version 2.1.0) - Annotate PlayersController with @tag for API grouping - Add @operation annotations with summaries and descriptions for all endpoints - Add @ApiResponses documenting all response codes (200, 201, 204, 400, 404, 409) - Add @parameter annotations with descriptions and examples - Swagger UI automatically available at /swagger-ui.html - OpenAPI spec available at /v3/api-docs - All 35 tests still passing Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * ADR * Add Flyway migrations and Testcontainers configuration per ADR-011 and ADR-012 - Add Flyway dependencies (flyway-core and flyway-database-postgresql) - Add spring-boot-testcontainers dependency for @Serviceconnection support - Configure Flyway in application.properties (enabled, baseline-on-migrate) - Change JPA ddl-auto from 'update' to 'none' (Flyway manages schema now) - Create Flyway migration scripts: - V1__Create_player_table.sql with indexes and constraints - V2__Create_game_table.sql with foreign keys and indexes - V3__Create_player_score_table.sql with indexes - Create PostgresTestcontainersConfig for integration tests - Create application-test.properties with Flyway enabled - Update PlayersControllerIT to use @import(PostgresTestcontainersConfig.class) and @activeprofiles("test") - Remove manual container configuration from tests - All 35 tests passing (16 unit + 19 integration) Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> * ADR, Swagger --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jwellniak <87517644+jwellniak@users.noreply.github.com> Co-authored-by: Joern Wellniak <joern.wellniak@partner.bmw.de> --------- Co-authored-by: Joern Wellniak <joern.wellniak@partner.bmw.de> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
UC-01: Service for Managing Players (Backend) - Complete Implementation
Changes Made
ADR-004 (Lombok):
ADR-005 (Repository Returns Entities):
PlayerRepository.findPlayersWithLatestScore()to returnList<PlayerEntity>instead ofList<Object[]>findAllOrderedByName()andfindAllPlayers()PlayerScoreRepository.findLatestScoresForPlayers()to fetch latest scores separatelyPlayersServiceImpl.listPlayers()to:ADR-006 (var):
varthroughout PlayersServiceImpl where type is obviousADR-007 (@Autowired on Private Members):
PlayersServiceImplto use@Autowiredon private members instead of constructor injectionPlayersControllerto use@Autowiredon private members instead of constructor injectionADR-008 (TestRestTemplate instead of MockMvc):
@AutoConfigureMockMvcandMockMvcwithTestRestTemplatein PlayersControllerITrestTemplate.getForEntity(),postForEntity(), andexchange()methods@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)for full application contextADR-010 (OpenAPI/Swagger Annotations):
springdoc-openapi-starter-webmvc-uidependency (version 2.1.0)PlayersControllerwith@Tagfor API documentation grouping@Operationannotations with summaries and descriptions for all endpoints@ApiResponsesdocumenting all possible response codes (200, 201, 204, 400, 404, 409)@Parameterannotations with descriptions and examples for all parameters/swagger-ui.html/v3/api-docsADR-011 and ADR-012 (Flyway Migrations):
src/main/resources/db/migration/:V1__Create_player_table.sql- player table with unique constraint on (first_name, last_name) and indexesV2__Create_game_table.sql- game table with foreign keys to player and indexesV3__Create_player_score_table.sql- player_score table with foreign keys and indexesPostgresTestcontainersConfigwith @Serviceconnection annotation for automatic container managementapplication-test.propertieswith Flyway configuration for testsPlayersControllerITto use@Import(PostgresTestcontainersConfig.class)and@ActiveProfiles("test")Test Updates:
PlayersServiceTestto match new repository methodsImplementation Details
The implementation adheres to all project architectural decisions:
varreducing verbosityAPI Documentation
The REST API is fully documented with OpenAPI/Swagger annotations:
/swagger-ui.html/v3/api-docsDatabase Schema Management
Database schema is now managed through Flyway migrations:
src/main/resources/db/migration/Testing Infrastructure
Integration tests use:
All acceptance criteria remain fully tested and passing.
Fixes #2
Original prompt
This section details on the original issue you should resolve
<issue_title>UC-01: Service for managing players in the backend</issue_title>
<issue_description># UC-01: Service for Managing Players (Backend)
References (Constraints & Context)
ARCHITECTURE.mddb_entities.mdREST_ENDPOINTS_overview.mdGET_players_spec.mdPOST_players_upsert.mdDELETE_player_spec.mdScope
Implement the backend capabilities to:
(first_name, last_name).forceDeletionbehavior:false: delete only if the player has no games/scores.true: nullify references in games/scores, then delete.Actors
Functional Requirements
List Players
/api/playerssortenum (name,score_desc),startIndex(≥ 0),pageSize(1..200).items[]with player id, names, current total points, current sequence index, updated timestamp +pagingandsortmetadata.GET_players_spec.md.Upsert Player
/api/players{ id? , first_name, last_name }, names required, ≤ 50 chars, trimmed.idpresent → update only if player exists. Enforce uniqueness of(first_name, last_name)for the new values.id→ create new player if uniqueness is not violated.POST_players_upsert.md.Delete Player
/api/players/{id}?forceDeletion={bool}forceDeletion=false→ delete only if no references ingameorplayer_score.forceDeletion=true→ set FKs toNULLingame/player_scorefirst, then delete.DELETE_player_spec.md.Non-Functional Requirements
OffsetDateTime(ISO-8601).@NotBlank,@Size,@Min,@Max, etc.).Success Criteria
Acceptance Criteria (Gherkin)
AC-1: List players — default sorting and paging
AC-2: List players — score_desc ordering
AC-3: List players — parameter validation
AC-4: Create player — unique full name
AC-5: Create player — conflict on duplicate full name