generated from UdL-EPS-SoftArch-Igualada/spring-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Feature/referee match assignment #42
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
Merged
pol-rivero
merged 14 commits into
UdL-EPS-SoftArch-Igualada:main
from
polMarsol:feature/referee-match-assignment
Mar 3, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
39c65e8
Fix: Team.java member limit validation and Creation: TeamTest.java an…
MartiFarranC c8cb886
feat: new test in TeamTest.java for 100% coverage
MartiFarranC a99620b
Merge branch 'UdL-EPS-SoftArch-Igualada:main' into main
polMarsol a76f84b
feat(match-assignment): add referee-to-match assignment with validati…
7379ebf
feat(match-assignment): implement referee assignment flow with lockin…
820a479
feat(match-assignment): enforce match time range and remove redundant…
79c775e
test(match-assignment): add cucumber coverage and harden validation v…
125fa8c
test(team): clarify assertThrows lambda to satisfy Sonar S5778
5119a3c
test(cucumber): fix auth/session usage and remove flaky ID/date assum…
9fd115e
feat(match-assignment): add referee assignment endpoint with validati…
4b66be0
Merge branch 'feature/referee-match-assignment' of github.com:polMars…
e275f5e
fix(merge): remove leftover demo package files and keep fll match ass…
3e11ba9
fix(match-assignment): align error contract, add locking, and restore…
727f4ca
fix(match-assignment): address review feedback (query clarity, status…
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/cat/udl/eps/softarch/fll/controller/MatchAssignmentController.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,33 @@ | ||
| package cat.udl.eps.softarch.fll.controller; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| 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; | ||
| import cat.udl.eps.softarch.fll.controller.dto.MatchAssignmentRequest; | ||
| import cat.udl.eps.softarch.fll.controller.dto.MatchAssignmentResponse; | ||
| import cat.udl.eps.softarch.fll.domain.Match; | ||
| import cat.udl.eps.softarch.fll.service.MatchAssignmentService; | ||
| import jakarta.validation.Valid; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/matchAssignments") | ||
| public class MatchAssignmentController { | ||
| private final MatchAssignmentService matchAssignmentService; | ||
|
|
||
| public MatchAssignmentController(MatchAssignmentService matchAssignmentService) { | ||
| this.matchAssignmentService = matchAssignmentService; | ||
| } | ||
|
|
||
| @PostMapping("/assign") | ||
| public ResponseEntity<MatchAssignmentResponse> assignReferee(@Valid @RequestBody MatchAssignmentRequest request) { | ||
| Match assignedMatch = matchAssignmentService.assignReferee(request.matchId(), request.refereeId()); | ||
| MatchAssignmentResponse response = new MatchAssignmentResponse( | ||
| String.valueOf(assignedMatch.getId()), | ||
| String.valueOf(assignedMatch.getReferee().getId()), | ||
| "ASSIGNED"); | ||
| return ResponseEntity.status(HttpStatus.OK).body(response); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/cat/udl/eps/softarch/fll/controller/dto/MatchAssignmentRequest.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,8 @@ | ||
| package cat.udl.eps.softarch.fll.controller.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record MatchAssignmentRequest( | ||
| @NotBlank String matchId, | ||
| @NotBlank String refereeId | ||
| ) {} |
7 changes: 7 additions & 0 deletions
7
src/main/java/cat/udl/eps/softarch/fll/controller/dto/MatchAssignmentResponse.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 cat.udl.eps.softarch.fll.controller.dto; | ||
|
|
||
| public record MatchAssignmentResponse( | ||
| String matchId, | ||
| String refereeId, | ||
| 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
src/main/java/cat/udl/eps/softarch/fll/domain/MatchState.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 cat.udl.eps.softarch.fll.domain; | ||
|
|
||
| public enum MatchState { | ||
| SCHEDULED, | ||
| IN_PROGRESS, | ||
| FINISHED | ||
| } |
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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/cat/udl/eps/softarch/fll/exception/MatchAssignmentErrorCode.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 cat.udl.eps.softarch.fll.exception; | ||
|
|
||
| public enum MatchAssignmentErrorCode { | ||
| MATCH_NOT_FOUND, | ||
| REFEREE_NOT_FOUND, | ||
| INVALID_ROLE, | ||
| AVAILABILITY_CONFLICT, | ||
| MATCH_ALREADY_HAS_REFEREE, | ||
| INVALID_MATCH_STATE, | ||
| INVALID_ID_FORMAT | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/cat/udl/eps/softarch/fll/exception/MatchAssignmentException.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,14 @@ | ||
| package cat.udl.eps.softarch.fll.exception; | ||
|
|
||
| public class MatchAssignmentException extends RuntimeException { | ||
| private final MatchAssignmentErrorCode errorCode; | ||
|
|
||
| public MatchAssignmentException(MatchAssignmentErrorCode errorCode, String message) { | ||
| super(message); | ||
| this.errorCode = errorCode; | ||
| } | ||
|
|
||
| public MatchAssignmentErrorCode getErrorCode() { | ||
| return errorCode; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/cat/udl/eps/softarch/fll/exception/MatchAssignmentExceptionHandler.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,23 @@ | ||
| package cat.udl.eps.softarch.fll.exception; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
|
||
| @RestControllerAdvice | ||
| public class MatchAssignmentExceptionHandler { | ||
|
|
||
| @ExceptionHandler(MatchAssignmentException.class) | ||
| public ResponseEntity<ErrorResponse> handleMatchAssignmentException(MatchAssignmentException ex) { | ||
| HttpStatus status = switch (ex.getErrorCode()) { | ||
| case MATCH_NOT_FOUND, REFEREE_NOT_FOUND -> HttpStatus.NOT_FOUND; | ||
| case AVAILABILITY_CONFLICT, MATCH_ALREADY_HAS_REFEREE -> HttpStatus.CONFLICT; | ||
| case INVALID_ROLE, INVALID_MATCH_STATE, INVALID_ID_FORMAT -> HttpStatus.UNPROCESSABLE_CONTENT; | ||
| }; | ||
| ErrorResponse body = new ErrorResponse(ex.getErrorCode().name(), ex.getMessage()); | ||
| return ResponseEntity.status(status).body(body); | ||
| } | ||
|
|
||
| public record ErrorResponse(String error, String message) {} | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/cat/udl/eps/softarch/fll/repository/MatchRepository.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 |
|---|---|---|
| @@ -1,12 +1,38 @@ | ||
| package cat.udl.eps.softarch.fll.repository; | ||
|
|
||
| import java.time.LocalTime; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.Lock; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.CrudRepository; | ||
| import org.springframework.data.repository.PagingAndSortingRepository; | ||
| import org.springframework.data.repository.query.Param; | ||
| import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
| import org.springframework.data.rest.core.annotation.RestResource; | ||
| import org.springframework.stereotype.Repository; | ||
| import cat.udl.eps.softarch.fll.domain.Match; | ||
| import cat.udl.eps.softarch.fll.domain.Referee; | ||
| import jakarta.persistence.LockModeType; | ||
|
|
||
| @Repository | ||
| @RepositoryRestResource | ||
| public interface MatchRepository extends CrudRepository<Match, Long>, PagingAndSortingRepository<Match, Long> { | ||
| @Query(""" | ||
| SELECT m FROM Match m | ||
| WHERE m.referee = :referee | ||
| AND m.startTime < :newMatchEndTime | ||
| AND m.endTime > :newMatchStartTime | ||
| AND m.id <> :currentMatchId | ||
| """) | ||
| List<Match> findOverlappingAssignments( | ||
| @Param("referee") Referee referee, | ||
| @Param("newMatchStartTime") LocalTime newMatchStartTime, | ||
| @Param("newMatchEndTime") LocalTime newMatchEndTime, | ||
| @Param("currentMatchId") Long currentMatchId); | ||
|
|
||
| @Lock(LockModeType.PESSIMISTIC_WRITE) | ||
| @Query("SELECT m FROM Match m WHERE m.id = :id") | ||
| @RestResource(exported = false) | ||
| Optional<Match> findByIdForUpdate(@Param("id") Long id); | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.