Skip to content

Commit

Permalink
refactor : HostRole 명칭 수정 (#257)
Browse files Browse the repository at this point in the history
* refactor : 호스트 역할 이름 수정

* chore : 컨트롤러 명칭 수정

* chore : spotless apply

* chore : 검증 메소드 명칭 수정

* chore : spotless apply
  • Loading branch information
gengminy authored Feb 1, 2023
1 parent 4340168 commit 36f0178
Showing 18 changed files with 44 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
/** 각 권한에 맞춰서 host 도메인의 검증메소드를 실행시킵니다. 검증 메소드이므로 biConsumer 를 통해 실행 시킬 함수를 미리 생성해 둡니다. -이찬진 */
public enum HostQualification {
MASTER((userId, host) -> host.validateMasterHostUser(userId)),
MANAGER((userId, host) -> host.validateSuperHostUser(userId)),
MANAGER((userId, host) -> host.validateManagerHostUser(userId)),
GUEST((userId, host) -> host.validateActiveHostUser(userId));
private final BiConsumer<Long, Host> consumer;

Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public CreateCouponCampaignResponse execute(
// 존재하는 유저인지 검증
User user = userUtils.getCurrentUser();
// 슈퍼 호스트인지 검증
hostService.validateSuperHostUser(createCouponCampaignRequest.getHostId(), user.getId());
hostService.validateManagerHostUser(createCouponCampaignRequest.getHostId(), user.getId());
// 이미 생성된 쿠폰 코드인지 검증
createCouponCampaignDomainService.checkCouponCodeExists(
createCouponCampaignRequest.getCouponCode());
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public EventResponse execute(CreateEventRequest createEventRequest) {
final User user = userUtils.getCurrentUser();
final Long userId = user.getId();
// 슈퍼 호스트 이상만 공연 생성 가능
hostService.validateSuperHostUser(createEventRequest.getHostId(), userId);
hostService.validateManagerHostUser(createEventRequest.getHostId(), userId);
final Event event = eventMapper.toEntity(createEventRequest);
return EventResponse.of(eventService.createEvent(event));
}
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public EventResponse execute(Long eventId, UpdateEventBasicRequest updateEventBa
final User user = userUtils.getCurrentUser();
final Long userId = user.getId();
final Event event = eventAdaptor.findById(eventId);
hostService.validateSuperHostUser(event.getHostId(), userId);
hostService.validateManagerHostUser(event.getHostId(), userId);

EventBasic eventBasic = eventMapper.toEventBasic(updateEventBasicRequest);
EventPlace eventPlace = eventMapper.toEventPlace(updateEventBasicRequest);
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public EventResponse execute(Long eventId, UpdateEventStatusRequest updateEventS
final User user = userUtils.getCurrentUser();
final Long userId = user.getId();
final Event event = eventAdaptor.findById(eventId);
hostService.validateSuperHostUser(event.getHostId(), userId);
hostService.validateManagerHostUser(event.getHostId(), userId);
final EventStatus status = updateEventStatusRequest.getStatus();

return EventResponse.of(eventService.updateEventStatus(event, status));
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ public HostDetailResponse inviteHost(
return inviteHostUseCase.execute(hostId, inviteHostRequest);
}

@Operation(summary = "호스트 유저의 권한을 변경합니다. 슈퍼 호스트 이상만 가능합니다.")
@Operation(summary = "호스트 유저의 권한을 변경합니다. 매니저 이상만 가능합니다.")
@PatchMapping("/{hostId}/role")
public HostDetailResponse patchHostUserRole(
@PathVariable Long hostId,
@@ -95,14 +95,14 @@ public HostDetailResponse patchHostUserRole(
}

// todo :: 슈퍼 호스트 이상으로?
@Operation(summary = "호스트 정보를 변경합니다. 슈퍼 호스트 이상만 가능합니다.")
@Operation(summary = "호스트 정보를 변경합니다. 매니저 이상만 가능합니다.")
@PatchMapping("/{hostId}/profile")
public HostDetailResponse patchHostById(
@PathVariable Long hostId, @RequestBody @Valid UpdateHostRequest updateHostRequest) {
return updateHostProfileUseCase.execute(hostId, updateHostRequest);
}

@Operation(summary = "호스트 슬랙 알람 URL 을 변경합니다. 슈퍼 호스트 이상만 가능합니다.")
@Operation(summary = "호스트 슬랙 알람 URL 을 변경합니다. 매니저 이상만 가능합니다.")
@PatchMapping("/{hostId}/slack")
public HostDetailResponse patchHostSlackUrlById(
@PathVariable Long hostId,
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public class UpdateHostUserRoleRequest {
@Positive(message = "올바른 유저 고유 아이디를 입력해주세요")
private Long userId;

@Schema(defaultValue = "HOST", description = "호스트 유저 역할")
@Enum(message = "HOST 또는 SUPER_HOST 만 허용됩니다")
@Schema(defaultValue = "MANAGER", description = "호스트 유저 역할")
@Enum(message = "GUEST, MANAGER, MASTER 만 허용됩니다")
private HostRole role;
}
Original file line number Diff line number Diff line change
@@ -52,10 +52,16 @@ public HostUser toHostUser(Long hostId, Long userId, HostRole role) {
return HostUser.builder().userId(userId).host(host).role(role).build();
}

/** 역할 지정하여 주입하는 생성자 */
public HostUser toSuperHostUser(Long hostId, Long userId) {
/** 매니저로 주입하는 생성자 */
public HostUser toManagerHostUser(Long hostId, Long userId) {
final Host host = hostAdaptor.findById(hostId);
return HostUser.builder().userId(userId).host(host).role(HostRole.SUPER_HOST).build();
return HostUser.builder().userId(userId).host(host).role(HostRole.MANAGER).build();
}

/** 마스터 주입하는 생성자 */
public HostUser toMasterHostUser(Long hostId, Long userId) {
final Host host = hostAdaptor.findById(hostId);
return HostUser.builder().userId(userId).host(host).role(HostRole.MASTER).build();
}

@Transactional(readOnly = true)
@@ -88,8 +94,6 @@ private HostDetailResponse toHostDetailResponseExecute(Host host) {
.map(User::toUserInfoVo)
.collect(Collectors.toSet());

// todo :: 유저 리스트에 역할까지 추가하기

final Set<HostUserVo> hostUserVoSet =
userInfoVoSet.stream()
.map(
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ public HostResponse execute(CreateHostRequest createHostRequest) {
final Long userId = user.getId();
// 호스트 생성
final Host host = hostService.createHost(hostMapper.toEntity(createHostRequest, userId));
// 생성한 유저를 마스터로 + 슈퍼 호스트 권한으로 등록
final HostUser masterHostUser = hostMapper.toSuperHostUser(host.getId(), userId);
// 생성한 유저를 마스터 권한으로 등록
final HostUser masterHostUser = hostMapper.toMasterHostUser(host.getId(), userId);
// 초대 보류 없이 즉시 활성화
masterHostUser.activate();
return HostResponse.of(hostService.addHostUser(host, masterHostUser));
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public HostDetailResponse execute(Long hostId, UpdateHostRequest updateHostReque

final Host host = hostAdaptor.findById(hostId);
// 슈퍼 호스트 검증
host.validateSuperHostUser(userId);
host.validateManagerHostUser(userId);

return hostMapper.toHostDetailResponse(
hostService.updateHostProfile(host, hostMapper.toHostProfile(updateHostRequest)));
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@ public HostDetailResponse execute(
final User user = userUtils.getCurrentUser();
final Long userId = user.getId();
final Host host = hostAdaptor.findById(hostId);
// 슈퍼 호스트 검증
host.validateSuperHostUser(userId);
// 매니저 호스트 검증
host.validateManagerHostUser(userId);

final Long updateUserId = updateHostUserRoleRequest.getUserId();
final HostRole updateUserRole = updateHostUserRoleRequest.getRole();
Original file line number Diff line number Diff line change
@@ -60,12 +60,12 @@ public void setSlackUrl(String slackUrl) {
this.slackUrl = slackUrl;
}

public Boolean isSuperHostUserId(Long userId) {
public Boolean isManagerHostUserId(Long userId) {
return this.hostUsers.stream()
.anyMatch(
hostUser ->
hostUser.getUserId().equals(userId)
&& hostUser.getRole().equals(HostRole.SUPER_HOST));
&& hostUser.getRole().equals(HostRole.MANAGER));
}

public Boolean isActiveHostUserId(Long userId) {
@@ -100,11 +100,11 @@ public void validateActiveHostUser(Long userId) {
}
}

/** 해당 유저가 슈퍼 호스트인지 확인하는 검증 로직입니다 */
public void validateSuperHostUser(Long userId) {
/** 해당 유저가 매니저 이상인지 확인하는 검증 로직입니다 */
public void validateManagerHostUser(Long userId) {
this.validateActiveHostUser(userId);
if (!this.isSuperHostUserId(userId)) {
throw NotSuperHostException.EXCEPTION;
if (!this.isManagerHostUserId(userId) && !this.getMasterUserId().equals(userId)) {
throw NotManagerHostException.EXCEPTION;
}
}

Original file line number Diff line number Diff line change
@@ -8,10 +8,12 @@
@Getter
@AllArgsConstructor
public enum HostRole {
// 마스터 (모든 권한)
MASTER("MASTER", "마스터"),
// 슈퍼 호스트 (조회, 변경 가능)
SUPER_HOST("SUPER_HOST", "매니저"),
MANAGER("MANAGER", "매니저"),
// 일반 호스트 (조회만 가능)
HOST("HOST", "게스트");
GUEST("GUEST", "게스트");

private final String name;
private final String value;
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public class HostUser extends BaseTimeEntity {

// 유저의 권한
@Enumerated(EnumType.STRING)
private HostRole role = HostRole.HOST;
private HostRole role = HostRole.GUEST;

public void setHostRole(HostRole role) {
this.role = role;
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ public class ForbiddenHostOperationException extends DuDoongCodeException {
public static final DuDoongCodeException EXCEPTION = new ForbiddenHostOperationException();

private ForbiddenHostOperationException() {
super(HostErrorCode.FORBIDDEN_HOST_OPERATION);
super(HostErrorCode.CANNOT_MODIFY_MASTER_HOST_ROLE);
}
}
Original file line number Diff line number Diff line change
@@ -14,11 +14,11 @@
@Getter
@AllArgsConstructor
public enum HostErrorCode implements BaseErrorCode {
NOT_SUPER_HOST(BAD_REQUEST, "HOST_400_1", "슈퍼 호스트 권한이 없는 유저입니다."),
NOT_MANAGER_HOST(BAD_REQUEST, "HOST_400_1", "매니저 권한이 없는 유저입니다."),
FORBIDDEN_HOST(BAD_REQUEST, "HOST_400_2", "해당 호스트에 대한 접근 권한이 없습니다."),
ALREADY_JOINED_HOST(BAD_REQUEST, "HOST_400_3", "이미 가입되어 있는 유저입니다."),
NOT_MASTER_HOST(BAD_REQUEST, "HOST_400_4", "마스터 호스트 권한이 없는 유저입니다."),
FORBIDDEN_HOST_OPERATION(BAD_REQUEST, "HOST_400_5", "마스터 호스트의 권한은 변경할 수 없습니다."),
CANNOT_MODIFY_MASTER_HOST_ROLE(BAD_REQUEST, "HOST_400_5", "마스터 호스트의 권한은 변경할 수 없습니다."),
NOT_ACCEPTED_HOST(BAD_REQUEST, "HOST_400_6", "아직 초대를 수락하지 않은 유저입니다."),
HOST_NOT_FOUND(NOT_FOUND, "Host_404_1", "해당 호스트를 찾을 수 없습니다."),
HOST_USER_NOT_FOUND(NOT_FOUND, "HOST_404_2", "가입된 호스트 유저가 아닙니다.");
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@

import band.gosrock.common.exception.DuDoongCodeException;

public class NotSuperHostException extends DuDoongCodeException {
public static final DuDoongCodeException EXCEPTION = new NotSuperHostException();
public class NotManagerHostException extends DuDoongCodeException {
public static final DuDoongCodeException EXCEPTION = new NotManagerHostException();

private NotSuperHostException() {
super(HostErrorCode.NOT_SUPER_HOST);
private NotManagerHostException() {
super(HostErrorCode.NOT_MANAGER_HOST);
}
}
Original file line number Diff line number Diff line change
@@ -63,8 +63,8 @@ public void validateMasterHostUser(Host host, Long userId) {
}

/** 해당 유저가 슈퍼 호스트인지 확인하는 검증 로직입니다 */
public void validateSuperHostUser(Long hostId, Long userId) {
public void validateManagerHostUser(Long hostId, Long userId) {
Host host = hostAdaptor.findById(hostId);
host.validateSuperHostUser(userId);
host.validateManagerHostUser(userId);
}
}

0 comments on commit 36f0178

Please sign in to comment.