Skip to content

Commit

Permalink
๐Ÿš€ :: Api-v0.1.4-2
Browse files Browse the repository at this point in the history
๐Ÿš€ :: Api-v0.1.4-2
  • Loading branch information
ImNM authored Feb 12, 2023
2 parents 4b3d7c8 + f73c514 commit 776e9f1
Show file tree
Hide file tree
Showing 28 changed files with 167 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.event.handler;
package band.gosrock.api.slack.handler.event;


import band.gosrock.domain.common.alarm.EventSlackAlarm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.event.handler;
package band.gosrock.api.slack.handler.event;


import band.gosrock.domain.common.alarm.EventSlackAlarm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.event.handler;
package band.gosrock.api.slack.handler.event;


import band.gosrock.domain.common.alarm.EventSlackAlarm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.event.handler;
package band.gosrock.api.slack.handler.event;


import band.gosrock.domain.common.alarm.EventSlackAlarm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.host.handler;
package band.gosrock.api.slack.handler.host;


import band.gosrock.domain.common.alarm.HostSlackAlarm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.host.handler;
package band.gosrock.api.slack.handler.host;


import band.gosrock.api.email.service.HostUserDisabledEmailService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.host.handler;
package band.gosrock.api.slack.handler.host;


import band.gosrock.api.email.service.HostUserInvitationEmailService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.host.handler;
package band.gosrock.api.slack.handler.host;


import band.gosrock.domain.common.alarm.HostSlackAlarm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.gosrock.api.host.handler;
package band.gosrock.api.slack.handler.host;


import band.gosrock.api.email.service.HostMasterChangeEmailService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TicketItem> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public TicketItemResponse execute(
ticketItemService.createTicketItem(
ticketItemMapper.toTicketItem(createTicketItemRequest, event), isPartner);

return TicketItemResponse.from(ticketItem);
return TicketItemResponse.from(ticketItem, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public GetEventTicketItemsResponse execute(Long eventId, Long ticketItemId) {

ticketItemService.softDeleteTicketItem(eventId, ticketItemId);

return ticketItemMapper.toGetEventTicketItemsResponse(eventId);
return ticketItemMapper.toGetEventTicketItemsResponse(eventId, true);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "๊ฐ€์ž…๋œ ํ˜ธ์ŠคํŠธ ์œ ์ €๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.");

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading

0 comments on commit 776e9f1

Please sign in to comment.