diff --git a/.idea/.gitignore b/.idea/.gitignore index 5cfb252fb22a7d805d47bc013faa93e5b3fd263b..13566b81b018ad684f3a35fee301741b2734c8f4 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -6,16 +6,3 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml - -.idea -*.iws -*.iml -*.ipr -/codeStyles/codeStyleConfig.xml -/compiler.xml -/jarRepositories.xml -/encodings.xml -/misc.xml -/modules.xml -/uiDesigner.xml -/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..dbb096cd6d54e582fa1f05a952f900aff209bf72 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" project-jdk-name="20" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..f22b0514c88c9e7d3cb3185d592709fa11428d53 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/student-tournament-hub.iml" filepath="$PROJECT_DIR$/.idea/student-tournament-hub.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/1/5/15d493c652d20750608adb0a33ec5d3ad17ece3d b/.idea/sonarlint/issuestore/1/5/15d493c652d20750608adb0a33ec5d3ad17ece3d new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/8/1/81d8eb2bc5a911b258c49bed79926844ea3988f0 b/.idea/sonarlint/issuestore/8/1/81d8eb2bc5a911b258c49bed79926844ea3988f0 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d b/.idea/sonarlint/issuestore/8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/a/d/ad9815cb514700b7f513e4aad039536e258c58d9 b/.idea/sonarlint/issuestore/a/d/ad9815cb514700b7f513e4aad039536e258c58d9 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/d/4/d4d373a247368212c60cc99595abbf323611ed8f b/.idea/sonarlint/issuestore/d/4/d4d373a247368212c60cc99595abbf323611ed8f new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/e/f/ef8def03dc8f162799089e9b5f4321201c8810d5 b/.idea/sonarlint/issuestore/e/f/ef8def03dc8f162799089e9b5f4321201c8810d5 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/f/7/f764c0a37a5c9f7a04bea4edf778d74fc41a085c b/.idea/sonarlint/issuestore/f/7/f764c0a37a5c9f7a04bea4edf778d74fc41a085c new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/f/f/ffa88f39108e02aca02fbfcfdefda86d60005743 b/.idea/sonarlint/issuestore/f/f/ffa88f39108e02aca02fbfcfdefda86d60005743 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000000000000000000000000000000000000..709b569b73e4ff515d56973c80bb33eb1facd1f4 --- /dev/null +++ b/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,17 @@ + +9 + README.md,8\e\8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d +I +tournament-factory-adr.md,8\1\81d8eb2bc5a911b258c49bed79926844ea3988f0 +C +docker-compose.yaml,e\f\ef8def03dc8f162799089e9b5f4321201c8810d5 +F +sth-backend/Dockerfile,a\d\ad9815cb514700b7f513e4aad039536e258c58d9 +@ +sth-backend/mvnw,f\7\f764c0a37a5c9f7a04bea4edf778d74fc41a085c +C +sth-backend/pom.xml,f\f\ffa88f39108e02aca02fbfcfdefda86d60005743 +m +=sth-backend/src/main/java/hdm/mi/sthbackend/model/IMatch.java,1\5\15d493c652d20750608adb0a33ec5d3ad17ece3d +r +Bsth-backend/src/main/java/hdm/mi/sthbackend/model/ITournament.java,d\4\d4d373a247368212c60cc99595abbf323611ed8f \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/1/5/15d493c652d20750608adb0a33ec5d3ad17ece3d b/.idea/sonarlint/securityhotspotstore/1/5/15d493c652d20750608adb0a33ec5d3ad17ece3d new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/8/1/81d8eb2bc5a911b258c49bed79926844ea3988f0 b/.idea/sonarlint/securityhotspotstore/8/1/81d8eb2bc5a911b258c49bed79926844ea3988f0 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d b/.idea/sonarlint/securityhotspotstore/8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/a/d/ad9815cb514700b7f513e4aad039536e258c58d9 b/.idea/sonarlint/securityhotspotstore/a/d/ad9815cb514700b7f513e4aad039536e258c58d9 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/d/4/d4d373a247368212c60cc99595abbf323611ed8f b/.idea/sonarlint/securityhotspotstore/d/4/d4d373a247368212c60cc99595abbf323611ed8f new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/e/f/ef8def03dc8f162799089e9b5f4321201c8810d5 b/.idea/sonarlint/securityhotspotstore/e/f/ef8def03dc8f162799089e9b5f4321201c8810d5 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/f/7/f764c0a37a5c9f7a04bea4edf778d74fc41a085c b/.idea/sonarlint/securityhotspotstore/f/7/f764c0a37a5c9f7a04bea4edf778d74fc41a085c new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/f/f/ffa88f39108e02aca02fbfcfdefda86d60005743 b/.idea/sonarlint/securityhotspotstore/f/f/ffa88f39108e02aca02fbfcfdefda86d60005743 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000000000000000000000000000000000000..709b569b73e4ff515d56973c80bb33eb1facd1f4 --- /dev/null +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -0,0 +1,17 @@ + +9 + README.md,8\e\8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d +I +tournament-factory-adr.md,8\1\81d8eb2bc5a911b258c49bed79926844ea3988f0 +C +docker-compose.yaml,e\f\ef8def03dc8f162799089e9b5f4321201c8810d5 +F +sth-backend/Dockerfile,a\d\ad9815cb514700b7f513e4aad039536e258c58d9 +@ +sth-backend/mvnw,f\7\f764c0a37a5c9f7a04bea4edf778d74fc41a085c +C +sth-backend/pom.xml,f\f\ffa88f39108e02aca02fbfcfdefda86d60005743 +m +=sth-backend/src/main/java/hdm/mi/sthbackend/model/IMatch.java,1\5\15d493c652d20750608adb0a33ec5d3ad17ece3d +r +Bsth-backend/src/main/java/hdm/mi/sthbackend/model/ITournament.java,d\4\d4d373a247368212c60cc99595abbf323611ed8f \ No newline at end of file diff --git a/.idea/student-tournament-hub.iml b/.idea/student-tournament-hub.iml new file mode 100644 index 0000000000000000000000000000000000000000..ad374d022aed5c40a4269d539eab810e124ec75c --- /dev/null +++ b/.idea/student-tournament-hub.iml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> + <component name="SonarLintModuleSettings"> + <option name="uniqueId" value="496df6ed-8d28-4ba0-bd76-20bf08cf48f0" /> + </component> +</module> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index b08e00ab0478c8879e44320c4feb5071b487eae8..4bc8da635b628ba84803ac1ba30a73e2e5c5997e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,31 +1,30 @@ version: '3' services: - frontend: - build: - context: ./sth-frontend - develop: - watch: - - action: sync - path: ./sth-frontend/src - target: /app/src - ports: - - "3000:3000" - backend: - build: - context: ./sth-backend - develop: - watch: - - action: sync - path: ./sth-backend/src - target: /apps/src - ports: - - "8080:8080" + # frontend: + # build: + # context: ./sth-frontend + # develop: + # watch: + # - action: sync + # path: ./sth-frontend/src + # target: /app/src + # ports: + # - "3000:3000" + # backend: + # build: + # context: ./sth-backend + # develop: + # watch: + # - action: sync + # path: ./sth-backend/src + # target: /apps/src + # ports: + # - "8080:8080" db: image: mongo:latest environment: - MONGO_INITDB_DATABASE: event-planner MONGO_INITDB_ROOT_USERNAME: alhb MONGO_INITDB_ROOT_PASSWORD: asdasd123 ports: - - "27017:27017" + - 27018:27017 diff --git a/sth-backend/pom.xml b/sth-backend/pom.xml index e3916aa957f216685bfc000d37acc33635e8ffa6..18c77c9ea9cf0c8259571608b1266915f5f3a305 100644 --- a/sth-backend/pom.xml +++ b/sth-backend/pom.xml @@ -17,10 +17,6 @@ <java.version>21</java.version> </properties> <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> @@ -34,11 +30,6 @@ <artifactId>lombok</artifactId> <optional>true</optional> </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> @@ -68,6 +59,7 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> + <version>3.2.0</version> </dependency> </dependencies> diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/SthBackendApplication.java b/sth-backend/src/main/java/hdm/mi/sthbackend/SthBackendApplication.java index 2374fcdfe662f3db9a39152b19943628022ce3cd..06da9bdb8086e43ef06f6638fd98048e1d696fcf 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/SthBackendApplication.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/SthBackendApplication.java @@ -1,20 +1,22 @@ package hdm.mi.sthbackend; +import hdm.mi.sthbackend.repository.ITournamentRepository; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.logging.Logger; @SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class}) -@RestController +@EnableMongoRepositories public class SthBackendApplication { - @GetMapping("/") - public String index() { - return "Hello World"; - } + @Autowired + ITournamentRepository tournamentRepository; + public static void main(String[] args) { SpringApplication.run(SthBackendApplication.class, args); diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java b/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java new file mode 100644 index 0000000000000000000000000000000000000000..074bd869fa57ed69e10a13f9b6d0fdc485867c0a --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java @@ -0,0 +1,65 @@ +package hdm.mi.sthbackend.controller; + + +import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException; +import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; +import hdm.mi.sthbackend.model.Player; +import hdm.mi.sthbackend.model.Team; +import hdm.mi.sthbackend.model.Tournament; +import hdm.mi.sthbackend.service.TournamentService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.UUID; + +@RestController +@RequestMapping("/api/v1/tournaments") +@AllArgsConstructor +public class TournamentController { + + private final TournamentService service; + + /** + * Player Endpoints + **/ + @PatchMapping("/{tournamentId}/teams/{teamId}/players/{playerId}") + public UUID updatePlayerName(@PathVariable UUID tournamentId, + @PathVariable UUID teamId, + @PathVariable UUID playerId, + @RequestBody String newPlayerName) throws Exception { + return service.updatePlayerName(tournamentId, teamId, playerId, newPlayerName); + } + + /** + * Team Endpoints + **/ + @PostMapping("/{tournamentId}/teams") + public Team createTeam(@PathVariable UUID tournamentId, + @RequestBody String teamName) throws TournamentIdNotFoundException { + return service.createTeam(tournamentId, teamName); + } + + @PostMapping("/{tournamentId}/teams/{teamId}/addPlayer") + public Player addPlayerToTeam(@PathVariable UUID tournamentId, + @PathVariable UUID teamId, + @RequestBody String playerName) throws Exception { + return service.addPlayerToTeam(tournamentId, teamId, playerName); + } + + @DeleteMapping("/{tournamentId}/teams/{teamId}/players/{playerId}") + public Player removePlayerFromTeam(@PathVariable UUID tournamentId, + @PathVariable UUID teamId, + @PathVariable UUID playerId) throws PlayerIdNotFoundException, TournamentIdNotFoundException { + return service.removePlayerFromTeam(tournamentId, teamId, playerId); + } + + + /** + * Tournament Endpoints + */ + @PostMapping + public Tournament createTournament(@RequestBody String tournamentName) { + return service.createTournament(tournamentName); + } + +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/PlayerIdNotFoundException.java b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/PlayerIdNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..8f4ae1099eba09406b1d2fe756b838a0ee4d39f5 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/PlayerIdNotFoundException.java @@ -0,0 +1,9 @@ +package hdm.mi.sthbackend.exeptions; + +import java.util.UUID; + +public class PlayerIdNotFoundException extends Exception { + public PlayerIdNotFoundException (UUID playerId) { + super(String.format("PlayerId %s not found", playerId.toString())); + } +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/TeamMatchScoreIdNotFoundException.java b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/TeamMatchScoreIdNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..d00a7668e4100c345de3764cd046cceafcb4e3f8 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/TeamMatchScoreIdNotFoundException.java @@ -0,0 +1,7 @@ +package hdm.mi.sthbackend.exeptions; + +public class TeamMatchScoreIdNotFoundException extends Exception{ + public TeamMatchScoreIdNotFoundException(String message) { + super(message); + } +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/TournamentIdNotFoundException.java b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/TournamentIdNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..85f5a24b84698a77cb8d7b084bf56aa2478730dc --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/TournamentIdNotFoundException.java @@ -0,0 +1,10 @@ +package hdm.mi.sthbackend.exeptions; + +import java.util.UUID; + +public class TournamentIdNotFoundException extends Exception{ + public TournamentIdNotFoundException(UUID tournamentId) { + super(String.format("TournamentId %s not found", tournamentId.toString())); + + } +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java index 467639b5db65b94b1eb297bfec486e642c546845..f613efec076edb7d764385d7f36ea8fc890fd1a8 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java @@ -1,33 +1,54 @@ package hdm.mi.sthbackend.model; -import org.hibernate.id.uuid.UuidGenerator; +import hdm.mi.sthbackend.exeptions.TeamMatchScoreIdNotFoundException; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; import java.util.List; +import java.util.Objects; import java.util.UUID; +@Getter +@Document("Match") +@AllArgsConstructor public class Match { - private String matchId; - private List<TeamMatchScore> teams; + private static final Logger log = LogManager.getLogger(Match.class); + @Id + private UUID matchId; + private List<TeamMatchScore> teamScores; + + @Setter private Team winner; + @Setter private String comment; + @Setter private Match nextMatch; - public Match(String matchId, List<TeamMatchScore> teams, Team winner, String comment, Match nextMatch) { - this.matchId = matchId; - this.teams = teams; - this.winner = winner; - this.comment = comment; - this.nextMatch = nextMatch; + + public void removeTeam(UUID teamMatchScoreId) throws Exception { + TeamMatchScore team = teamScores.stream().filter(t -> t.getTeamMatchScoreId().equals(teamMatchScoreId)).findFirst().orElse(null); + log.debug("removeTeam: " + team); + if (team == null) { + throw new TeamMatchScoreIdNotFoundException(String.format("TeamMatchScoreID %s was not found", teamMatchScoreId)); + } + teamScores.remove(team); } - public Match(String matchId, List<TeamMatchScore> teams, Team winner, Match nextMatch) { - this(matchId, teams, winner, "", nextMatch); + public void removeTeam(TeamMatchScore team) { + teamScores.remove(team); } - public void addTeam(Team team) { - teams.add(new TeamMatchScore( team, 0)); + public TeamMatchScore[] getAllTeams() { + return (TeamMatchScore[]) teamScores.stream().filter(Objects::nonNull).toArray(); } + } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Player.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Player.java index c7e8c3e0cd04698bb7350f359372dcbe387dc642..ca124371f0686e555a38a8f95342f88c11dd070b 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Player.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Player.java @@ -1,17 +1,19 @@ package hdm.mi.sthbackend.model; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; import java.util.UUID; @Getter +@Document("Player") +@AllArgsConstructor public class Player { + @Id private final UUID playerId; - private final String name; - - public Player(String name) { - this.playerId = UUID.randomUUID(); - this.name = name; - } - + @Setter + private String name; } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java index b6563d548b6eec7884fc7b0e5321f82a16127d56..f03a287a938637ecf3149c5b1edf90425a67fe1b 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java @@ -1,9 +1,20 @@ package hdm.mi.sthbackend.model; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + import java.util.List; +import java.util.UUID; +@Getter +@Document("Team") +@AllArgsConstructor public class Team { - private String teamId; - private List<Player> teamMembers; + @Id + private final UUID id; + private final String teamName; + private final List<Player> teamMembers; } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/TeamMatchScore.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/TeamMatchScore.java index fde8ebd629951693c073399490abc912aad570be..ee9213c4d0d3657ed173052b778d83987c79ef87 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/TeamMatchScore.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/TeamMatchScore.java @@ -1,16 +1,25 @@ package hdm.mi.sthbackend.model; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + import java.util.UUID; +@Getter +@Document("TeamMatchScore") +@AllArgsConstructor public class TeamMatchScore { - private UUID teamMatchScoreId; - private Team team; - private int score; + private static final Logger log = LogManager.getLogger(TeamMatchScore.class); - public TeamMatchScore(Team team, int score) { - this.teamMatchScoreId = UUID.randomUUID(); - this.team = team; - this.score = score; - } + @Id + private final UUID teamMatchScoreId; + private final UUID teamId; + @Setter + private int score; } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java index ab1860befe34449e1392a9f427b289510a6a278d..4d454729e662c2b7b302394666493278b8b7d813 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java @@ -1,9 +1,24 @@ package hdm.mi.sthbackend.model; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + import java.util.List; +import java.util.Map; +import java.util.UUID; +@Document("Tournament") +@Getter +@AllArgsConstructor public class Tournament implements ITournament{ - private String tournamentId; + @Id + private UUID tournamentId; + + private String tournamentName; private List<Match> matches; + + private Map<UUID, Team> teams; } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/ITournamentRepository.java b/sth-backend/src/main/java/hdm/mi/sthbackend/repository/ITournamentRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..82c2ea2c87902ba941dd64d59de5914d6e225d5c --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/repository/ITournamentRepository.java @@ -0,0 +1,12 @@ +package hdm.mi.sthbackend.repository; + +import hdm.mi.sthbackend.model.Tournament; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository +public interface ITournamentRepository extends MongoRepository<Tournament, UUID> { + +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/MongoManager.java b/sth-backend/src/main/java/hdm/mi/sthbackend/repository/MongoManager.java new file mode 100644 index 0000000000000000000000000000000000000000..86687ec56843ea0ff11487dd0b23c3959726ad12 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/repository/MongoManager.java @@ -0,0 +1,25 @@ +package hdm.mi.sthbackend.repository; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import lombok.AllArgsConstructor; +import org.bson.Document; + +@AllArgsConstructor +public class MongoManager { + + public MongoClient getMongoClient(){ + return MongoClients.create("mongodb://alhb:asdasd123@localhost:27018"); + } + + public MongoCollection<Document> getTestCollection(MongoClient client){ + MongoDatabase database = client.getDatabase("tournament-hub"); + return database.getCollection("tournaments"); + } + + + + +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java b/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java new file mode 100644 index 0000000000000000000000000000000000000000..f75b5466f0cd846b44e64d2d50166b06fc1df8db --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java @@ -0,0 +1,107 @@ +package hdm.mi.sthbackend.service; + +import com.mongodb.client.MongoClient; +import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException; +import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; +import hdm.mi.sthbackend.model.Player; +import hdm.mi.sthbackend.model.Team; +import hdm.mi.sthbackend.model.Tournament; +import hdm.mi.sthbackend.repository.ITournamentRepository; +import hdm.mi.sthbackend.repository.MongoManager; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +@Service +@AllArgsConstructor +public class TournamentService { + + ITournamentRepository tournamentRepository; + + public Player addPlayerToTeam(UUID tournamentId, UUID teamId, String playerName) throws TournamentIdNotFoundException { + Tournament tournament = tournamentRepository.findById(tournamentId) + .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); + Player newPlayer = new Player(UUID.randomUUID(), playerName); + tournament + .getTeams() + .get(teamId) + .getTeamMembers() + .add(newPlayer); + tournamentRepository.save(tournament); + return newPlayer; + } + + public Player removePlayerFromTeam(UUID tournamentId, + UUID teamId, + UUID playerId) throws TournamentIdNotFoundException, PlayerIdNotFoundException { + Tournament tournament = tournamentRepository.findById(tournamentId) + .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); + + List<Player> teamMembers = tournament.getTeams() + .get(teamId) + .getTeamMembers(); + + Player playerToRemove = teamMembers.stream() + .filter(player -> player.getPlayerId() + .equals(playerId)) + .findFirst() + .orElseThrow(() -> new PlayerIdNotFoundException(playerId)); + + tournament.getTeams() + .get(teamId) + .getTeamMembers() + .remove(playerToRemove); + tournamentRepository.save(tournament); + return playerToRemove; + } + + public UUID updatePlayerName(UUID tournamentId, + UUID teamId, + UUID playerId, + String newPlayerName) throws TournamentIdNotFoundException, PlayerIdNotFoundException { + Tournament tournament = tournamentRepository.findById(tournamentId) + .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); + + tournament.getTeams() + .get(teamId) + .getTeamMembers() + .stream() + .filter(player -> player.getPlayerId() + .equals(playerId)) + .findFirst() + .orElseThrow(() -> new PlayerIdNotFoundException(playerId)) + .setName(newPlayerName); + tournamentRepository.save(tournament); + return playerId; + } + + public Team createTeam(UUID tournamentId, String teamName) throws TournamentIdNotFoundException { + Tournament tournament = tournamentRepository.findById(tournamentId) + .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); + + Team team = new Team(UUID.randomUUID(), teamName, new ArrayList<>() { + }); + + tournament.getTeams() + .put(team.getId(), team); + + tournamentRepository.save(tournament); + return team; + } + + public Tournament createTournament(String tournamentName) { + MongoManager manager = new MongoManager(); + MongoClient client = manager.getMongoClient(); + manager.getTestCollection(client); + + Tournament tournament = new Tournament(UUID.randomUUID(), tournamentName, new ArrayList<>(), new HashMap<>()); + tournamentRepository.insert(tournament); + return tournament; + } + + +} diff --git a/sth-backend/src/main/resources/application-dev.yaml b/sth-backend/src/main/resources/application-dev.yaml index 21003fd30f2f18244f2be1d651f081f1042d7110..e7c0fa4e0780d6313a1aaa401efab832bd9d7533 100644 --- a/sth-backend/src/main/resources/application-dev.yaml +++ b/sth-backend/src/main/resources/application-dev.yaml @@ -1,13 +1,5 @@ spring: datasource: - url: jdbc:h2:mem:testdb - driver-class-name: org.h2.Driver - username: sa - password: password - h2: - console: - enabled: true - path: /h2-console - jpa: - hibernate: - ddl-auto: update + url: mongodb://alhb:asdasd123@localhost:27018/?authMechanism=DEFAULT + username: alhb + password: asdasd123 diff --git a/sth-backend/src/main/resources/application.yaml b/sth-backend/src/main/resources/application.yaml index 3d7808a0c672513d472ab235d04d18e363fc8a87..8149bfffe9ffd7045bb15bc12146dac3b57c576e 100644 --- a/sth-backend/src/main/resources/application.yaml +++ b/sth-backend/src/main/resources/application.yaml @@ -1,3 +1,8 @@ spring: - profiles: - active: dev + data: + mongodb: + host: localhost + port: 27018 + database: tournament-hub + authentication-database: admin + uri: mongodb://alhb:asdasd123@localhost:27018/tournament-hub diff --git a/sth-frontend/.idea/.gitignore b/sth-frontend/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b58b603fea78041071d125a30db58d79b3d49217 --- /dev/null +++ b/sth-frontend/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/sth-frontend/.idea/modules.xml b/sth-frontend/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..eb0968383d20df1d15c95facf84d3da3e9289b4b --- /dev/null +++ b/sth-frontend/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/sth-frontend.iml" filepath="$PROJECT_DIR$/.idea/sth-frontend.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/sth-frontend/.idea/sth-frontend.iml b/sth-frontend/.idea/sth-frontend.iml new file mode 100644 index 0000000000000000000000000000000000000000..24643cc37449b4bde54411a80b8ed61258225e34 --- /dev/null +++ b/sth-frontend/.idea/sth-frontend.iml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="WEB_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/.tmp" /> + <excludeFolder url="file://$MODULE_DIR$/temp" /> + <excludeFolder url="file://$MODULE_DIR$/tmp" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/sth-frontend/.idea/vcs.xml b/sth-frontend/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..6c0b8635858dc7ad44b93df54b762707ce49eefc --- /dev/null +++ b/sth-frontend/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> + </component> +</project> \ No newline at end of file