From 6691b57ba50343f2c570a448c626680365572b72 Mon Sep 17 00:00:00 2001 From: smg0725 Date: Tue, 3 Dec 2024 02:44:47 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[CHORE]=20MemberTeamController=20=EC=9D=BC?= =?UTF-8?q?=EC=9B=90=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberTeamController.java | 23 ++++++++++ .../MemberTeamManagerController.java | 42 ------------------- 2 files changed, 23 insertions(+), 42 deletions(-) delete mode 100644 src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.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 index 04d38414..4492e00d 100644 --- a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java +++ b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java @@ -13,6 +13,8 @@ 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.KICK_TEAM; +import static com.tiki.server.memberteammanager.message.SuccessMessage.LEAVE_TEAM; import static com.tiki.server.memberteammanager.message.SuccessMessage.UPDATE_NAME; @RestController @@ -42,4 +44,25 @@ public ResponseEntity updateTeamMemberName( memberTeamManagerService.updateTeamMemberName(memberId, teamId, request.newName()); return ResponseEntity.ok(success(UPDATE_NAME.getMessage())); } + + @DeleteMapping("/teams/{teamId}/members/{kickOutMemberId}") + public ResponseEntity kickOutMemberFromTeam( + final Principal principal, + @PathVariable final long teamId, + @PathVariable final long kickOutMemberId + ) { + long memberId = Long.parseLong(principal.getName()); + memberTeamManagerService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); + return ResponseEntity.ok(success(KICK_TEAM.getMessage())); + } + + @DeleteMapping("/teams/{teamId}/leave") + public ResponseEntity leaveTeam( + final Principal principal, + @PathVariable final long teamId + ) { + long memberId = Long.parseLong(principal.getName()); + memberTeamManagerService.leaveTeam(memberId, teamId); + return ResponseEntity.ok(success(LEAVE_TEAM.getMessage())); + } } diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.java b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.java deleted file mode 100644 index 9f99291d..00000000 --- a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamManagerController.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.tiki.server.memberteammanager.controller; - -import com.tiki.server.common.dto.BaseResponse; -import com.tiki.server.memberteammanager.service.MemberTeamManagerService; -import lombok.AllArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.security.Principal; - - -@RestController -@AllArgsConstructor -@RequestMapping("api/v1/teams") -public class MemberTeamManagerController { - - private final MemberTeamManagerService memberTeamManagerService; - - @DeleteMapping("/{teamId}/members/{kickOutMemberId}") - public ResponseEntity kickOutMemberFromTeam( - final Principal principal, - @PathVariable final long teamId, - @PathVariable final long kickOutMemberId - ) { - long memberId = Long.parseLong(principal.getName()); - memberTeamManagerService.kickOutMemberFromTeam(memberId, teamId, kickOutMemberId); - return ResponseEntity.noContent().build(); - } - - @DeleteMapping("/{teamId}/leave") - public ResponseEntity leaveTeam( - final Principal principal, - @PathVariable final long teamId - ) { - long memberId = Long.parseLong(principal.getName()); - memberTeamManagerService.leaveTeam(memberId, teamId); - return ResponseEntity.noContent().build(); - } -} From 46808d98d8cf6e575d9a2461083727947fe91f70 Mon Sep 17 00:00:00 2001 From: smg0725 Date: Tue, 3 Dec 2024 02:44:57 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[CHORE]=20=EB=A9=94=EC=84=B8=EC=A7=80=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 --- .../tiki/server/memberteammanager/message/SuccessMessage.java | 2 ++ src/main/java/com/tiki/server/team/message/ErrorCode.java | 1 + 2 files changed, 3 insertions(+) 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 e128e091..280715bc 100644 --- a/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java @@ -8,6 +8,8 @@ public enum SuccessMessage { UPDATE_NAME("팀 내 이름 변경 성공"), + LEAVE_TEAM("팀 탈퇴 성공"), + KICK_TEAM("팀 퇴출 성공"), GET_POSITION("직책 불러오기 성공"); private final String message; diff --git a/src/main/java/com/tiki/server/team/message/ErrorCode.java b/src/main/java/com/tiki/server/team/message/ErrorCode.java index 3f871892..309a0175 100644 --- a/src/main/java/com/tiki/server/team/message/ErrorCode.java +++ b/src/main/java/com/tiki/server/team/message/ErrorCode.java @@ -13,6 +13,7 @@ public enum ErrorCode { /* 400 BAD_REQUEST : 잘못된 요청 */ TOO_HIGH_AUTHORIZATION(BAD_REQUEST, "어드민은 진행할 수 없습니다."), + TOO_SHORT_PERIOD(BAD_REQUEST,"30일이 지나야 이름을 변경할 수 있습니다."), /* 403 FORBIDDEN : 권한 없음 */ INVALID_AUTHORIZATION_DELETE(FORBIDDEN, "권한이 없습니다."), From 620f46398affc569169121104021e73e11fd9724 Mon Sep 17 00:00:00 2001 From: smg0725 Date: Tue, 3 Dec 2024 02:45:20 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[CHORE]=20=ED=8C=80=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=A0=95=EC=B1=85=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/entity/Team.java | 18 ++++++++++++++++++ 1 file changed, 18 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 aff50a76..5db50789 100644 --- a/src/main/java/com/tiki/server/team/entity/Team.java +++ b/src/main/java/com/tiki/server/team/entity/Team.java @@ -1,5 +1,6 @@ package com.tiki.server.team.entity; +import static com.tiki.server.team.message.ErrorCode.TOO_SHORT_PERIOD; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PRIVATE; @@ -9,11 +10,14 @@ import com.tiki.server.common.entity.University; import com.tiki.server.team.dto.request.TeamCreateRequest; +import com.tiki.server.team.exception.TeamException; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -44,18 +48,24 @@ public class Team extends BaseTime { private String imageUrl; private String iconImageUrl; + private LocalDate namingUpdatedAt; public static Team of(TeamCreateRequest request, University univ) { return Team.builder() .name(request.name()) .category(request.category()) .univ(univ) + .namingUpdatedAt(null) .iconImageUrl(request.iconImageUrl()) .build(); } public void updateName(final String name) { + if (!canChangeName()) { + throw new TeamException(TOO_SHORT_PERIOD); + } this.name = name; + this.namingUpdatedAt = LocalDate.now(); } public void setIconImageUrl(final String url) { @@ -65,4 +75,12 @@ public void setIconImageUrl(final String url) { public boolean isDefaultImage() { return this.getIconImageUrl().isBlank(); } + + private boolean canChangeName() { + if (namingUpdatedAt == null) { + return true; + } + long daysBetween = ChronoUnit.DAYS.between(namingUpdatedAt, LocalDate.now()); + return daysBetween >= 30; + } } From 035c8062ba5db1769d40609991145cc5b01421f9 Mon Sep 17 00:00:00 2001 From: smg0725 Date: Tue, 3 Dec 2024 02:47:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[CHORE]=20=EC=BB=A8=EB=B2=A4=EC=85=98=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/SuccessMessage.java | 10 +++++----- .../tiki/server/team/message/ErrorCode.java | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) 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 280715bc..23dab3db 100644 --- a/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java @@ -7,10 +7,10 @@ @RequiredArgsConstructor public enum SuccessMessage { - UPDATE_NAME("팀 내 이름 변경 성공"), - LEAVE_TEAM("팀 탈퇴 성공"), - KICK_TEAM("팀 퇴출 성공"), - GET_POSITION("직책 불러오기 성공"); + UPDATE_NAME("팀 내 이름 변경 성공"), + LEAVE_TEAM("팀 탈퇴 성공"), + KICK_TEAM("팀 퇴출 성공"), + GET_POSITION("직책 불러오기 성공"); - private final String message; + private final String message; } diff --git a/src/main/java/com/tiki/server/team/message/ErrorCode.java b/src/main/java/com/tiki/server/team/message/ErrorCode.java index 309a0175..a80d0766 100644 --- a/src/main/java/com/tiki/server/team/message/ErrorCode.java +++ b/src/main/java/com/tiki/server/team/message/ErrorCode.java @@ -11,16 +11,16 @@ @AllArgsConstructor public enum ErrorCode { - /* 400 BAD_REQUEST : 잘못된 요청 */ - TOO_HIGH_AUTHORIZATION(BAD_REQUEST, "어드민은 진행할 수 없습니다."), - TOO_SHORT_PERIOD(BAD_REQUEST,"30일이 지나야 이름을 변경할 수 있습니다."), + /* 400 BAD_REQUEST : 잘못된 요청 */ + TOO_HIGH_AUTHORIZATION(BAD_REQUEST, "어드민은 진행할 수 없습니다."), + TOO_SHORT_PERIOD(BAD_REQUEST, "30일이 지나야 이름을 변경할 수 있습니다."), - /* 403 FORBIDDEN : 권한 없음 */ - INVALID_AUTHORIZATION_DELETE(FORBIDDEN, "권한이 없습니다."), + /* 403 FORBIDDEN : 권한 없음 */ + INVALID_AUTHORIZATION_DELETE(FORBIDDEN, "권한이 없습니다."), - /* 404 NOT_FOUND : 자원을 찾을 수 없음 */ - INVALID_TEAM(NOT_FOUND, "유효하지 않은 단체입니다."); + /* 404 NOT_FOUND : 자원을 찾을 수 없음 */ + INVALID_TEAM(NOT_FOUND, "유효하지 않은 단체입니다."); - private final HttpStatus httpStatus; - private final String message; + private final HttpStatus httpStatus; + private final String message; }