From ccd04d4c7fe2e9154d818fc481d10185a3a76ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=85=B8=EA=B2=BD=EB=AF=BC?= Date: Sun, 12 Feb 2023 09:26:11 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix=20:=20=ED=98=B8=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=EC=8A=AC=EB=9E=99=20URL=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=B6=94=EA=B0=80=20(#348)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/ReadEventDetailUseCase.java | 2 +- .../dto/request/UpdateHostSlackRequest.java | 2 ++ .../service/UpdateHostSlackUrlUseCase.java | 14 +++++++++- .../EventContentChangeEventHandler.java | 2 +- .../event}/EventCreationEventHandler.java | 2 +- .../event}/EventDeletionEventHandler.java | 2 +- .../event}/EventStatusChangeEventHandler.java | 2 +- .../host}/HostRegisterSlackEventHandler.java | 2 +- .../host}/HostUserDisabledEventHandler.java | 2 +- .../host}/HostUserInvitationEventHandler.java | 2 +- .../host}/HostUserJoinEventHandler.java | 2 +- .../host}/HostUserRoleChangeEventHandler.java | 2 +- .../gosrock/domain/common/vo/HostInfoVo.java | 1 + .../domain/domains/host/domain/Host.java | 3 ++- .../domains/host/exception/HostErrorCode.java | 1 + .../exception/InvalidSlackUrlException.java | 12 +++++++++ .../domains/host/service/HostService.java | 8 ++++++ .../config/slack/SlackMessageProvider.java | 27 ++++++++++++++++--- 18 files changed, 73 insertions(+), 15 deletions(-) rename DuDoong-Api/src/main/java/band/gosrock/api/{event/handler => slack/handler/event}/EventContentChangeEventHandler.java (97%) rename DuDoong-Api/src/main/java/band/gosrock/api/{event/handler => slack/handler/event}/EventCreationEventHandler.java (96%) rename DuDoong-Api/src/main/java/band/gosrock/api/{event/handler => slack/handler/event}/EventDeletionEventHandler.java (97%) rename DuDoong-Api/src/main/java/band/gosrock/api/{event/handler => slack/handler/event}/EventStatusChangeEventHandler.java (97%) rename DuDoong-Api/src/main/java/band/gosrock/api/{host/handler => slack/handler/host}/HostRegisterSlackEventHandler.java (96%) rename DuDoong-Api/src/main/java/band/gosrock/api/{host/handler => slack/handler/host}/HostUserDisabledEventHandler.java (97%) rename DuDoong-Api/src/main/java/band/gosrock/api/{host/handler => slack/handler/host}/HostUserInvitationEventHandler.java (96%) rename DuDoong-Api/src/main/java/band/gosrock/api/{host/handler => slack/handler/host}/HostUserJoinEventHandler.java (97%) rename DuDoong-Api/src/main/java/band/gosrock/api/{host/handler => slack/handler/host}/HostUserRoleChangeEventHandler.java (98%) create mode 100644 DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/InvalidSlackUrlException.java diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/event/service/ReadEventDetailUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/event/service/ReadEventDetailUseCase.java index 79a5896c..0a542044 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/event/service/ReadEventDetailUseCase.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/event/service/ReadEventDetailUseCase.java @@ -27,7 +27,7 @@ public EventDetailResponse execute(Long eventId) { final Host host = hostAdaptor.findById(event.getHostId()); final Long userId = userUtils.getCurrentUserId(); // 호스트 유저가 아닐 경우 준비 상태일 때 조회할 수 없음 - if (event.isPreparing() && !host.hasHostUserId(userId)) { + if (event.isPreparing() && !host.isActiveHostUserId(userId)) { throw EventNotOpenException.EXCEPTION; } return eventMapper.toEventDetailResponse(host, event); diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/host/model/dto/request/UpdateHostSlackRequest.java b/DuDoong-Api/src/main/java/band/gosrock/api/host/model/dto/request/UpdateHostSlackRequest.java index 2db34943..73040dc0 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/host/model/dto/request/UpdateHostSlackRequest.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/host/model/dto/request/UpdateHostSlackRequest.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.NotBlank; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -13,6 +14,7 @@ @AllArgsConstructor public class UpdateHostSlackRequest { @Schema(defaultValue = "https://slack.dd.com", description = "슬랙 웹훅 URL") + @NotBlank(message = "올바른 슬랙 URL 을 입력해주세요") @URL(message = "올바른 슬랙 URL 을 입력해주세요") private String slackUrl; } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/host/service/UpdateHostSlackUrlUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/host/service/UpdateHostSlackUrlUseCase.java index c59c7383..0c584e2e 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/host/service/UpdateHostSlackUrlUseCase.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/host/service/UpdateHostSlackUrlUseCase.java @@ -10,7 +10,10 @@ import band.gosrock.common.annotation.UseCase; import band.gosrock.domain.domains.host.adaptor.HostAdaptor; import band.gosrock.domain.domains.host.domain.Host; +import band.gosrock.domain.domains.host.exception.InvalidSlackUrlException; import band.gosrock.domain.domains.host.service.HostService; +import band.gosrock.infrastructure.config.slack.SlackMessageProvider; +import java.net.UnknownHostException; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; @@ -21,11 +24,20 @@ public class UpdateHostSlackUrlUseCase { private final HostAdaptor hostAdaptor; private final HostMapper hostMapper; + private final SlackMessageProvider slackMessageProvider; + @Transactional @HostRolesAllowed(role = MANAGER, findHostFrom = HOST_ID) public HostDetailResponse execute(Long hostId, UpdateHostSlackRequest updateHostSlackRequest) { final Host host = hostAdaptor.findById(hostId); final String slackUrl = updateHostSlackRequest.getSlackUrl(); - return hostMapper.toHostDetailResponse(hostService.updateHostSlackUrl(host, slackUrl)); + hostService.validateDuplicatedSlackUrl(host, slackUrl); + + try { + slackMessageProvider.register(slackUrl); + return hostMapper.toHostDetailResponse(hostService.updateHostSlackUrl(host, slackUrl)); + } catch (UnknownHostException e) { + throw InvalidSlackUrlException.EXCEPTION; + } } } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventContentChangeEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventContentChangeEventHandler.java similarity index 97% rename from DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventContentChangeEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventContentChangeEventHandler.java index ae885d97..af1e33ac 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventContentChangeEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventContentChangeEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.event.handler; +package band.gosrock.api.slack.handler.event; import band.gosrock.domain.common.alarm.EventSlackAlarm; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventCreationEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventCreationEventHandler.java similarity index 96% rename from DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventCreationEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventCreationEventHandler.java index 891840af..ed315afd 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventCreationEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventCreationEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.event.handler; +package band.gosrock.api.slack.handler.event; import band.gosrock.domain.common.alarm.EventSlackAlarm; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventDeletionEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventDeletionEventHandler.java similarity index 97% rename from DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventDeletionEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventDeletionEventHandler.java index 7bdf3fb5..7138c5d0 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventDeletionEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventDeletionEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.event.handler; +package band.gosrock.api.slack.handler.event; import band.gosrock.domain.common.alarm.EventSlackAlarm; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventStatusChangeEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventStatusChangeEventHandler.java similarity index 97% rename from DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventStatusChangeEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventStatusChangeEventHandler.java index 5b093906..b1f5aaab 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/event/handler/EventStatusChangeEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/event/EventStatusChangeEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.event.handler; +package band.gosrock.api.slack.handler.event; import band.gosrock.domain.common.alarm.EventSlackAlarm; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostRegisterSlackEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostRegisterSlackEventHandler.java similarity index 96% rename from DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostRegisterSlackEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostRegisterSlackEventHandler.java index 149154a1..12eefd04 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostRegisterSlackEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostRegisterSlackEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.host.handler; +package band.gosrock.api.slack.handler.host; import band.gosrock.domain.common.alarm.HostSlackAlarm; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserDisabledEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserDisabledEventHandler.java similarity index 97% rename from DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserDisabledEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserDisabledEventHandler.java index 9c188aac..6997bed4 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserDisabledEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserDisabledEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.host.handler; +package band.gosrock.api.slack.handler.host; import band.gosrock.api.email.service.HostUserDisabledEmailService; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserInvitationEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserInvitationEventHandler.java similarity index 96% rename from DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserInvitationEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserInvitationEventHandler.java index 5d4cd90b..7be6186f 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserInvitationEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserInvitationEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.host.handler; +package band.gosrock.api.slack.handler.host; import band.gosrock.api.email.service.HostUserInvitationEmailService; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserJoinEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserJoinEventHandler.java similarity index 97% rename from DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserJoinEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserJoinEventHandler.java index 2cd21e74..31118ce5 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserJoinEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserJoinEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.host.handler; +package band.gosrock.api.slack.handler.host; import band.gosrock.domain.common.alarm.HostSlackAlarm; diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserRoleChangeEventHandler.java b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserRoleChangeEventHandler.java similarity index 98% rename from DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserRoleChangeEventHandler.java rename to DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserRoleChangeEventHandler.java index 4fb790c5..79f76334 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/host/handler/HostUserRoleChangeEventHandler.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/slack/handler/host/HostUserRoleChangeEventHandler.java @@ -1,4 +1,4 @@ -package band.gosrock.api.host.handler; +package band.gosrock.api.slack.handler.host; import band.gosrock.api.email.service.HostMasterChangeEmailService; diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java index ca8ee696..949efb09 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/common/vo/HostInfoVo.java @@ -30,6 +30,7 @@ public static HostInfoVo from(Host host) { .profileImage(host.getProfile().getProfileImage()) .contactEmail(host.getProfile().getContactEmail()) .contactNumber(host.getProfile().getContactNumber()) + .partner(host.getPartner()) .build(); } } diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java index 904420cd..39f0632d 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/domain/Host.java @@ -15,6 +15,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.apache.commons.codec.binary.StringUtils; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -77,7 +78,7 @@ public void updateProfile(HostProfile hostProfile) { } public void setSlackUrl(String slackUrl) { - if (this.slackUrl.equals(slackUrl)) { + if (StringUtils.equals(this.slackUrl, slackUrl)) { throw DuplicateSlackUrlException.EXCEPTION; } Events.raise(HostRegisterSlackEvent.of(this)); diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/HostErrorCode.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/HostErrorCode.java index 67fe3dcd..fa6849c0 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/HostErrorCode.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/HostErrorCode.java @@ -22,6 +22,7 @@ public enum HostErrorCode implements BaseErrorCode { NOT_ACCEPTED_HOST(BAD_REQUEST, "HOST_400_6", "아직 초대를 수락하지 않은 유저입니다."), NOT_PARTNER_HOST(BAD_REQUEST, "HOST_400_7", "파트너 호스트만 사용할 수 있는 기능입니다. 제휴 신청을 해주세요."), DUPLICATED_SLACK_URL(BAD_REQUEST, "HOST_400_8", "기존과 동일한 슬랙 url 입니다."), + INVALID_SLACK_URL(BAD_REQUEST, "HOST_400_9", "유효하지 않은 않은 슬랙 url 입니다."), HOST_NOT_FOUND(NOT_FOUND, "Host_404_1", "해당 호스트를 찾을 수 없습니다."), HOST_USER_NOT_FOUND(NOT_FOUND, "HOST_404_2", "가입된 호스트 유저가 아닙니다."); diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/InvalidSlackUrlException.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/InvalidSlackUrlException.java new file mode 100644 index 00000000..4bae2d7e --- /dev/null +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/exception/InvalidSlackUrlException.java @@ -0,0 +1,12 @@ +package band.gosrock.domain.domains.host.exception; + + +import band.gosrock.common.exception.DuDoongCodeException; + +public class InvalidSlackUrlException extends DuDoongCodeException { + public static final DuDoongCodeException EXCEPTION = new InvalidSlackUrlException(); + + private InvalidSlackUrlException() { + super(HostErrorCode.INVALID_SLACK_URL); + } +} diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/service/HostService.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/service/HostService.java index 67d5047b..f9e759d8 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/service/HostService.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/host/service/HostService.java @@ -7,9 +7,11 @@ import band.gosrock.domain.domains.host.domain.HostProfile; import band.gosrock.domain.domains.host.domain.HostRole; import band.gosrock.domain.domains.host.domain.HostUser; +import band.gosrock.domain.domains.host.exception.InvalidSlackUrlException; import band.gosrock.domain.domains.host.repository.HostRepository; import java.util.Set; import lombok.RequiredArgsConstructor; +import org.apache.commons.codec.binary.StringUtils; import org.springframework.transaction.annotation.Transactional; @DomainService @@ -53,6 +55,12 @@ public Host activateHostUser(Host host, Long userId) { return hostRepository.save(host); } + public void validateDuplicatedSlackUrl(Host host, String url) { + if (StringUtils.equals(host.getSlackUrl(), url)) { + throw InvalidSlackUrlException.EXCEPTION; + } + } + /** 해당 유저가 호스트에 속하는지 확인하는 검증 로직입니다 */ public void validateHostUser(Host host, Long userId) { host.validateHostUser(userId); diff --git a/DuDoong-Infrastructure/src/main/java/band/gosrock/infrastructure/config/slack/SlackMessageProvider.java b/DuDoong-Infrastructure/src/main/java/band/gosrock/infrastructure/config/slack/SlackMessageProvider.java index 0a33647b..7abd0552 100644 --- a/DuDoong-Infrastructure/src/main/java/band/gosrock/infrastructure/config/slack/SlackMessageProvider.java +++ b/DuDoong-Infrastructure/src/main/java/band/gosrock/infrastructure/config/slack/SlackMessageProvider.java @@ -4,8 +4,10 @@ import com.slack.api.Slack; import com.slack.api.webhook.Payload; import java.io.IOException; +import java.net.UnknownHostException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.binary.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -23,11 +25,30 @@ public class SlackMessageProvider { @Async public void sendMessage(String url, String text) { - Slack slack = Slack.getInstance(); - Payload payload = Payload.builder().text(text).username(username).iconUrl(iconUrl).build(); + try { + doSend(url, text); + } catch (Exception ignored) { + } + } + + /** 호스트가 존재하는 지 확인하기 위해 동기로 처리 */ + public void register(String url) throws UnknownHostException { + final String text = "두둥 슬랙 알림이 성공적으로 등록되었습니다!"; + doSend(url, text); + } + private void doSend(String url, String text) throws UnknownHostException { + final Slack slack = Slack.getInstance(); + final Payload payload = + Payload.builder().text(text).username(username).iconUrl(iconUrl).build(); try { - slack.send(url, payload); + String responseBody = slack.send(url, payload).getBody(); + if (!StringUtils.equals(responseBody, "ok")) { + throw new UnknownHostException("올바른 슬랙 URL이 아닙니다."); + } + } catch (UnknownHostException error) { + // 호스트가 존재하지 않을 경우 abort + throw error; } catch (IOException e) { log.error(e.getMessage(), e); throw new RuntimeException(e); From 4ebedfea2dd8f0b33acafe2df41ab348627b4385 Mon Sep 17 00:00:00 2001 From: Minjoon Kim <59060780+sanbonai06@users.noreply.github.com> Date: Sun, 12 Feb 2023 09:27:20 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20:=20=EB=B0=B8=EB=A6=AC=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EB=B0=B8?= =?UTF-8?q?=EB=A6=AC=EB=8D=B0=EC=9D=B4=EC=85=98=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20(#345)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issuedTicket/domain/IssuedTicket.java | 8 +-- .../domain/IssuedTicketStatus.java | 4 ++ .../validator/IssuedTicketValidator.java | 15 +++--- .../validator/IssuedTicketValidatorTest.java | 51 +++++++++++++++++++ 4 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/domain/validator/IssuedTicketValidatorTest.java diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicket.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicket.java index 5f7c90f9..324186f6 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicket.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicket.java @@ -163,7 +163,7 @@ public EmailIssuedTicketInfo toEmailIssuedTicketInfo() { 티켓이 입장 미완료 상태가 아니면 취소 할 수 없음 */ public void cancel() { - if (this.issuedTicketStatus != IssuedTicketStatus.ENTRANCE_INCOMPLETE) { + if (!this.issuedTicketStatus.isBeforeEntrance()) { throw CanNotCancelException.EXCEPTION; } this.issuedTicketStatus = IssuedTicketStatus.CANCELED; @@ -175,10 +175,10 @@ public void cancel() { (입장 처리 도메인 이벤트 발행) */ public void entrance() { - if (this.issuedTicketStatus == IssuedTicketStatus.CANCELED) { + if (this.issuedTicketStatus.isCanceled()) { throw CanNotEntranceException.EXCEPTION; } - if (this.issuedTicketStatus == IssuedTicketStatus.ENTRANCE_COMPLETED) { + if (this.issuedTicketStatus.isAfterEntrance()) { throw IssuedTicketAlreadyEntranceException.EXCEPTION; } this.issuedTicketStatus = IssuedTicketStatus.ENTRANCE_COMPLETED; @@ -190,7 +190,7 @@ public void entrance() { 티켓이 입장 완료 상태가 아니면 입장 취소 할 수 없음 */ public void entranceCancel() { - if (this.issuedTicketStatus != IssuedTicketStatus.ENTRANCE_COMPLETED) { + if (!this.issuedTicketStatus.isAfterEntrance()) { throw CanNotCancelEntranceException.EXCEPTION; } this.issuedTicketStatus = IssuedTicketStatus.ENTRANCE_INCOMPLETE; diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicketStatus.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicketStatus.java index ec72fb12..fd6e75cd 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicketStatus.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/domain/IssuedTicketStatus.java @@ -30,4 +30,8 @@ public Boolean isBeforeEntrance() { public Boolean isAfterEntrance() { return this == IssuedTicketStatus.ENTRANCE_COMPLETED; } + + public Boolean is(IssuedTicket issuedTicket) { + return issuedTicket.getIssuedTicketStatus() == IssuedTicketStatus.ENTRANCE_INCOMPLETE; + } } diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/validator/IssuedTicketValidator.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/validator/IssuedTicketValidator.java index 5b06a878..2cea6b1d 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/validator/IssuedTicketValidator.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/validator/IssuedTicketValidator.java @@ -3,9 +3,7 @@ import band.gosrock.common.annotation.Validator; import band.gosrock.domain.domains.event.adaptor.EventAdaptor; -import band.gosrock.domain.domains.event.domain.Event; import band.gosrock.domain.domains.host.adaptor.HostAdaptor; -import band.gosrock.domain.domains.host.domain.Host; import band.gosrock.domain.domains.issuedTicket.domain.IssuedTicket; import band.gosrock.domain.domains.issuedTicket.exception.IssuedTicketNotMatchedEventException; import java.util.Objects; @@ -17,12 +15,13 @@ public class IssuedTicketValidator { private final EventAdaptor eventAdaptor; private final HostAdaptor hostAdaptor; - - public void validCanModifyIssuedTicketUser(IssuedTicket issuedTicket, Long currentUserId) { - Event event = eventAdaptor.findById(issuedTicket.getEventId()); - Host host = hostAdaptor.findById(event.getHostId()); - host.validateHostUser(currentUserId); - } + // + // public void validCanModifyIssuedTicketUser(IssuedTicket issuedTicket, Long currentUserId) + // { + // Event event = eventAdaptor.findById(issuedTicket.getEventId()); + // Host host = hostAdaptor.findById(event.getHostId()); + // host.validateHostUser(currentUserId); + // } public void validIssuedTicketEventIdEqualEvent(IssuedTicket issuedTicket, Long eventId) { if (!Objects.equals(issuedTicket.getEventId(), eventId)) { diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/domain/validator/IssuedTicketValidatorTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/domain/validator/IssuedTicketValidatorTest.java new file mode 100644 index 00000000..0d8f9e4f --- /dev/null +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/domain/validator/IssuedTicketValidatorTest.java @@ -0,0 +1,51 @@ +package band.gosrock.domain.domains.issuedTicket.domain.validator; + +import static org.mockito.BDDMockito.given; + +import band.gosrock.domain.domains.event.adaptor.EventAdaptor; +import band.gosrock.domain.domains.host.adaptor.HostAdaptor; +import band.gosrock.domain.domains.issuedTicket.domain.IssuedTicket; +import band.gosrock.domain.domains.issuedTicket.exception.IssuedTicketNotMatchedEventException; +import band.gosrock.domain.domains.issuedTicket.validator.IssuedTicketValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class IssuedTicketValidatorTest { + + @Mock IssuedTicket issuedTicket; + + @Mock EventAdaptor eventAdaptor; + + @Mock HostAdaptor hostAdaptor; + + IssuedTicketValidator issuedTicketValidator; + + @BeforeEach + public void setUp() { + issuedTicketValidator = new IssuedTicketValidator(eventAdaptor, hostAdaptor); + } + + @Test + public void 발급티켓_이벤트_검증_성공() { + // given + given(issuedTicket.getEventId()).willReturn(1L); + // when + issuedTicketValidator.validIssuedTicketEventIdEqualEvent(issuedTicket, 1L); + } + + @Test + public void 발급티켓_이벤트_검증_실패() { + // given + given(issuedTicket.getEventId()).willReturn(2L); + // when + // then + Assertions.assertThrows( + IssuedTicketNotMatchedEventException.class, + () -> issuedTicketValidator.validIssuedTicketEventIdEqualEvent(issuedTicket, 1L)); + } +} From f73c514fd9b1ab751a7b0907ed5ea86e89e2b0ad Mon Sep 17 00:00:00 2001 From: ONE ZIN <80401705+kim-wonjin@users.noreply.github.com> Date: Sun, 12 Feb 2023 09:30:31 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor(ticketItem)=20:=20=ED=8B=B0?= =?UTF-8?q?=EC=BC=93=20=EC=9E=AC=EA=B3=A0=20=EC=88=A8=EA=B8=B0=EA=B8=B0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20/=20=EC=96=B4?= =?UTF-8?q?=EB=93=9C=EB=AF=B8=EC=9A=A9=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ticketItem/controller/TicketItemController.java | 6 ++++++ .../ticketItem/dto/response/TicketItemResponse.java | 7 +++++-- .../api/ticketItem/mapper/TicketItemMapper.java | 7 +++++-- .../ticketItem/service/CreateTicketItemUseCase.java | 2 +- .../ticketItem/service/DeleteTicketItemUseCase.java | 2 +- .../service/GetEventTicketItemsUseCase.java | 11 ++++++++++- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/controller/TicketItemController.java b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/controller/TicketItemController.java index c5befd98..132b4be0 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/controller/TicketItemController.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/controller/TicketItemController.java @@ -56,6 +56,12 @@ public GetEventTicketItemsResponse getEventTicketItems(@PathVariable Long eventI return getEventTicketItemsUseCase.execute(eventId); } + @Operation(summary = "해당 이벤트의 티켓상품을 모두 조회합니다. (어드민용)", description = "재고 정보가 무조건 공개됩니다.") + @GetMapping("/admin") + public GetEventTicketItemsResponse getEventTicketItemsForAdmin(@PathVariable Long eventId) { + return getEventTicketItemsUseCase.executeForAdmin(eventId); + } + @Operation(summary = "해당 티켓상품의 옵션을 모두 조회합니다.") @GetMapping("/{ticketItemId}/options") public GetTicketItemOptionsResponse getTicketItemOptions( diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/dto/response/TicketItemResponse.java b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/dto/response/TicketItemResponse.java index b1fb0265..a959195e 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/dto/response/TicketItemResponse.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/dto/response/TicketItemResponse.java @@ -42,7 +42,7 @@ public class TicketItemResponse { @Schema(description = "재고공개 여부") private final Boolean isQuantityPublic; - public static TicketItemResponse from(TicketItem ticketItem) { + public static TicketItemResponse from(TicketItem ticketItem, Boolean isAdmin) { return TicketItemResponse.builder() .ticketItemId(ticketItem.getId()) @@ -53,7 +53,10 @@ public static TicketItemResponse from(TicketItem ticketItem) { .approveType(ticketItem.getType()) .purchaseLimit(ticketItem.getPurchaseLimit()) .supplyCount(ticketItem.getSupplyCount()) - .quantity(ticketItem.getQuantity()) + .quantity( + isAdmin || ticketItem.getIsQuantityPublic() + ? ticketItem.getQuantity() + : null) .isQuantityPublic(ticketItem.getIsQuantityPublic()) .build(); } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/mapper/TicketItemMapper.java b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/mapper/TicketItemMapper.java index d90b8bdf..29ea0b98 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/mapper/TicketItemMapper.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/mapper/TicketItemMapper.java @@ -41,12 +41,15 @@ public TicketItem toTicketItem(CreateTicketItemRequest createTicketItemRequest, } @Transactional(readOnly = true) - public GetEventTicketItemsResponse toGetEventTicketItemsResponse(Long eventId) { + public GetEventTicketItemsResponse toGetEventTicketItemsResponse( + Long eventId, Boolean isAdmin) { Event event = eventAdaptor.findById(eventId); List ticketItems = ticketItemAdaptor.findAllByEventId(event.getId()); return GetEventTicketItemsResponse.from( - ticketItems.stream().map(TicketItemResponse::from).toList()); + ticketItems.stream() + .map(ticketItem -> TicketItemResponse.from(ticketItem, isAdmin)) + .toList()); } @Transactional(readOnly = true) diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/CreateTicketItemUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/CreateTicketItemUseCase.java index 814f24b1..29407314 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/CreateTicketItemUseCase.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/CreateTicketItemUseCase.java @@ -42,6 +42,6 @@ public TicketItemResponse execute( ticketItemService.createTicketItem( ticketItemMapper.toTicketItem(createTicketItemRequest, event), isPartner); - return TicketItemResponse.from(ticketItem); + return TicketItemResponse.from(ticketItem, true); } } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/DeleteTicketItemUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/DeleteTicketItemUseCase.java index f2aaabbb..3a9eafc9 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/DeleteTicketItemUseCase.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/DeleteTicketItemUseCase.java @@ -34,6 +34,6 @@ public GetEventTicketItemsResponse execute(Long eventId, Long ticketItemId) { ticketItemService.softDeleteTicketItem(eventId, ticketItemId); - return ticketItemMapper.toGetEventTicketItemsResponse(eventId); + return ticketItemMapper.toGetEventTicketItemsResponse(eventId, true); } } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/GetEventTicketItemsUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/GetEventTicketItemsUseCase.java index 88dc2ad0..d9774cb0 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/GetEventTicketItemsUseCase.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/ticketItem/service/GetEventTicketItemsUseCase.java @@ -1,6 +1,9 @@ package band.gosrock.api.ticketItem.service; +import static band.gosrock.api.common.aop.hostRole.FindHostFrom.EVENT_ID; +import static band.gosrock.api.common.aop.hostRole.HostQualification.GUEST; +import band.gosrock.api.common.aop.hostRole.HostRolesAllowed; import band.gosrock.api.ticketItem.dto.response.GetEventTicketItemsResponse; import band.gosrock.api.ticketItem.mapper.TicketItemMapper; import band.gosrock.common.annotation.UseCase; @@ -14,6 +17,12 @@ public class GetEventTicketItemsUseCase { public GetEventTicketItemsResponse execute(Long eventId) { - return ticketItemMapper.toGetEventTicketItemsResponse(eventId); + return ticketItemMapper.toGetEventTicketItemsResponse(eventId, false); + } + + @HostRolesAllowed(role = GUEST, findHostFrom = EVENT_ID) + public GetEventTicketItemsResponse executeForAdmin(Long eventId) { + + return ticketItemMapper.toGetEventTicketItemsResponse(eventId, true); } }