Skip to content

Commit a0f108a

Browse files
authored
Merge pull request #42 from polMarsol/feature/referee-match-assignment
Feature/referee match assignment
2 parents 9a84a84 + 727f4ca commit a0f108a

20 files changed

+874
-52
lines changed

pom.xml

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
45
<modelVersion>4.0.0</modelVersion>
56
<parent>
67
<groupId>org.springframework.boot</groupId>
78
<artifactId>spring-boot-starter-parent</artifactId>
89
<version>4.0.1</version>
9-
<relativePath/> <!-- lookup parent from repository -->
10+
<relativePath /> <!-- lookup parent from repository -->
1011
</parent>
1112
<groupId>cat.udl.eps.softarch</groupId>
1213
<artifactId>spring-template</artifactId>
@@ -50,13 +51,13 @@
5051
<artifactId>spring-data-rest-hal-explorer</artifactId>
5152
</dependency>
5253

53-
<dependency>
54-
<groupId>org.springframework.boot</groupId>
55-
<artifactId>spring-boot-devtools</artifactId>
56-
<scope>runtime</scope>
57-
<optional>true</optional>
58-
</dependency>
59-
<dependency>
54+
<dependency>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-devtools</artifactId>
57+
<scope>runtime</scope>
58+
<optional>true</optional>
59+
</dependency>
60+
<dependency>
6061
<groupId>com.fasterxml.jackson.datatype</groupId>
6162
<artifactId>jackson-datatype-jsr310</artifactId>
6263
</dependency>
@@ -77,7 +78,7 @@
7778
<dependency>
7879
<groupId>org.projectlombok</groupId>
7980
<artifactId>lombok</artifactId>
80-
<scope>provided</scope>
81+
<scope>provided</scope>
8182
</dependency>
8283
<dependency>
8384
<groupId>org.springframework.boot</groupId>
@@ -89,24 +90,24 @@
8990
<artifactId>spring-security-test</artifactId>
9091
<scope>test</scope>
9192
</dependency>
92-
<dependency>
93-
<groupId>io.cucumber</groupId>
94-
<artifactId>cucumber-junit-platform-engine</artifactId>
95-
<version>7.19.0</version>
96-
<scope>test</scope>
97-
</dependency>
98-
<dependency>
99-
<groupId>org.junit.platform</groupId>
100-
<artifactId>junit-platform-suite-api</artifactId>
101-
<version>6.0.1</version>
102-
<scope>test</scope>
103-
</dependency>
104-
<dependency>
105-
<groupId>io.cucumber</groupId>
106-
<artifactId>cucumber-java</artifactId>
107-
<version>7.19.0</version>
108-
<scope>test</scope>
109-
</dependency>
93+
<dependency>
94+
<groupId>io.cucumber</groupId>
95+
<artifactId>cucumber-junit-platform-engine</artifactId>
96+
<version>7.19.0</version>
97+
<scope>test</scope>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.junit.platform</groupId>
101+
<artifactId>junit-platform-suite-api</artifactId>
102+
<version>6.0.1</version>
103+
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>io.cucumber</groupId>
107+
<artifactId>cucumber-java</artifactId>
108+
<version>7.19.0</version>
109+
<scope>test</scope>
110+
</dependency>
110111
<dependency>
111112
<groupId>io.cucumber</groupId>
112113
<artifactId>cucumber-spring</artifactId>
@@ -118,36 +119,37 @@
118119
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
119120
<version>3.0.1</version>
120121
</dependency>
121-
</dependencies>
122+
123+
</dependencies>
122124

123125
<build>
124126
<plugins>
125127
<plugin>
126128
<groupId>org.springframework.boot</groupId>
127129
<artifactId>spring-boot-maven-plugin</artifactId>
128130
</plugin>
129-
<plugin>
130-
<groupId>org.apache.maven.plugins</groupId>
131-
<artifactId>maven-surefire-plugin</artifactId>
132-
<version>3.2.5</version>
133-
<configuration>
134-
<useModulePath>false</useModulePath>
135-
</configuration>
136-
</plugin>
137-
<plugin>
138-
<groupId>org.apache.maven.plugins</groupId>
139-
<artifactId>maven-compiler-plugin</artifactId>
140-
<version>3.14.0</version>
141-
<configuration>
142-
<annotationProcessorPaths>
143-
<path>
144-
<groupId>org.projectlombok</groupId>
145-
<artifactId>lombok</artifactId>
146-
<version>1.18.34</version>
147-
</path>
148-
</annotationProcessorPaths>
149-
</configuration>
150-
</plugin>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-surefire-plugin</artifactId>
134+
<version>3.2.5</version>
135+
<configuration>
136+
<useModulePath>false</useModulePath>
137+
</configuration>
138+
</plugin>
139+
<plugin>
140+
<groupId>org.apache.maven.plugins</groupId>
141+
<artifactId>maven-compiler-plugin</artifactId>
142+
<version>3.14.0</version>
143+
<configuration>
144+
<annotationProcessorPaths>
145+
<path>
146+
<groupId>org.projectlombok</groupId>
147+
<artifactId>lombok</artifactId>
148+
<version>1.18.34</version>
149+
</path>
150+
</annotationProcessorPaths>
151+
</configuration>
152+
</plugin>
151153
<plugin>
152154
<groupId>org.apache.maven.plugins</groupId>
153155
<artifactId>maven-checkstyle-plugin</artifactId>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cat.udl.eps.softarch.fll.controller;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.PostMapping;
6+
import org.springframework.web.bind.annotation.RequestBody;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
import cat.udl.eps.softarch.fll.controller.dto.MatchAssignmentRequest;
10+
import cat.udl.eps.softarch.fll.controller.dto.MatchAssignmentResponse;
11+
import cat.udl.eps.softarch.fll.domain.Match;
12+
import cat.udl.eps.softarch.fll.service.MatchAssignmentService;
13+
import jakarta.validation.Valid;
14+
15+
@RestController
16+
@RequestMapping("/matchAssignments")
17+
public class MatchAssignmentController {
18+
private final MatchAssignmentService matchAssignmentService;
19+
20+
public MatchAssignmentController(MatchAssignmentService matchAssignmentService) {
21+
this.matchAssignmentService = matchAssignmentService;
22+
}
23+
24+
@PostMapping("/assign")
25+
public ResponseEntity<MatchAssignmentResponse> assignReferee(@Valid @RequestBody MatchAssignmentRequest request) {
26+
Match assignedMatch = matchAssignmentService.assignReferee(request.matchId(), request.refereeId());
27+
MatchAssignmentResponse response = new MatchAssignmentResponse(
28+
String.valueOf(assignedMatch.getId()),
29+
String.valueOf(assignedMatch.getReferee().getId()),
30+
"ASSIGNED");
31+
return ResponseEntity.status(HttpStatus.OK).body(response);
32+
}
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cat.udl.eps.softarch.fll.controller.dto;
2+
3+
import jakarta.validation.constraints.NotBlank;
4+
5+
public record MatchAssignmentRequest(
6+
@NotBlank String matchId,
7+
@NotBlank String refereeId
8+
) {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cat.udl.eps.softarch.fll.controller.dto;
2+
3+
public record MatchAssignmentResponse(
4+
String matchId,
5+
String refereeId,
6+
String status
7+
) {}

src/main/java/cat/udl/eps/softarch/fll/domain/Match.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.time.LocalTime;
44
import com.fasterxml.jackson.annotation.JsonBackReference;
55
import jakarta.persistence.Entity;
6+
import jakarta.persistence.EnumType;
7+
import jakarta.persistence.Enumerated;
68
import jakarta.persistence.FetchType;
79
import jakarta.persistence.GeneratedValue;
810
import jakarta.persistence.GenerationType;
@@ -33,6 +35,13 @@ public class Match extends UriEntity<Long> {
3335
@JoinColumn(name = "table_id")
3436
private CompetitionTable competitionTable;
3537

38+
@ManyToOne(fetch = FetchType.LAZY)
39+
@JoinColumn(name = "referee_id")
40+
private Referee referee;
41+
42+
@Enumerated(EnumType.STRING)
43+
private MatchState state = MatchState.SCHEDULED;
44+
3645
public Match() {}
3746

3847
@Override
@@ -75,4 +84,20 @@ public CompetitionTable getCompetitionTable() {
7584
public void setCompetitionTable(CompetitionTable competitionTable) {
7685
this.competitionTable = competitionTable;
7786
}
87+
88+
public Referee getReferee() {
89+
return referee;
90+
}
91+
92+
public void setReferee(Referee referee) {
93+
this.referee = referee;
94+
}
95+
96+
public MatchState getState() {
97+
return state;
98+
}
99+
100+
public void setState(MatchState state) {
101+
this.state = state;
102+
}
78103
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cat.udl.eps.softarch.fll.domain;
2+
3+
public enum MatchState {
4+
SCHEDULED,
5+
IN_PROGRESS,
6+
FINISHED
7+
}

src/main/java/cat/udl/eps/softarch/fll/domain/ScientificProject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@Getter
1414
@Setter
1515
@ToString
16-
@EqualsAndHashCode(of = "id")
16+
@EqualsAndHashCode(of = "id", callSuper = false)
1717
public class ScientificProject extends UriEntity<Long> {
1818

1919
@Id

src/main/java/cat/udl/eps/softarch/fll/domain/Team.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public String getId() {
6969
private LocalDate inscriptionDate;
7070

7171
@OneToMany(mappedBy = "team", cascade = CascadeType.ALL, orphanRemoval = true)
72+
@Size(max = 10, message = "A team cannot have more than 10 members")
7273
@ToString.Exclude
7374
private List<TeamMember> members = new ArrayList<>();
7475

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cat.udl.eps.softarch.fll.exception;
2+
3+
public enum MatchAssignmentErrorCode {
4+
MATCH_NOT_FOUND,
5+
REFEREE_NOT_FOUND,
6+
INVALID_ROLE,
7+
AVAILABILITY_CONFLICT,
8+
MATCH_ALREADY_HAS_REFEREE,
9+
INVALID_MATCH_STATE,
10+
INVALID_ID_FORMAT
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cat.udl.eps.softarch.fll.exception;
2+
3+
public class MatchAssignmentException extends RuntimeException {
4+
private final MatchAssignmentErrorCode errorCode;
5+
6+
public MatchAssignmentException(MatchAssignmentErrorCode errorCode, String message) {
7+
super(message);
8+
this.errorCode = errorCode;
9+
}
10+
11+
public MatchAssignmentErrorCode getErrorCode() {
12+
return errorCode;
13+
}
14+
}

0 commit comments

Comments
 (0)