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(); - } -} 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..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,8 +7,10 @@ @RequiredArgsConstructor public enum SuccessMessage { - UPDATE_NAME("팀 내 이름 변경 성공"), - 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/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; + } } 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..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,15 +11,16 @@ @AllArgsConstructor public enum ErrorCode { - /* 400 BAD_REQUEST : 잘못된 요청 */ - TOO_HIGH_AUTHORIZATION(BAD_REQUEST, "어드민은 진행할 수 없습니다."), + /* 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; }