-
Notifications
You must be signed in to change notification settings - Fork 0
Implment matches domain #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rootandroo
wants to merge
1
commit into
add-match-cycles-domain
Choose a base branch
from
add-matches-domain
base: add-match-cycles-domain
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/org/patinanetwork/patchats/api/match/AdminMatchController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.patinanetwork.patchats.api.match; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.patinanetwork.patchats.api.match.dto.match.AdminMatchResponse; | ||
| import org.patinanetwork.patchats.api.match.dto.match.CreateMatchRequest; | ||
| import org.patinanetwork.patchats.common.dto.ApiResponder; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/admin/matches") | ||
| @Tag(name = "Admin Matches") | ||
| @RequiredArgsConstructor | ||
| public class AdminMatchController { | ||
|
|
||
| private final MatchService matchService; | ||
|
|
||
| @Operation(summary = "Create a match between two members for a match cycle") | ||
| @PostMapping | ||
| public ResponseEntity<ApiResponder<AdminMatchResponse>> createMatch( | ||
| @Valid @RequestBody final CreateMatchRequest request) { | ||
| final AdminMatchResponse response = matchService.createMatch(request); | ||
| return ResponseEntity.ok(ApiResponder.success("Match created successfully", response)); | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
src/main/java/org/patinanetwork/patchats/api/match/MatchController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
48 changes: 48 additions & 0 deletions
48
src/main/java/org/patinanetwork/patchats/api/match/MatchService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package org.patinanetwork.patchats.api.match; | ||
|
|
||
| import java.time.ZoneOffset; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.patinanetwork.patchats.api.match.db.models.Match; | ||
| import org.patinanetwork.patchats.api.match.db.models.MatchCycle; | ||
| import org.patinanetwork.patchats.api.match.db.repos.MatchCycleRepo; | ||
| import org.patinanetwork.patchats.api.match.db.repos.MatchRepo; | ||
| import org.patinanetwork.patchats.api.match.dto.match.AdminMatchResponse; | ||
| import org.patinanetwork.patchats.api.match.dto.match.CreateMatchRequest; | ||
| import org.patinanetwork.patchats.common.web.exception.MatchCycleNotFoundException; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class MatchService { | ||
|
|
||
| private static final String DEFAULT_MATCH_STATUS = "PENDING"; | ||
| private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM"); | ||
|
|
||
| private final MatchRepo matchRepo; | ||
| private final MatchCycleRepo matchCycleRepo; | ||
|
|
||
| public AdminMatchResponse createMatch(CreateMatchRequest request) { | ||
| MatchCycle cycle = matchCycleRepo | ||
| .getMatchCycleById(request.matchCycleId()) | ||
| .orElseThrow(() -> new MatchCycleNotFoundException(request.matchCycleId())); | ||
|
|
||
| Match match = Match.builder() | ||
| .id(UUID.randomUUID()) | ||
| .memberAId(request.memberAId()) | ||
| .memberBId(request.memberBId()) | ||
| .matchCycleId(request.matchCycleId()) | ||
| .matchScore(request.matchScore()) | ||
| .status(request.status() == null ? DEFAULT_MATCH_STATUS : request.status()) | ||
| .build(); | ||
|
|
||
| Match createdMatch = matchRepo.createMatch(match); | ||
| return AdminMatchResponse.from(createdMatch, deriveMonth(cycle)); | ||
| } | ||
|
|
||
| /** Derives the "YYYY-MM" month label for a match from its cycle's run time (UTC). */ | ||
| private String deriveMonth(final MatchCycle cycle) { | ||
| return MONTH_FORMATTER.format(cycle.getRunAt().atZone(ZoneOffset.UTC)); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/patinanetwork/patchats/api/match/dto/cycle/MatchCycleDetailResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.cycle; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.util.List; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.patinanetwork.patchats.api.match.dto.match.AdminMatchResponse; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @ToString | ||
| @EqualsAndHashCode | ||
| public class MatchCycleDetailResponse { | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final MatchCycleResponse cycle; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final List<AdminMatchResponse> matches; | ||
| } |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/patinanetwork/patchats/api/match/dto/match/AdminMatchResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.match; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.patinanetwork.patchats.api.match.db.models.Match; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @ToString | ||
| @EqualsAndHashCode | ||
| public class AdminMatchResponse { | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final UUID matchId; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final UUID memberAId; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final UUID memberBId; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final Integer matchCycleId; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final String month; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final String status; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED, nullable = true) | ||
| private final Double matchScore; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final Instant createdAt; | ||
|
|
||
| public static AdminMatchResponse from(final Match match, final String month) { | ||
| return AdminMatchResponse.builder() | ||
| .matchId(match.getId()) | ||
| .memberAId(match.getMemberAId()) | ||
| .memberBId(match.getMemberBId()) | ||
| .matchCycleId(match.getMatchCycleId()) | ||
| .month(month) | ||
| .status(match.getStatus()) | ||
| .matchScore(match.getMatchScore()) | ||
| .createdAt(match.getCreatedAt()) | ||
| .build(); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/patinanetwork/patchats/api/match/dto/match/BulkCreateMatchesRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.match; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.NotEmpty; | ||
| import java.util.List; | ||
|
|
||
| public record BulkCreateMatchesRequest(@Valid @NotEmpty List<CreateMatchRequest> matches) {} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/patinanetwork/patchats/api/match/dto/match/CreateMatchRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.match; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import java.util.UUID; | ||
|
|
||
| public record CreateMatchRequest( | ||
| @NotNull UUID memberAId, | ||
| @NotNull UUID memberBId, | ||
| @NotNull Integer matchCycleId, | ||
| Double matchScore, | ||
| String status) {} |
6 changes: 6 additions & 0 deletions
6
src/main/java/org/patinanetwork/patchats/api/match/dto/match/MatchListQuery.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.match; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| public record MatchListQuery(UUID memberId, String period, Instant startTime, Instant endTime, String status) {} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/patinanetwork/patchats/api/match/dto/match/MatchResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.match; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.util.UUID; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.patinanetwork.patchats.api.match.db.models.Match; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @ToString | ||
| @EqualsAndHashCode | ||
| public class MatchResponse { | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final UUID matchId; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final UUID memberAId; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final UUID memberBId; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final String month; | ||
|
|
||
| @Schema(requiredMode = Schema.RequiredMode.REQUIRED) | ||
| private final String status; | ||
|
|
||
| public static MatchResponse from(final Match match, final String month) { | ||
| return MatchResponse.builder() | ||
| .matchId(match.getId()) | ||
| .memberAId(match.getMemberAId()) | ||
| .memberBId(match.getMemberBId()) | ||
| .month(month) | ||
| .status(match.getStatus()) | ||
| .build(); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/patinanetwork/patchats/api/match/dto/match/UpdateMatchFeedbackRequest.java
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets drop everything related to feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.match; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record UpdateMatchFeedbackRequest(@NotBlank String feedback) {} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/patinanetwork/patchats/api/match/dto/match/UpdateMatchStatusRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package org.patinanetwork.patchats.api.match.dto.match; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record UpdateMatchStatusRequest(@NotBlank String status) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ain/java/org/patinanetwork/patchats/common/web/exception/MatchCycleNotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.patinanetwork.patchats.common.web.exception; | ||
|
|
||
| public class MatchCycleNotFoundException extends RuntimeException { | ||
| public MatchCycleNotFoundException(Integer id) { | ||
| super("Match Cycle with ID " + id + " not found"); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/patinanetwork/patchats/common/web/exception/MatchNotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.patinanetwork.patchats.common.web.exception; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public class MatchNotFoundException extends RuntimeException { | ||
| public MatchNotFoundException(UUID id) { | ||
| super("Match with ID " + id + " not found"); | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
src/test/java/org/patinanetwork/patchats/api/match/AdminMatchControllerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package org.patinanetwork.patchats.api.match; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.patinanetwork.patchats.api.match.dto.match.AdminMatchResponse; | ||
| import org.patinanetwork.patchats.common.web.ApiExceptionHandler; | ||
| import org.patinanetwork.patchats.common.web.exception.MatchCycleNotFoundException; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.context.bean.override.mockito.MockitoBean; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| @WebMvcTest(AdminMatchController.class) | ||
| @AutoConfigureMockMvc(addFilters = false) | ||
| @Import(ApiExceptionHandler.class) | ||
| class AdminMatchControllerTest { | ||
|
|
||
| private static final String MEMBER_A_ID = "11111111-1111-1111-1111-111111111111"; | ||
| private static final String MEMBER_B_ID = "22222222-2222-2222-2222-222222222222"; | ||
| private static final String REQUEST_BODY = | ||
| "{\"memberAId\":\"%s\",\"memberBId\":\"%s\",\"matchCycleId\":1,\"matchScore\":0.85,\"status\":\"CONFIRMED\"}" | ||
| .formatted(MEMBER_A_ID, MEMBER_B_ID); | ||
|
|
||
| @Autowired | ||
| private MockMvc mockMvc; | ||
|
|
||
| @MockitoBean | ||
| private MatchService matchService; | ||
|
|
||
| @Test | ||
| void createMatch_ReturnsOkAndAdminMatchResponse() throws Exception { | ||
| when(matchService.createMatch(any())) | ||
| .thenReturn(AdminMatchResponse.builder() | ||
| .matchId(UUID.fromString("33333333-3333-3333-3333-333333333333")) | ||
| .memberAId(UUID.fromString(MEMBER_A_ID)) | ||
| .memberBId(UUID.fromString(MEMBER_B_ID)) | ||
| .matchCycleId(1) | ||
| .month("2026-07") | ||
| .status("CONFIRMED") | ||
| .matchScore(0.85) | ||
| .createdAt(Instant.parse("2026-07-15T10:00:00Z")) | ||
| .build()); | ||
|
|
||
| mockMvc.perform(post("/api/admin/matches") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(REQUEST_BODY)) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.success").value(true)) | ||
| .andExpect(jsonPath("$.payload.matchId").value("33333333-3333-3333-3333-333333333333")) | ||
| .andExpect(jsonPath("$.payload.memberAId").value(MEMBER_A_ID)) | ||
| .andExpect(jsonPath("$.payload.memberBId").value(MEMBER_B_ID)) | ||
| .andExpect(jsonPath("$.payload.matchCycleId").value(1)) | ||
| .andExpect(jsonPath("$.payload.month").value("2026-07")) | ||
| .andExpect(jsonPath("$.payload.status").value("CONFIRMED")) | ||
| .andExpect(jsonPath("$.payload.matchScore").value(0.85)) | ||
| .andExpect(jsonPath("$.payload.createdAt").isNotEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void createMatch_ReturnsBadRequestWhenMemberAIdMissing() throws Exception { | ||
| mockMvc.perform(post("/api/admin/matches") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content("{\"memberBId\":\"%s\",\"matchCycleId\":1}".formatted(MEMBER_B_ID))) | ||
| .andExpect(status().isBadRequest()) | ||
| .andExpect(jsonPath("$.success").value(false)); | ||
| } | ||
|
|
||
| @Test | ||
| void createMatch_ReturnsNotFoundWhenCycleMissing() throws Exception { | ||
| when(matchService.createMatch(any())).thenThrow(new MatchCycleNotFoundException(1)); | ||
|
|
||
| mockMvc.perform(post("/api/admin/matches") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(REQUEST_BODY)) | ||
| .andExpect(status().isNotFound()) | ||
| .andExpect(jsonPath("$.success").value(false)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets just stick with MatchController for everything, and then we can handle the permissioning after the fact, once Randy's done.