-
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
Changes from 4 commits
39c65e8
c8cb886
a99620b
a76f84b
7379ebf
820a479
79c775e
125fa8c
5119a3c
9fd115e
4b66be0
e275f5e
3e11ba9
727f4ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>4.0.1</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| <relativePath /> <!-- lookup parent from repository --> | ||
| </parent> | ||
| <groupId>cat.udl.eps.softarch</groupId> | ||
| <artifactId>spring-template</artifactId> | ||
|
|
@@ -50,13 +51,13 @@ | |
| <artifactId>spring-data-rest-hal-explorer</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-devtools</artifactId> | ||
| <scope>runtime</scope> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-devtools</artifactId> | ||
| <scope>runtime</scope> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.datatype</groupId> | ||
| <artifactId>jackson-datatype-jsr310</artifactId> | ||
| </dependency> | ||
|
|
@@ -77,7 +78,7 @@ | |
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <scope>provided</scope> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
|
|
@@ -89,24 +90,24 @@ | |
| <artifactId>spring-security-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.cucumber</groupId> | ||
| <artifactId>cucumber-junit-platform-engine</artifactId> | ||
| <version>7.19.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.platform</groupId> | ||
| <artifactId>junit-platform-suite-api</artifactId> | ||
| <version>6.0.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.cucumber</groupId> | ||
| <artifactId>cucumber-java</artifactId> | ||
| <version>7.19.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.cucumber</groupId> | ||
| <artifactId>cucumber-junit-platform-engine</artifactId> | ||
| <version>7.19.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.platform</groupId> | ||
| <artifactId>junit-platform-suite-api</artifactId> | ||
| <version>6.0.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.cucumber</groupId> | ||
| <artifactId>cucumber-java</artifactId> | ||
| <version>7.19.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.cucumber</groupId> | ||
| <artifactId>cucumber-spring</artifactId> | ||
|
|
@@ -118,36 +119,43 @@ | |
| <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | ||
| <version>3.0.1</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
||
|
|
||
pol-rivero marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>3.2.5</version> | ||
| <configuration> | ||
| <useModulePath>false</useModulePath> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.14.0</version> | ||
| <configuration> | ||
| <annotationProcessorPaths> | ||
| <path> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>1.18.34</version> | ||
| </path> | ||
| </annotationProcessorPaths> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>3.2.5</version> | ||
| <configuration> | ||
| <useModulePath>false</useModulePath> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.14.0</version> | ||
| <configuration> | ||
| <annotationProcessorPaths> | ||
| <path> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>1.18.34</version> | ||
| </path> | ||
| </annotationProcessorPaths> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-checkstyle-plugin</artifactId> | ||
|
|
@@ -178,4 +186,4 @@ | |
| </plugins> | ||
| </build> | ||
|
|
||
| </project> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package cat.udl.eps.softarch.demo.api.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record AssignRefereeRequest( | ||
| @NotBlank(message = "matchId is mandatory") String matchId, | ||
| @NotBlank(message = "refereeId is mandatory") String refereeId) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package cat.udl.eps.softarch.demo.api.dto; | ||
|
|
||
| public record AssignRefereeResponse(String matchId, String refereeId, String status) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package cat.udl.eps.softarch.demo.api.dto; | ||
|
|
||
| public record AssignmentErrorResponse(String error, String message) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package cat.udl.eps.softarch.demo.controller; | ||
|
|
||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import cat.udl.eps.softarch.demo.api.dto.AssignRefereeRequest; | ||
| import cat.udl.eps.softarch.demo.api.dto.AssignRefereeResponse; | ||
| import cat.udl.eps.softarch.demo.service.MatchAssignmentService; | ||
| import jakarta.validation.Valid; | ||
|
|
||
| @Validated | ||
| @RestController | ||
| public class MatchAssignmentController { | ||
|
|
||
| private final MatchAssignmentService matchAssignmentService; | ||
|
|
||
| public MatchAssignmentController(MatchAssignmentService matchAssignmentService) { | ||
| this.matchAssignmentService = matchAssignmentService; | ||
| } | ||
|
|
||
| @PostMapping("/match-assignments") | ||
| @PreAuthorize("isAuthenticated()") | ||
| public AssignRefereeResponse assignReferee(@Valid @RequestBody AssignRefereeRequest request) { | ||
| return matchAssignmentService.assignReferee(request.matchId(), request.refereeId()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package cat.udl.eps.softarch.demo.domain; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Entity | ||
| @Table(name = "competition_match") | ||
| @Getter | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Setter | ||
| @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) | ||
| public class Match extends UriEntity<Long> { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @EqualsAndHashCode.Include | ||
| private Long id; | ||
pol-rivero marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @NotNull | ||
| @Column(nullable = false) | ||
| private LocalDateTime startTime; | ||
|
|
||
| @NotNull | ||
| @Column(nullable = false) | ||
| private LocalDateTime endTime; | ||
|
|
||
| @NotNull | ||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| private MatchState state; | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "referee_id") | ||
| private Referee referee; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package cat.udl.eps.softarch.demo.domain; | ||
|
|
||
| public enum MatchState { | ||
| SCHEDULED, | ||
| FINISHED | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package cat.udl.eps.softarch.demo.domain; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Table; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Entity | ||
| @Table(name = "referees") | ||
| @Getter | ||
| @Setter | ||
| @EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) | ||
| public class Referee extends Volunteer { | ||
| } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -70,6 +70,7 @@ public String getId() { | |||
|
|
||||
| @OneToMany(mappedBy = "team", cascade = CascadeType.ALL, orphanRemoval = true) | ||||
| @ToString.Exclude | ||||
| @Size(max = 10, message = "A team cannot have more than 10 members") | ||||
|
||||
| @Size(max = 10, message = "A team cannot have more than 10 members") |
pol-rivero marked this conversation as resolved.
Show resolved
Hide resolved
pol-rivero marked this conversation as resolved.
Show resolved
Hide resolved
pol-rivero marked this conversation as resolved.
Show resolved
Hide resolved
pol-rivero marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package cat.udl.eps.softarch.demo.exception; | ||
|
|
||
| public enum AssignmentErrorCode { | ||
| MATCH_NOT_FOUND, | ||
| REFEREE_NOT_FOUND, | ||
| INVALID_ROLE, | ||
| AVAILABILITY_CONFLICT, | ||
| MATCH_ALREADY_HAS_REFEREE, | ||
| INVALID_MATCH_STATE, | ||
| INVALID_ID_FORMAT | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package cat.udl.eps.softarch.demo.exception; | ||
|
|
||
| public class AssignmentValidationException extends RuntimeException { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private final AssignmentErrorCode errorCode; | ||
|
|
||
| public AssignmentValidationException(AssignmentErrorCode errorCode, String message) { | ||
| super(message); | ||
| this.errorCode = errorCode; | ||
| } | ||
|
|
||
| public AssignmentErrorCode getErrorCode() { | ||
| return errorCode; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| package cat.udl.eps.softarch.demo.exception; | ||||||
|
|
||||||
| import org.springframework.dao.CannotAcquireLockException; | ||||||
| import org.springframework.dao.OptimisticLockingFailureException; | ||||||
| import org.springframework.dao.PessimisticLockingFailureException; | ||||||
| import org.springframework.http.HttpStatus; | ||||||
| import org.springframework.http.ResponseEntity; | ||||||
| import org.springframework.web.bind.MethodArgumentNotValidException; | ||||||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||||||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||||||
| import cat.udl.eps.softarch.demo.api.dto.AssignmentErrorResponse; | ||||||
| import cat.udl.eps.softarch.demo.controller.MatchAssignmentController; | ||||||
|
|
||||||
| @RestControllerAdvice(assignableTypes = MatchAssignmentController.class) | ||||||
| public class MatchAssignmentExceptionHandler { | ||||||
|
|
||||||
| @ExceptionHandler(AssignmentValidationException.class) | ||||||
| public ResponseEntity<AssignmentErrorResponse> handleAssignmentValidationException( | ||||||
| AssignmentValidationException exception) { | ||||||
| HttpStatus status = mapStatus(exception.getErrorCode()); | ||||||
| AssignmentErrorResponse response = new AssignmentErrorResponse( | ||||||
| exception.getErrorCode().name(), | ||||||
| exception.getMessage()); | ||||||
| return ResponseEntity.status(status).body(response); | ||||||
| } | ||||||
|
|
||||||
| @ExceptionHandler(MethodArgumentNotValidException.class) | ||||||
| public ResponseEntity<AssignmentErrorResponse> handleMethodArgumentNotValidException( | ||||||
| MethodArgumentNotValidException exception) { | ||||||
| String message = exception.getBindingResult().getFieldErrors().stream() | ||||||
| .findFirst() | ||||||
| .map(error -> error.getDefaultMessage()) | ||||||
| .orElse("Invalid request payload"); | ||||||
| AssignmentErrorResponse response = new AssignmentErrorResponse( | ||||||
| AssignmentErrorCode.INVALID_ID_FORMAT.name(), | ||||||
|
||||||
| AssignmentErrorCode.INVALID_ID_FORMAT.name(), | |
| "INVALID_REQUEST", |
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.
According to the custom coding guidelines, modifications to project dependencies are disallowed. The addition of the
junit-jupiter-apidependency violates this guideline. This dependency should already be available throughspring-boot-starter-test.