From 6f1196659e010982318a4b96b9a631280eb31441 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:52:00 +0900 Subject: [PATCH 01/20] =?UTF-8?q?[FEAT]=20=EC=A7=81=EC=B1=85=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EB=B0=8F=20=EB=A9=A4=EB=B2=84=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberTeamController.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java new file mode 100644 index 00000000..6d4bd951 --- /dev/null +++ b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java @@ -0,0 +1,42 @@ +package com.tiki.server.memberteammanager.controller; + +import com.tiki.server.common.dto.SuccessResponse; +import com.tiki.server.memberteammanager.service.MemberTeamManagerService; +import com.tiki.server.memberteammanager.service.dto.response.MemberTeamPositionGetResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.security.Principal; + +import static com.tiki.server.common.dto.SuccessResponse.success; +import static com.tiki.server.memberteammanager.message.SuccessMessage.GET_POSITION; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1") +public class MemberTeamController { + + private final MemberTeamManagerService memberTeamManagerService; + + @GetMapping("/teams/{teamId}/members/position") + public ResponseEntity> getMemberTeamPosition( + Principal principal, + @PathVariable long teamId + ) { + long memberId = Long.parseLong(principal.getName()); + MemberTeamPositionGetResponse response = memberTeamManagerService.getPosition(memberId, teamId); + return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), response)); + } + + @PatchMapping("/teams/{teamId}/members/name") + public ResponseEntity> updateTeamMemberName( + Principal principal, + @PathVariable long teamId, + @RequestBody String newName + ) { + long memberId = Long.parseLong(principal.getName()); + memberTeamManagerService.updateTeamMemberName(memberId, teamId, newName); + return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + } +} From 0f522e58301abe7e8a6ceb5503c6b692c21330ea Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:53:21 +0900 Subject: [PATCH 02/20] =?UTF-8?q?[FEAT]=20=EC=A7=81=EC=B1=85=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EB=B0=8F=20=EB=A9=A4=EB=B2=84=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberTeamManagerService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java index dde6e437..bf503ed1 100644 --- a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java +++ b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java @@ -1,5 +1,8 @@ package com.tiki.server.memberteammanager.service; +import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; +import com.tiki.server.memberteammanager.entity.MemberTeamManager; +import com.tiki.server.memberteammanager.service.dto.response.MemberTeamPositionGetResponse; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -9,4 +12,17 @@ @RequiredArgsConstructor @Transactional(readOnly = true) public class MemberTeamManagerService { + + private final MemberTeamManagerFinder memberTeamManagerFinder; + + public MemberTeamPositionGetResponse getPosition(final long memberId, final long teamId) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + return MemberTeamPositionGetResponse.from(memberTeamManager.getPosition()); + } + + @Transactional + public void updateTeamMemberName(final long memberId, final long teamId, final String name) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManager.setName(name); + } } From b109e82e3e223d6496d7d9346d1dd170e83d5dd1 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:53:44 +0900 Subject: [PATCH 03/20] =?UTF-8?q?[FEAT]=20MemberTeamManager=20setName?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/memberteammanager/entity/MemberTeamManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java index d8fe5302..10b2d037 100644 --- a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java +++ b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java @@ -64,4 +64,8 @@ public void checkMemberAccessible(Position accesiblePosition) { throw new MemberTeamManagerException(INVALID_AUTHORIZATION); } } + + public void setName(final String name){ + this.name = name; + } } From dad7aa6efec28a2474d84e2eeeadced7084f8e10 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:54:13 +0900 Subject: [PATCH 04/20] =?UTF-8?q?[FEAT]=20=EA=B6=8C=ED=95=9C=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20API=20ResponseDto=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MemberTeamPositionGetResponse.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/tiki/server/memberteammanager/service/dto/response/MemberTeamPositionGetResponse.java diff --git a/src/main/java/com/tiki/server/memberteammanager/service/dto/response/MemberTeamPositionGetResponse.java b/src/main/java/com/tiki/server/memberteammanager/service/dto/response/MemberTeamPositionGetResponse.java new file mode 100644 index 00000000..8f102320 --- /dev/null +++ b/src/main/java/com/tiki/server/memberteammanager/service/dto/response/MemberTeamPositionGetResponse.java @@ -0,0 +1,11 @@ +package com.tiki.server.memberteammanager.service.dto.response; + +import com.tiki.server.common.entity.Position; + +public record MemberTeamPositionGetResponse( + Position position +) { + public static MemberTeamPositionGetResponse from(Position position) { + return new MemberTeamPositionGetResponse(position); + } +} From 6feabe8a19a49be1557b600d9700f6d2f2740662 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:54:32 +0900 Subject: [PATCH 05/20] =?UTF-8?q?[FEAT]=20=EA=B6=8C=ED=95=9C=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8,=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/memberteammanager/message/SuccessMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java b/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java index d9a30836..e128e091 100644 --- a/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java @@ -7,7 +7,8 @@ @RequiredArgsConstructor public enum SuccessMessage { - TEMP("컴파일 에러 방지용"); + UPDATE_NAME("팀 내 이름 변경 성공"), + GET_POSITION("직책 불러오기 성공"); private final String message; } From 4e18aa0e79607f174e9cbad434f019031c8a7640 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:55:19 +0900 Subject: [PATCH 06/20] =?UTF-8?q?[FEAT]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/controller/TeamController.java | 82 +++++++++++-------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/tiki/server/team/controller/TeamController.java b/src/main/java/com/tiki/server/team/controller/TeamController.java index a39c4ba9..307d1ece 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -1,6 +1,7 @@ package com.tiki.server.team.controller; import static com.tiki.server.common.dto.SuccessResponse.success; +import static com.tiki.server.memberteammanager.message.SuccessMessage.GET_POSITION; import static com.tiki.server.team.message.SuccessMessage.*; import java.security.Principal; @@ -26,43 +27,54 @@ @RequestMapping("api/v1/teams") public class TeamController implements TeamControllerDocs { - private final TeamService teamService; + private final TeamService teamService; - @Override - @PostMapping - public ResponseEntity> createTeam( - Principal principal, - @RequestBody TeamCreateRequest request - ) { - long memberId = Long.parseLong(principal.getName()); - TeamCreateResponse response = teamService.createTeam(memberId, request); - return ResponseEntity.created( - UriGenerator.getUri("/api/v1/teams/" + response.teamId()) - ).body(success(SUCCESS_CREATE_TEAM.getMessage(), response)); - } + @Override + @PostMapping + public ResponseEntity> createTeam( + Principal principal, + @RequestBody TeamCreateRequest request + ) { + long memberId = Long.parseLong(principal.getName()); + TeamCreateResponse response = teamService.createTeam(memberId, request); + return ResponseEntity.created( + UriGenerator.getUri("/api/v1/teams/" + response.teamId()) + ).body(success(SUCCESS_CREATE_TEAM.getMessage(), response)); + } - @Override - @GetMapping - public ResponseEntity> getAllTeams(Principal principal) { - long memberId = Long.parseLong(principal.getName()); - TeamsGetResponse response = teamService.getAllTeams(memberId); - return ResponseEntity.ok().body(success(SUCCESS_GET_TEAMS.getMessage(), response)); - } + @Override + @GetMapping + public ResponseEntity> getAllTeams(Principal principal) { + long memberId = Long.parseLong(principal.getName()); + TeamsGetResponse response = teamService.getAllTeams(memberId); + return ResponseEntity.ok().body(success(SUCCESS_GET_TEAMS.getMessage(), response)); + } - @Override - @GetMapping("/category") - public ResponseEntity> getCategories() { - CategoriesGetResponse response = teamService.getCategories(); - return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); - } + @Override + @GetMapping("/category") + public ResponseEntity> getCategories() { + CategoriesGetResponse response = teamService.getCategories(); + return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); + } - @DeleteMapping("/{teamId}") - public ResponseEntity deleteTeam( - Principal principal, - @PathVariable long teamId - ) { - long memberId = Long.parseLong(principal.getName()); - teamService.deleteTeam(memberId, teamId); - return ResponseEntity.noContent().build(); - } + @DeleteMapping("/{teamId}") + public ResponseEntity deleteTeam( + Principal principal, + @PathVariable long teamId + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.deleteTeam(memberId, teamId); + return ResponseEntity.noContent().build(); + } + + @PatchMapping("/teams/{teamId}/members/name") + public ResponseEntity> updateTeamName( + Principal principal, + @PathVariable long teamId, + @RequestBody String newTeamName + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.updateTeamName(memberId, teamId, newTeamName); + return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + } } From f56e384144774957600a1ecd5552da656fea23d6 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:55:23 +0900 Subject: [PATCH 07/20] =?UTF-8?q?[FEAT]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/team/service/TeamService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/tiki/server/team/service/TeamService.java b/src/main/java/com/tiki/server/team/service/TeamService.java index 89b75c59..113c9607 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -82,6 +82,13 @@ public void deleteTeam(long memberId, long teamId) { teamDeleter.deleteById(teamId); } + @Transactional + public void updateTeamName(final long memberId,final long teamId,final String newTeamName){ + checkIsAdmin(memberId, teamId); + Team team = teamFinder.findById(teamId); + team.updateTeamName(newTeamName); + } + private Team createTeam(TeamCreateRequest request, University univ) { return Team.of(request, univ); } From 21fe816475f3a340ca3df74fd8ba887a2f23232f Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 11:56:09 +0900 Subject: [PATCH 08/20] =?UTF-8?q?[FEAT]=20Team=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20setName=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/team/entity/Team.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/tiki/server/team/entity/Team.java b/src/main/java/com/tiki/server/team/entity/Team.java index 2ce5b3fe..e3921c12 100644 --- a/src/main/java/com/tiki/server/team/entity/Team.java +++ b/src/main/java/com/tiki/server/team/entity/Team.java @@ -53,4 +53,8 @@ public static Team of(TeamCreateRequest request, University univ) { .iconImageUrl(request.iconImageUrl()) .build(); } + + public void setName(final String name){ + this.name = name; + } } From 40f79a02a26eb9dce181e74e26a200c0e73056bc Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 17:42:37 +0900 Subject: [PATCH 09/20] =?UTF-8?q?[FEAT]=20=EC=95=84=EC=9D=B4=EC=BD=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD,=20=EC=96=B4=EB=93=9C=EB=AF=BC=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=9C=84=EC=9E=84=EA=B8=B0=EB=8A=A5=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=EB=8B=A8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/controller/TeamController.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/tiki/server/team/controller/TeamController.java b/src/main/java/com/tiki/server/team/controller/TeamController.java index 307d1ece..74368094 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -77,4 +77,26 @@ public ResponseEntity> updateTeamName( teamService.updateTeamName(memberId, teamId, newTeamName); return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); } + + @PatchMapping("/teams/{teamId}/icon") + public ResponseEntity> updateIconImage( + Principal principal, + @PathVariable long teamId, + @RequestBody String iconImageUrl + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.updateIconImage(memberId, teamId, iconImageUrl); + return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + } + + @PatchMapping("/team/{teamId}/member/{targetId}/admin") + public ResponseEntity> alterAdmin( + Principal principal, + @PathVariable long teamId, + @PathVariable long targetId + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.alterAdmin(memberId, teamId, targetId); + return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + } } From a658f58ea920d3a113cbb7723bb0af5b9f8282b9 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 17:42:51 +0900 Subject: [PATCH 10/20] =?UTF-8?q?[FEAT]=20=EC=95=84=EC=9D=B4=EC=BD=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD,=20=EC=96=B4=EB=93=9C=EB=AF=BC=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=9C=84=EC=9E=84=EA=B8=B0=EB=8A=A5=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EB=8B=A8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/team/service/TeamService.java | 146 ++++++++++-------- 1 file changed, 82 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/tiki/server/team/service/TeamService.java b/src/main/java/com/tiki/server/team/service/TeamService.java index 113c9607..43926187 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -8,6 +8,7 @@ import com.tiki.server.document.adapter.DocumentDeleter; import com.tiki.server.document.adapter.DocumentFinder; import com.tiki.server.document.entity.Document; +import com.tiki.server.external.util.S3Handler; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerDeleter; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; import com.tiki.server.team.adapter.TeamDeleter; @@ -40,68 +41,85 @@ @Transactional(readOnly = true) public class TeamService { - private final TeamSaver teamSaver; - private final TeamFinder teamFinder; - private final TeamDeleter teamDeleter; - private final MemberFinder memberFinder; - private final DocumentFinder documentFinder; - private final DocumentDeleter documentDeleter; - private final TimeBlockDeleter timeBlockDeleter; - private final MemberTeamManagerFinder memberTeamManagerFinder; - private final MemberTeamManagerDeleter memberTeamManagerDeleter; - private final MemberTeamManagerSaver memberTeamManagerSaver; - - @Transactional - public TeamCreateResponse createTeam(long memberId, TeamCreateRequest request) { - Member member = memberFinder.findById(memberId); - Team team = teamSaver.save(createTeam(request, member.getUniv())); - memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); - return TeamCreateResponse.from(team); - } - - public TeamsGetResponse getAllTeams(long memberId) { - Member member = memberFinder.findById(memberId); - University univ = member.getUniv(); - List team = teamFinder.findAllByUniv(univ); - return TeamsGetResponse.from(team); - } - - public CategoriesGetResponse getCategories() { - Category[] categories = Category.values(); - return CategoriesGetResponse.from(categories); - } - - @Transactional - public void deleteTeam(long memberId, long teamId) { - checkIsAdmin(memberId, teamId); - List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); - memberTeamManagerDeleter.deleteAll(memberTeamManagers); - List documents = documentFinder.findAllByTeamId(teamId); - documentDeleter.deleteAll(documents); - timeBlockDeleter.deleteAllByTeamId(teamId); - teamDeleter.deleteById(teamId); - } - - @Transactional - public void updateTeamName(final long memberId,final long teamId,final String newTeamName){ - checkIsAdmin(memberId, teamId); - Team team = teamFinder.findById(teamId); - team.updateTeamName(newTeamName); - } - - private Team createTeam(TeamCreateRequest request, University univ) { - return Team.of(request, univ); - } - - private MemberTeamManager createMemberTeamManager(Member member, Team team, Position position) { - return MemberTeamManager.of(member, team, position); - } - - private void checkIsAdmin(long memberId, long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - if (!memberTeamManager.getPosition().equals(ADMIN)) { - throw new TeamException(INVALID_AUTHORIZATION_DELETE); - } - memberTeamManagerDeleter.delete(memberTeamManager); - } + private final TeamSaver teamSaver; + private final TeamFinder teamFinder; + private final TeamDeleter teamDeleter; + private final MemberFinder memberFinder; + private final DocumentFinder documentFinder; + private final DocumentDeleter documentDeleter; + private final TimeBlockDeleter timeBlockDeleter; + private final MemberTeamManagerFinder memberTeamManagerFinder; + private final MemberTeamManagerDeleter memberTeamManagerDeleter; + private final MemberTeamManagerSaver memberTeamManagerSaver; + private final S3Handler s3Handler; + + @Transactional + public TeamCreateResponse createTeam(long memberId, TeamCreateRequest request) { + Member member = memberFinder.findById(memberId); + Team team = teamSaver.save(createTeam(request, member.getUniv())); + memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); + return TeamCreateResponse.from(team); + } + + public TeamsGetResponse getAllTeams(long memberId) { + Member member = memberFinder.findById(memberId); + University univ = member.getUniv(); + List team = teamFinder.findAllByUniv(univ); + return TeamsGetResponse.from(team); + } + + public CategoriesGetResponse getCategories() { + Category[] categories = Category.values(); + return CategoriesGetResponse.from(categories); + } + + @Transactional + public void deleteTeam(long memberId, long teamId) { + checkIsAdmin(memberId, teamId); + List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); + memberTeamManagerDeleter.deleteAll(memberTeamManagers); + List documents = documentFinder.findAllByTeamId(teamId); + documentDeleter.deleteAll(documents); + timeBlockDeleter.deleteAllByTeamId(teamId); + teamDeleter.deleteById(teamId); + } + + @Transactional + public void updateTeamName(final long memberId, final long teamId, final String newTeamName) { + checkIsAdmin(memberId, teamId); + Team team = teamFinder.findById(teamId); + team.setName(newTeamName); + } + + @Transactional + public void updateIconImage(final long memberId, final long teamId, final String iconImageUrl) { + checkIsAdmin(memberId, teamId); + Team team = teamFinder.findById(teamId); + s3Handler.deleteFile(team.getIconImageUrl()); + team.setIconImageUrl(iconImageUrl); + } + + @Transactional + public void alterAdmin(final long memberId, final long teamId, final long targetId) { + MemberTeamManager oldAdmin = checkIsAdmin(memberId, teamId); + MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + oldAdmin.setPositionToExecutive(); + newAdmin.setPositionToAdmin(); + } + + private Team createTeam(TeamCreateRequest request, University univ) { + return Team.of(request, univ); + } + + private MemberTeamManager createMemberTeamManager(Member member, Team team, Position position) { + return MemberTeamManager.of(member, team, position); + } + + private MemberTeamManager checkIsAdmin(long memberId, long teamId) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + if (!memberTeamManager.getPosition().equals(ADMIN)) { + throw new TeamException(INVALID_AUTHORIZATION_DELETE); + } + return memberTeamManager; + } } From a0908081f304c57732f701fdd93a312c2ea1f66d Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 17:43:41 +0900 Subject: [PATCH 11/20] =?UTF-8?q?[FEAT]=20Team=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=EC=97=90=20setIconImageURL=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/team/entity/Team.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/tiki/server/team/entity/Team.java b/src/main/java/com/tiki/server/team/entity/Team.java index e3921c12..de9e8bca 100644 --- a/src/main/java/com/tiki/server/team/entity/Team.java +++ b/src/main/java/com/tiki/server/team/entity/Team.java @@ -57,4 +57,8 @@ public static Team of(TeamCreateRequest request, University univ) { public void setName(final String name){ this.name = name; } + + public void setIconImageUrl(final String url){ + this.iconImageUrl = url; + } } From e768fa06b66c47c2644a6b0f48a0b7881a6f4d21 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 17:44:21 +0900 Subject: [PATCH 12/20] =?UTF-8?q?[FEAT]=20MemberTeamManager=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20=EA=B6=8C=ED=95=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memberteammanager/entity/MemberTeamManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java index 10b2d037..5d19a540 100644 --- a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java +++ b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java @@ -68,4 +68,12 @@ public void checkMemberAccessible(Position accesiblePosition) { public void setName(final String name){ this.name = name; } + + public void setPositionToExecutive(){ + this.position = Position.EXECUTIVE; + } + + public void setPositionToAdmin(){ + this.position = Position.ADMIN; + } } From 70aad9412e56bcc8456d502e6d4e54035fd37fe1 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 17:45:27 +0900 Subject: [PATCH 13/20] =?UTF-8?q?[CHORE]=20S3service=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=9D=84=20S3Handler=EB=A1=9C=20=EC=9C=84=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../external/controller/S3Controller.java | 2 +- .../server/external/service/S3Service.java | 22 +++++++++++++++++++ .../util/{S3Service.java => S3Handler.java} | 6 ++--- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/tiki/server/external/service/S3Service.java rename src/main/java/com/tiki/server/external/util/{S3Service.java => S3Handler.java} (96%) diff --git a/src/main/java/com/tiki/server/external/controller/S3Controller.java b/src/main/java/com/tiki/server/external/controller/S3Controller.java index 96b9b31a..8f32f5ac 100644 --- a/src/main/java/com/tiki/server/external/controller/S3Controller.java +++ b/src/main/java/com/tiki/server/external/controller/S3Controller.java @@ -4,6 +4,7 @@ import static com.tiki.server.external.message.SuccessMessage.PRESIGNED_URL_GET_SUCCESS; import static com.tiki.server.external.message.SuccessMessage.S3_FILE_DELETE_SUCCESS; +import com.tiki.server.external.service.S3Service; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -17,7 +18,6 @@ import com.tiki.server.external.controller.docs.S3ControllerDocs; import com.tiki.server.external.dto.request.S3DeleteRequest; import com.tiki.server.external.dto.response.PreSignedUrlResponse; -import com.tiki.server.external.util.S3Service; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/tiki/server/external/service/S3Service.java b/src/main/java/com/tiki/server/external/service/S3Service.java new file mode 100644 index 00000000..c07eb796 --- /dev/null +++ b/src/main/java/com/tiki/server/external/service/S3Service.java @@ -0,0 +1,22 @@ +package com.tiki.server.external.service; + +import com.tiki.server.external.dto.request.S3DeleteRequest; +import com.tiki.server.external.dto.response.PreSignedUrlResponse; +import com.tiki.server.external.util.S3Handler; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class S3Service { + + private final S3Handler s3Handler; + + public PreSignedUrlResponse getUploadPreSignedUrl(String fileFormat) { + return s3Handler.getUploadPreSignedUrl(fileFormat); + } + + public void deleteFile(S3DeleteRequest request) { + s3Handler.deleteFile(request.fileName()); + } +} diff --git a/src/main/java/com/tiki/server/external/util/S3Service.java b/src/main/java/com/tiki/server/external/util/S3Handler.java similarity index 96% rename from src/main/java/com/tiki/server/external/util/S3Service.java rename to src/main/java/com/tiki/server/external/util/S3Handler.java index abbd5306..69cd42ce 100644 --- a/src/main/java/com/tiki/server/external/util/S3Service.java +++ b/src/main/java/com/tiki/server/external/util/S3Handler.java @@ -25,7 +25,7 @@ @Component @RequiredArgsConstructor -public class S3Service { +public class S3Handler { private final AWSConfig awsConfig; @@ -46,12 +46,12 @@ public PreSignedUrlResponse getUploadPreSignedUrl(String fileFormat) { } } - public void deleteFile(S3DeleteRequest request) { + public void deleteFile(String request) { try { S3Client s3Client = awsConfig.getS3Client(); s3Client.deleteObject((DeleteObjectRequest.Builder builder) -> builder.bucket(bucket) - .key(request.fileName()) + .key(request) .build() ); } catch (RuntimeException e) { From 3117d466ae35fe5454611473ed8b953634bcf969 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 22:01:12 +0900 Subject: [PATCH 14/20] =?UTF-8?q?[FEAT]=20=EC=9A=94=EC=B2=AD=20DTO=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/request/UpdateTeamMemberNameRequest.java | 6 ++++++ .../team/controller/dto/request/UpdateTeamIconRequest.java | 6 ++++++ .../team/controller/dto/request/UpdateTeamNameRequest.java | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java create mode 100644 src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java create mode 100644 src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java new file mode 100644 index 00000000..57c8144f --- /dev/null +++ b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java @@ -0,0 +1,6 @@ +package com.tiki.server.memberteammanager.controller.dto.request; + +public record UpdateTeamMemberNameRequest( + String newName +) { +} diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java new file mode 100644 index 00000000..5dc819de --- /dev/null +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java @@ -0,0 +1,6 @@ +package com.tiki.server.team.controller.dto.request; + +public record UpdateTeamIconRequest( + String iconImageUrl +) { +} diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java new file mode 100644 index 00000000..98fe995f --- /dev/null +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java @@ -0,0 +1,6 @@ +package com.tiki.server.team.controller.dto.request; + +public record UpdateTeamNameRequest( + String newTeamName +) { +} From 21f33b27fdc3d9bc4624402c3ea3fe0666832f51 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 22:01:56 +0900 Subject: [PATCH 15/20] =?UTF-8?q?[FEAT]=20PATH=EB=B0=8F=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/controller/TeamController.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/tiki/server/team/controller/TeamController.java b/src/main/java/com/tiki/server/team/controller/TeamController.java index 74368094..a1516fc8 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -1,12 +1,13 @@ package com.tiki.server.team.controller; import static com.tiki.server.common.dto.SuccessResponse.success; -import static com.tiki.server.memberteammanager.message.SuccessMessage.GET_POSITION; import static com.tiki.server.team.message.SuccessMessage.*; import java.security.Principal; import com.tiki.server.common.dto.BaseResponse; +import com.tiki.server.team.controller.dto.request.UpdateTeamIconRequest; +import com.tiki.server.team.controller.dto.request.UpdateTeamNameRequest; import com.tiki.server.team.dto.response.CategoriesGetResponse; import com.tiki.server.team.dto.response.TeamsGetResponse; @@ -67,29 +68,29 @@ public ResponseEntity deleteTeam( return ResponseEntity.noContent().build(); } - @PatchMapping("/teams/{teamId}/members/name") + @PatchMapping("/{teamId}/name") public ResponseEntity> updateTeamName( Principal principal, @PathVariable long teamId, - @RequestBody String newTeamName + @RequestBody UpdateTeamNameRequest request ) { long memberId = Long.parseLong(principal.getName()); - teamService.updateTeamName(memberId, teamId, newTeamName); - return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + teamService.updateTeamName(memberId, teamId, request.newTeamName()); + return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_NAME.getMessage(), null)); } - @PatchMapping("/teams/{teamId}/icon") + @PatchMapping("/{teamId}/icon") public ResponseEntity> updateIconImage( Principal principal, @PathVariable long teamId, - @RequestBody String iconImageUrl + @RequestBody UpdateTeamIconRequest request ) { long memberId = Long.parseLong(principal.getName()); - teamService.updateIconImage(memberId, teamId, iconImageUrl); - return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + teamService.updateIconImage(memberId, teamId, request.iconImageUrl()); + return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_ICON.getMessage(), null)); } - @PatchMapping("/team/{teamId}/member/{targetId}/admin") + @PatchMapping("/{teamId}/member/{targetId}/admin") public ResponseEntity> alterAdmin( Principal principal, @PathVariable long teamId, @@ -97,6 +98,6 @@ public ResponseEntity> alterAdmin( ) { long memberId = Long.parseLong(principal.getName()); teamService.alterAdmin(memberId, teamId, targetId); - return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + return ResponseEntity.ok().body(success(SUCCESS_ALTER_AUTHORITY.getMessage(), null)); } } From 9f783b702355a4a20d21ea046095a7942bf3ff69 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 22:04:42 +0900 Subject: [PATCH 16/20] =?UTF-8?q?[FEAT]=20=EC=95=84=EC=9D=B4=EC=BD=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/team/service/TeamService.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/tiki/server/team/service/TeamService.java b/src/main/java/com/tiki/server/team/service/TeamService.java index 43926187..24429fe6 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -54,14 +54,14 @@ public class TeamService { private final S3Handler s3Handler; @Transactional - public TeamCreateResponse createTeam(long memberId, TeamCreateRequest request) { + public TeamCreateResponse createTeam(final long memberId, final TeamCreateRequest request) { Member member = memberFinder.findById(memberId); Team team = teamSaver.save(createTeam(request, member.getUniv())); memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); return TeamCreateResponse.from(team); } - public TeamsGetResponse getAllTeams(long memberId) { + public TeamsGetResponse getAllTeams(final long memberId) { Member member = memberFinder.findById(memberId); University univ = member.getUniv(); List team = teamFinder.findAllByUniv(univ); @@ -74,7 +74,7 @@ public CategoriesGetResponse getCategories() { } @Transactional - public void deleteTeam(long memberId, long teamId) { + public void deleteTeam(final long memberId, final long teamId) { checkIsAdmin(memberId, teamId); List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); memberTeamManagerDeleter.deleteAll(memberTeamManagers); @@ -95,27 +95,33 @@ public void updateTeamName(final long memberId, final long teamId, final String public void updateIconImage(final long memberId, final long teamId, final String iconImageUrl) { checkIsAdmin(memberId, teamId); Team team = teamFinder.findById(teamId); - s3Handler.deleteFile(team.getIconImageUrl()); + deleteIconUrl(team); team.setIconImageUrl(iconImageUrl); } @Transactional public void alterAdmin(final long memberId, final long teamId, final long targetId) { MemberTeamManager oldAdmin = checkIsAdmin(memberId, teamId); - MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(targetId, teamId); oldAdmin.setPositionToExecutive(); newAdmin.setPositionToAdmin(); } - private Team createTeam(TeamCreateRequest request, University univ) { + private Team createTeam(final TeamCreateRequest request, final University univ) { return Team.of(request, univ); } - private MemberTeamManager createMemberTeamManager(Member member, Team team, Position position) { + private void deleteIconUrl(final Team team) { + if (!team.getIconImageUrl().isBlank()) { + s3Handler.deleteFile(team.getIconImageUrl()); + } + } + + private MemberTeamManager createMemberTeamManager(final Member member, final Team team, final Position position) { return MemberTeamManager.of(member, team, position); } - private MemberTeamManager checkIsAdmin(long memberId, long teamId) { + private MemberTeamManager checkIsAdmin(final long memberId, final long teamId) { MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); if (!memberTeamManager.getPosition().equals(ADMIN)) { throw new TeamException(INVALID_AUTHORIZATION_DELETE); From 3c801cfe9a241156eeec2c24f1352be019d51ac6 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 22:04:57 +0900 Subject: [PATCH 17/20] =?UTF-8?q?[FEAT]=20=EC=84=B1=EA=B3=B5=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/team/message/SuccessMessage.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/tiki/server/team/message/SuccessMessage.java b/src/main/java/com/tiki/server/team/message/SuccessMessage.java index 407b5295..7454e072 100644 --- a/src/main/java/com/tiki/server/team/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/team/message/SuccessMessage.java @@ -8,6 +8,9 @@ public enum SuccessMessage { SUCCESS_CREATE_TEAM("팀 생성 성공"), + SUCCESS_UPDATE_TEAM_NAME("팀 이름 변경 성공"), + SUCCESS_UPDATE_TEAM_ICON("팀 아이콘 변경 성공"), + SUCCESS_ALTER_AUTHORITY("어드민 권한 위임 성공"), SUCCESS_GET_TEAMS("전체 팀 불러오기 성공"), SUCCESS_GET_CATEGORIES("카테고리 리스트 불러오기 성공"), SUCCESS_GET_JOINED_TEAM("소속 팀 불러오기 성공"); From 25772efd7fd0979d3ea08abfb6b7330099c24879 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 22:05:31 +0900 Subject: [PATCH 18/20] =?UTF-8?q?[FEAT]=20=EC=84=B1=EA=B3=B5=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberTeamController.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java index 6d4bd951..7e35ea2e 100644 --- a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java +++ b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java @@ -1,6 +1,7 @@ package com.tiki.server.memberteammanager.controller; import com.tiki.server.common.dto.SuccessResponse; +import com.tiki.server.memberteammanager.controller.dto.request.UpdateTeamMemberNameRequest; import com.tiki.server.memberteammanager.service.MemberTeamManagerService; import com.tiki.server.memberteammanager.service.dto.response.MemberTeamPositionGetResponse; import lombok.RequiredArgsConstructor; @@ -11,10 +12,11 @@ import static com.tiki.server.common.dto.SuccessResponse.success; import static com.tiki.server.memberteammanager.message.SuccessMessage.GET_POSITION; +import static com.tiki.server.memberteammanager.message.SuccessMessage.UPDATE_NAME; @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1") +@RequestMapping("/api/v1/team-member") public class MemberTeamController { private final MemberTeamManagerService memberTeamManagerService; @@ -22,7 +24,7 @@ public class MemberTeamController { @GetMapping("/teams/{teamId}/members/position") public ResponseEntity> getMemberTeamPosition( Principal principal, - @PathVariable long teamId + @PathVariable final long teamId ) { long memberId = Long.parseLong(principal.getName()); MemberTeamPositionGetResponse response = memberTeamManagerService.getPosition(memberId, teamId); @@ -32,11 +34,11 @@ public ResponseEntity> getMemberT @PatchMapping("/teams/{teamId}/members/name") public ResponseEntity> updateTeamMemberName( Principal principal, - @PathVariable long teamId, - @RequestBody String newName + @PathVariable final long teamId, + @RequestBody final UpdateTeamMemberNameRequest request ) { long memberId = Long.parseLong(principal.getName()); - memberTeamManagerService.updateTeamMemberName(memberId, teamId, newName); - return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), null)); + memberTeamManagerService.updateTeamMemberName(memberId, teamId, request.newName()); + return ResponseEntity.ok().body(success(UPDATE_NAME.getMessage(), null)); } } From 8301b8266c0996f455c544e33b01d67ed409b602 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Fri, 29 Nov 2024 22:06:32 +0900 Subject: [PATCH 19/20] =?UTF-8?q?[FEAT]=20final=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/controller/TeamController.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/tiki/server/team/controller/TeamController.java b/src/main/java/com/tiki/server/team/controller/TeamController.java index a1516fc8..90da066b 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -33,8 +33,8 @@ public class TeamController implements TeamControllerDocs { @Override @PostMapping public ResponseEntity> createTeam( - Principal principal, - @RequestBody TeamCreateRequest request + final Principal principal, + @RequestBody final TeamCreateRequest request ) { long memberId = Long.parseLong(principal.getName()); TeamCreateResponse response = teamService.createTeam(memberId, request); @@ -45,7 +45,7 @@ public ResponseEntity> createTeam( @Override @GetMapping - public ResponseEntity> getAllTeams(Principal principal) { + public ResponseEntity> getAllTeams(final Principal principal) { long memberId = Long.parseLong(principal.getName()); TeamsGetResponse response = teamService.getAllTeams(memberId); return ResponseEntity.ok().body(success(SUCCESS_GET_TEAMS.getMessage(), response)); @@ -60,8 +60,8 @@ public ResponseEntity> getCategories() { @DeleteMapping("/{teamId}") public ResponseEntity deleteTeam( - Principal principal, - @PathVariable long teamId + final Principal principal, + @PathVariable final long teamId ) { long memberId = Long.parseLong(principal.getName()); teamService.deleteTeam(memberId, teamId); @@ -70,9 +70,9 @@ public ResponseEntity deleteTeam( @PatchMapping("/{teamId}/name") public ResponseEntity> updateTeamName( - Principal principal, - @PathVariable long teamId, - @RequestBody UpdateTeamNameRequest request + final Principal principal, + @PathVariable final long teamId, + @RequestBody final UpdateTeamNameRequest request ) { long memberId = Long.parseLong(principal.getName()); teamService.updateTeamName(memberId, teamId, request.newTeamName()); @@ -81,9 +81,9 @@ public ResponseEntity> updateTeamName( @PatchMapping("/{teamId}/icon") public ResponseEntity> updateIconImage( - Principal principal, - @PathVariable long teamId, - @RequestBody UpdateTeamIconRequest request + final Principal principal, + @PathVariable final long teamId, + @RequestBody final UpdateTeamIconRequest request ) { long memberId = Long.parseLong(principal.getName()); teamService.updateIconImage(memberId, teamId, request.iconImageUrl()); @@ -92,9 +92,9 @@ public ResponseEntity> updateIconImage( @PatchMapping("/{teamId}/member/{targetId}/admin") public ResponseEntity> alterAdmin( - Principal principal, - @PathVariable long teamId, - @PathVariable long targetId + final Principal principal, + @PathVariable final long teamId, + @PathVariable final long targetId ) { long memberId = Long.parseLong(principal.getName()); teamService.alterAdmin(memberId, teamId, targetId); From a2dce319dc6fadb8839ce7f6d24b0e94beb988d8 Mon Sep 17 00:00:00 2001 From: paragon0107 Date: Mon, 2 Dec 2024 14:25:01 +0900 Subject: [PATCH 20/20] =?UTF-8?q?[FEAT]=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../document/service/DocumentService.java | 16 +++--- .../server/folder/service/FolderService.java | 6 +- .../adapter/MemberTeamManagerFinder.java | 7 +-- .../controller/MemberTeamController.java | 9 +-- .../request/UpdateTeamMemberNameRequest.java | 4 +- .../entity/MemberTeamManager.java | 6 +- .../service/MemberTeamManagerService.java | 6 +- .../tiki/server/note/service/NoteService.java | 18 +++--- .../team/controller/TeamController.java | 12 ++-- .../dto/request/UpdateTeamIconRequest.java | 4 +- .../dto/request/UpdateTeamNameRequest.java | 4 +- .../com/tiki/server/team/entity/Team.java | 56 ++++++++++--------- .../tiki/server/team/service/TeamService.java | 18 +++--- .../timeblock/service/TimeBlockService.java | 8 +-- 14 files changed, 88 insertions(+), 86 deletions(-) diff --git a/src/main/java/com/tiki/server/document/service/DocumentService.java b/src/main/java/com/tiki/server/document/service/DocumentService.java index 2acadc30..355b48fd 100644 --- a/src/main/java/com/tiki/server/document/service/DocumentService.java +++ b/src/main/java/com/tiki/server/document/service/DocumentService.java @@ -39,7 +39,7 @@ public class DocumentService { private final DeletedDocumentAdapter deletedDocumentAdapter; public DocumentsGetResponse getAllDocuments(final long memberId, final long teamId, final String type) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); return getAllDocumentsByType(teamId, accessiblePosition); @@ -47,7 +47,7 @@ public DocumentsGetResponse getAllDocuments(final long memberId, final long team @Transactional public void deleteDocument(final long memberId, final long teamId, final long documentId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Document document = documentFinder.findByIdWithTimeBlock(documentId); memberTeamManager.checkMemberAccessible(document.getTimeBlock().getAccessiblePosition()); documentDeleter.delete(document); @@ -56,21 +56,21 @@ public void deleteDocument(final long memberId, final long teamId, final long do @Transactional public void createDocuments(final long memberId, final long teamId, final Long folderId, final DocumentsCreateRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); validateFolder(folderId, teamId); validateFileName(folderId, teamId, request); saveDocuments(teamId, folderId, request); } public DocumentsGetResponse get(final long memberId, final long teamId, final Long folderId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List documents = documentFinder.findByTeamIdAndFolderId(teamId, folderId); return DocumentsGetResponse.from(documents); } @Transactional public void delete(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List documents = documentFinder.findAllByIdAndTeamId(documentIds, teamId); deletedDocumentAdapter.save(documents); documentDeleter.deleteAll(documents); @@ -78,21 +78,21 @@ public void delete(final long memberId, final long teamId, final List docu @Transactional public void deleteTrash(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId); deletedDocumentAdapter.deleteAll(deletedDocuments); } @Transactional public void restore(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId); documentSaver.restore(deletedDocuments); deletedDocumentAdapter.deleteAll(deletedDocuments); } public DeletedDocumentsGetResponse getTrash(final long memberId, final long teamId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List deletedDocuments = deletedDocumentAdapter.get(teamId); return DeletedDocumentsGetResponse.from(deletedDocuments); } diff --git a/src/main/java/com/tiki/server/folder/service/FolderService.java b/src/main/java/com/tiki/server/folder/service/FolderService.java index 2be875a0..5dfb46f6 100644 --- a/src/main/java/com/tiki/server/folder/service/FolderService.java +++ b/src/main/java/com/tiki/server/folder/service/FolderService.java @@ -39,7 +39,7 @@ public class FolderService { public FoldersGetResponse get(final long memberId, final long teamId, final Long folderId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Folder folder = getFolder(teamId, folderId); String path = getChildFolderPath(folder); List folders = folderFinder.findByTeamIdAndPath(teamId, path); @@ -49,7 +49,7 @@ public FoldersGetResponse get(final long memberId, final long teamId, @Transactional public FolderCreateResponse create(final long memberId, final long teamId, final Long folderId, final FolderCreateRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Folder parentFolder = getFolder(teamId, folderId); String path = getChildFolderPath(parentFolder); validateFolderName(teamId, path, request); @@ -59,7 +59,7 @@ public FolderCreateResponse create(final long memberId, final long teamId, @Transactional public void delete(final long memberId, final long teamId, final List folderIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List folders = folderFinder.findAllById(folderIds, teamId); deleteFolders(folders); } diff --git a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java index 84ff2bb4..38b726fa 100644 --- a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java +++ b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java @@ -10,7 +10,6 @@ import lombok.RequiredArgsConstructor; import java.util.List; -import java.util.Optional; @RepositoryAdapter @RequiredArgsConstructor @@ -18,15 +17,11 @@ public class MemberTeamManagerFinder { private final MemberTeamManagerRepository memberTeamManagerRepository; - public MemberTeamManager findByMemberIdAndTeamIdOrElseThrow(long memberId, long teamId) { + public MemberTeamManager findByMemberIdAndTeamId(long memberId, long teamId) { return memberTeamManagerRepository.findByMemberIdAndTeamId(memberId, teamId) .orElseThrow(() -> new MemberTeamManagerException(INVALID_MEMBER_TEAM_MANAGER)); } - public Optional findByMemberIdAndTeamId(final long memberId, final long teamId) { - return memberTeamManagerRepository.findByMemberIdAndTeamId(memberId, teamId); - } - public List findBelongTeamByMemberId(long memberId) { return memberTeamManagerRepository.findAllBelongTeamByMemberId(memberId).stream().toList(); } diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java index 7e35ea2e..04d38414 100644 --- a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java +++ b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java @@ -1,5 +1,6 @@ package com.tiki.server.memberteammanager.controller; +import com.tiki.server.common.dto.BaseResponse; import com.tiki.server.common.dto.SuccessResponse; import com.tiki.server.memberteammanager.controller.dto.request.UpdateTeamMemberNameRequest; import com.tiki.server.memberteammanager.service.MemberTeamManagerService; @@ -23,7 +24,7 @@ public class MemberTeamController { @GetMapping("/teams/{teamId}/members/position") public ResponseEntity> getMemberTeamPosition( - Principal principal, + final Principal principal, @PathVariable final long teamId ) { long memberId = Long.parseLong(principal.getName()); @@ -32,13 +33,13 @@ public ResponseEntity> getMemberT } @PatchMapping("/teams/{teamId}/members/name") - public ResponseEntity> updateTeamMemberName( - Principal principal, + public ResponseEntity updateTeamMemberName( + final Principal principal, @PathVariable final long teamId, @RequestBody final UpdateTeamMemberNameRequest request ) { long memberId = Long.parseLong(principal.getName()); memberTeamManagerService.updateTeamMemberName(memberId, teamId, request.newName()); - return ResponseEntity.ok().body(success(UPDATE_NAME.getMessage(), null)); + return ResponseEntity.ok(success(UPDATE_NAME.getMessage())); } } diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java index 57c8144f..9b6fc655 100644 --- a/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java +++ b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java @@ -1,6 +1,8 @@ package com.tiki.server.memberteammanager.controller.dto.request; +import jakarta.validation.constraints.NotNull; + public record UpdateTeamMemberNameRequest( - String newName + @NotNull String newName ) { } diff --git a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java index 5d19a540..c6e29230 100644 --- a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java +++ b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java @@ -65,15 +65,15 @@ public void checkMemberAccessible(Position accesiblePosition) { } } - public void setName(final String name){ + public void updateName(final String name){ this.name = name; } - public void setPositionToExecutive(){ + public void updatePositionToExecutive(){ this.position = Position.EXECUTIVE; } - public void setPositionToAdmin(){ + public void updatePositionToAdmin(){ this.position = Position.ADMIN; } } diff --git a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java index bf503ed1..5ea3a791 100644 --- a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java +++ b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java @@ -16,13 +16,13 @@ public class MemberTeamManagerService { private final MemberTeamManagerFinder memberTeamManagerFinder; public MemberTeamPositionGetResponse getPosition(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); return MemberTeamPositionGetResponse.from(memberTeamManager.getPosition()); } @Transactional public void updateTeamMemberName(final long memberId, final long teamId, final String name) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - memberTeamManager.setName(name); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); + memberTeamManager.updateName(name); } } diff --git a/src/main/java/com/tiki/server/note/service/NoteService.java b/src/main/java/com/tiki/server/note/service/NoteService.java index 3888b4ef..a9be7efc 100644 --- a/src/main/java/com/tiki/server/note/service/NoteService.java +++ b/src/main/java/com/tiki/server/note/service/NoteService.java @@ -6,7 +6,6 @@ import com.tiki.server.document.entity.Document; import com.tiki.server.member.adapter.MemberFinder; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; -import com.tiki.server.memberteammanager.entity.MemberTeamManager; import com.tiki.server.note.adapter.NoteDeleter; import com.tiki.server.note.adapter.NoteFinder; import com.tiki.server.note.adapter.NoteSaver; @@ -32,7 +31,6 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import static com.tiki.server.common.Constants.INIT_NUM; import static com.tiki.server.note.constants.NoteConstants.PAGE_SIZE; @@ -57,7 +55,7 @@ public class NoteService { @Transactional public NoteCreateServiceResponse createNoteFree(final NoteFreeCreateServiceRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteFree(request.contents()); Note note = createNote(NoteBase.of(request), encryptedContents, NoteType.FREE); createNoteTimeBlockManagers(request.timeBlockIds(), note.getId()); @@ -67,7 +65,7 @@ public NoteCreateServiceResponse createNoteFree(final NoteFreeCreateServiceReque @Transactional public NoteCreateServiceResponse createNoteTemplate(final NoteTemplateCreateServiceRequest request) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteTemplate( request.answerWhatActivity(), request.answerHowToPrepare(), @@ -83,7 +81,7 @@ public NoteCreateServiceResponse createNoteTemplate(final NoteTemplateCreateServ @Transactional public void updateNoteFree(final NoteFreeUpdateServiceRequest request) { Note note = noteFinder.findById(request.noteId()); - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteFree(request.contents()); note.updateValue( request.memberId(), @@ -102,7 +100,7 @@ public void updateNoteFree(final NoteFreeUpdateServiceRequest request) { @Transactional public void updateNoteTemplate(final NoteTemplateUpdateServiceRequest request) { Note note = noteFinder.findById(request.noteId()); - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId()); + memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId()); String encryptedContents = ContentEncoder.encodeNoteTemplate( request.answerWhatActivity(), request.answerHowToPrepare(), @@ -125,7 +123,7 @@ public void updateNoteTemplate(final NoteTemplateUpdateServiceRequest request) { @Transactional public void deleteNotes(final List noteIds, final long teamId, final long memberId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); noteDocumentManagerDeleter.deleteByNoteIds(noteIds); noteTimeBlockManagerDeleter.noteTimeBlockManagerDeleteByIds(noteIds); noteDeleter.deleteNoteByIds(noteIds); @@ -137,7 +135,7 @@ public NoteListGetServiceResponse getNote( final LocalDateTime createdAt, final SortOrder sortOrder ) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); PageRequest pageable = PageRequest.of(INIT_NUM, PAGE_SIZE); List noteList = getNotes(createdAt, sortOrder, pageable, teamId); List noteGetResponses = noteList.stream() @@ -147,7 +145,7 @@ public NoteListGetServiceResponse getNote( } public NoteDetailGetServiceResponse getNoteDetail(final long teamId, final long memberId, final long noteId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Note note = noteFinder.findById(noteId); List documentList = getDocumentListMappedByNote(noteId); List timeBlockList = getTimeBlocksMappedByNote(noteId); @@ -159,7 +157,7 @@ public NoteDetailGetServiceResponse getNoteDetail(final long teamId, final long private String getMemberName(final Long noteMemberId, final long teamId) { return Optional.ofNullable(noteMemberId) - .map(id -> memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(id, teamId).getName()) + .map(id -> memberTeamManagerFinder.findByMemberIdAndTeamId(id, teamId).getName()) .orElse("알 수 없음"); } diff --git a/src/main/java/com/tiki/server/team/controller/TeamController.java b/src/main/java/com/tiki/server/team/controller/TeamController.java index 90da066b..22a31e1e 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -69,35 +69,35 @@ public ResponseEntity deleteTeam( } @PatchMapping("/{teamId}/name") - public ResponseEntity> updateTeamName( + public ResponseEntity updateTeamName( final Principal principal, @PathVariable final long teamId, @RequestBody final UpdateTeamNameRequest request ) { long memberId = Long.parseLong(principal.getName()); teamService.updateTeamName(memberId, teamId, request.newTeamName()); - return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_NAME.getMessage(), null)); + return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_NAME.getMessage())); } @PatchMapping("/{teamId}/icon") - public ResponseEntity> updateIconImage( + public ResponseEntity updateIconImage( final Principal principal, @PathVariable final long teamId, @RequestBody final UpdateTeamIconRequest request ) { long memberId = Long.parseLong(principal.getName()); teamService.updateIconImage(memberId, teamId, request.iconImageUrl()); - return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_ICON.getMessage(), null)); + return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_ICON.getMessage())); } @PatchMapping("/{teamId}/member/{targetId}/admin") - public ResponseEntity> alterAdmin( + public ResponseEntity alterAdmin( final Principal principal, @PathVariable final long teamId, @PathVariable final long targetId ) { long memberId = Long.parseLong(principal.getName()); teamService.alterAdmin(memberId, teamId, targetId); - return ResponseEntity.ok().body(success(SUCCESS_ALTER_AUTHORITY.getMessage(), null)); + return ResponseEntity.ok(success(SUCCESS_ALTER_AUTHORITY.getMessage())); } } diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java index 5dc819de..4a0e039a 100644 --- a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java @@ -1,6 +1,8 @@ package com.tiki.server.team.controller.dto.request; +import jakarta.validation.constraints.NotNull; + public record UpdateTeamIconRequest( - String iconImageUrl + @NotNull String iconImageUrl ) { } diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java index 98fe995f..278810df 100644 --- a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java @@ -1,6 +1,8 @@ package com.tiki.server.team.controller.dto.request; +import jakarta.validation.constraints.NotNull; + public record UpdateTeamNameRequest( - String newTeamName + @NotNull String newTeamName ) { } diff --git a/src/main/java/com/tiki/server/team/entity/Team.java b/src/main/java/com/tiki/server/team/entity/Team.java index de9e8bca..aff50a76 100644 --- a/src/main/java/com/tiki/server/team/entity/Team.java +++ b/src/main/java/com/tiki/server/team/entity/Team.java @@ -26,39 +26,43 @@ @NoArgsConstructor(access = PROTECTED) public class Team extends BaseTime { - @Id - @GeneratedValue(strategy = IDENTITY) - @Column(name = "team_id") - private Long id; + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "team_id") + private Long id; - private String name; + private String name; - private String overview; + private String overview; - @Enumerated(value = STRING) - private Category category; + @Enumerated(value = STRING) + private Category category; - @Enumerated(value = STRING) - private University univ; + @Enumerated(value = STRING) + private University univ; - private String imageUrl; + private String imageUrl; - private String iconImageUrl; + private String iconImageUrl; - public static Team of(TeamCreateRequest request, University univ) { - return Team.builder() - .name(request.name()) - .category(request.category()) - .univ(univ) - .iconImageUrl(request.iconImageUrl()) - .build(); - } + public static Team of(TeamCreateRequest request, University univ) { + return Team.builder() + .name(request.name()) + .category(request.category()) + .univ(univ) + .iconImageUrl(request.iconImageUrl()) + .build(); + } - public void setName(final String name){ - this.name = name; - } + public void updateName(final String name) { + this.name = name; + } - public void setIconImageUrl(final String url){ - this.iconImageUrl = url; - } + public void setIconImageUrl(final String url) { + this.iconImageUrl = url; + } + + public boolean isDefaultImage() { + return this.getIconImageUrl().isBlank(); + } } diff --git a/src/main/java/com/tiki/server/team/service/TeamService.java b/src/main/java/com/tiki/server/team/service/TeamService.java index 24429fe6..2f9724c7 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -88,7 +88,7 @@ public void deleteTeam(final long memberId, final long teamId) { public void updateTeamName(final long memberId, final long teamId, final String newTeamName) { checkIsAdmin(memberId, teamId); Team team = teamFinder.findById(teamId); - team.setName(newTeamName); + team.updateName(newTeamName); } @Transactional @@ -102,9 +102,9 @@ public void updateIconImage(final long memberId, final long teamId, final String @Transactional public void alterAdmin(final long memberId, final long teamId, final long targetId) { MemberTeamManager oldAdmin = checkIsAdmin(memberId, teamId); - MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(targetId, teamId); - oldAdmin.setPositionToExecutive(); - newAdmin.setPositionToAdmin(); + MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamId(targetId, teamId); + oldAdmin.updatePositionToExecutive(); + newAdmin.updatePositionToAdmin(); } private Team createTeam(final TeamCreateRequest request, final University univ) { @@ -112,7 +112,7 @@ private Team createTeam(final TeamCreateRequest request, final University univ) } private void deleteIconUrl(final Team team) { - if (!team.getIconImageUrl().isBlank()) { + if (!team.isDefaultImage()) { s3Handler.deleteFile(team.getIconImageUrl()); } } @@ -122,10 +122,8 @@ private MemberTeamManager createMemberTeamManager(final Member member, final Tea } private MemberTeamManager checkIsAdmin(final long memberId, final long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - if (!memberTeamManager.getPosition().equals(ADMIN)) { - throw new TeamException(INVALID_AUTHORIZATION_DELETE); - } - return memberTeamManager; + MemberTeamManager accessMember = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); + accessMember.checkMemberAccessible(ADMIN); + return accessMember; } } diff --git a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java index cf2262f7..66169dd6 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -54,7 +54,7 @@ public TimeBlockCreateResponse createTimeBlock( TimeBlockCreateRequest request ) { Team team = teamFinder.findById(teamId); - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); TimeBlock timeBlock = saveTimeBlock(team, accessiblePosition, request); @@ -64,7 +64,7 @@ public TimeBlockCreateResponse createTimeBlock( public TimelineGetResponse getTimeline(long memberId, long teamId, String type, String date) { Team team = teamFinder.findById(teamId); - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); List timeBlocks = timeBlockFinder.findByTeamAndAccessiblePositionAndDate( @@ -73,7 +73,7 @@ public TimelineGetResponse getTimeline(long memberId, long teamId, String type, } public TimeBlockDetailGetResponse getTimeBlockDetail(long memberId, long teamId, long timeBlockId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); TimeBlock timeBlock = timeBlockFinder.findByIdOrElseThrow(timeBlockId); memberTeamManager.checkMemberAccessible(timeBlock.getAccessiblePosition()); List documents = documentFinder.findAllByTimeBlockId(timeBlockId); @@ -83,7 +83,7 @@ public TimeBlockDetailGetResponse getTimeBlockDetail(long memberId, long teamId, @Transactional public void deleteTimeBlock(long memberId, long teamId, long timeBlockId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); TimeBlock timeBlock = timeBlockFinder.findByIdOrElseThrow(timeBlockId); memberTeamManager.checkMemberAccessible(timeBlock.getAccessiblePosition()); documentDeleter.deleteAllByTimeBlockId(timeBlock.getId());