Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] 워크스페이스 이름 변경 정책 추가 #189

Merged
merged 4 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,4 +44,25 @@ public ResponseEntity<BaseResponse> updateTeamMemberName(
memberTeamManagerService.updateTeamMemberName(memberId, teamId, request.newName());
return ResponseEntity.ok(success(UPDATE_NAME.getMessage()));
}

@DeleteMapping("/teams/{teamId}/members/{kickOutMemberId}")
public ResponseEntity<BaseResponse> 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<BaseResponse> 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()));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
18 changes: 18 additions & 0 deletions src/main/java/com/tiki/server/team/entity/Team.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
17 changes: 9 additions & 8 deletions src/main/java/com/tiki/server/team/message/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading