From 9f143387753cd0025b87eb13675e1f96c2a4188d Mon Sep 17 00:00:00 2001
From: mh378 <mh378@hdm-stuttgart.de>
Date: Mon, 8 Jan 2024 19:39:51 +0100
Subject: [PATCH] 08.01.2024 - added method updateTeamName to Service #24

---
 .../src/main/java/hdm/mi/sthbackend/model/Team.java  |  5 +++--
 .../hdm/mi/sthbackend/service/TournamentService.java | 12 +++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

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 cb98022..620a1d1 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
@@ -2,6 +2,7 @@ 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;
 
@@ -14,7 +15,7 @@ import java.util.UUID;
 public class Team {
     @Id
     private final UUID id;
-
-    private final String teamName;
+    @Setter
+    private String teamName;
     private final List<UUID> teamMembers;
 }
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
index 703c1fb..faab404 100644
--- a/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java
+++ b/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java
@@ -195,7 +195,17 @@ public class TournamentService {
         }
         match.getTeamScores().put(teamId, newScore);
         tournamentRepository.save(tournament);
-        log.debug("Score von Team " + teamId + " auf " + newScore + " geupdatet");
+        log.debug("Score of Team " + teamId + " updated to " + newScore);
+    }
+
+
+    public UUID updateTeamName(UUID teamId, String newTeamName) throws TeamIdNotFoundException {
+        Team team = teamRepository.findById(teamId)
+                .orElseThrow(() -> new TeamIdNotFoundException(teamId));
+        team.setTeamName(newTeamName);
+        teamRepository.save(team);
+        log.debug("Teamname of " + teamId + " updated to " + newTeamName);
+        return teamId;
     }
 
     /*
-- 
GitLab