Skip to content

Commit

Permalink
Api-v0.1.9
Browse files Browse the repository at this point in the history
Api-v0.1.9
  • Loading branch information
ImNM authored Feb 24, 2023
2 parents 36db23f + 60ea4de commit fe73c86
Show file tree
Hide file tree
Showing 19 changed files with 668 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public PageResponse<IssuedTicketAdminTableElement> getIssuedTickets(
}

@Operation(summary = "[어드민 기능] 발급 티켓 입장 처리 API 입니다.")
@PatchMapping(value = "/{issuedTicketId}")
@PatchMapping(value = "/{uuid}")
public IssuedTicketInfoVo patchIssuedTicketStatus(
@PathVariable Long eventId, @PathVariable Long issuedTicketId) {
return entranceIssuedTicketUseCase.execute(eventId, issuedTicketId);
@PathVariable Long eventId, @PathVariable String uuid) {
return entranceIssuedTicketUseCase.execute(eventId, uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class IssuedTicketController {
private final ReadIssuedTicketUseCase readIssuedTicketUseCase;

@Operation(summary = "발급 티켓 가져오기 API 입니다.")
@GetMapping(value = "/{issuedTicketId}", produces = "application/json; charset=utf-8")
public RetrieveIssuedTicketDetailResponse getIssuedTicket(@PathVariable Long issuedTicketId) {
return readIssuedTicketUseCase.execute(issuedTicketId);
@GetMapping(value = "/{uuid}", produces = "application/json; charset=utf-8")
public RetrieveIssuedTicketDetailResponse getIssuedTicket(@PathVariable String uuid) {
return readIssuedTicketUseCase.execute(uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ private static User getUser(List<User> users, Long userId) {

@Transactional(readOnly = true)
public RetrieveIssuedTicketDetailResponse toIssuedTicketDetailResponse(
Long currentUserId, Long issuedTicketId) {
IssuedTicket issuedTicket = issuedTicketAdaptor.findForUser(currentUserId, issuedTicketId);
Long currentUserId, String uuid) {
IssuedTicket issuedTicket = issuedTicketAdaptor.findForUser(currentUserId, uuid);
Event event = eventAdaptor.findById(issuedTicket.getEventId());
return RetrieveIssuedTicketDetailResponse.of(issuedTicket, event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EntranceIssuedTicketUseCase {

@Transactional
@HostRolesAllowed(role = MANAGER, findHostFrom = EVENT_ID)
public IssuedTicketInfoVo execute(Long eventId, Long issuedTicketId) {
return issuedTicketDomainService.processingEntranceIssuedTicket(eventId, issuedTicketId);
public IssuedTicketInfoVo execute(Long eventId, String uuid) {
return issuedTicketDomainService.processingEntranceIssuedTicket(eventId, uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class ReadIssuedTicketUseCase {
/**
* 발급 티켓 상세 정보 API
*
* @param issuedTicketId 발급 티켓 id
* @param uuid 발급 티켓 id
* @return RetrieveIssuedTicketDetailResponse
*/
public RetrieveIssuedTicketDetailResponse execute(Long issuedTicketId) {
public RetrieveIssuedTicketDetailResponse execute(String uuid) {
Long currentUserId = SecurityUtils.getCurrentUserId();
return issuedTicketMapper.toIssuedTicketDetailResponse(currentUserId, issuedTicketId);
return issuedTicketMapper.toIssuedTicketDetailResponse(currentUserId, uuid);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package band.gosrock.domain.domains.coupon.domain;


import band.gosrock.common.annotation.EnumClass;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
@EnumClass
public enum ApplyTarget {
ALL("ALL"),
SUB("SUB");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package band.gosrock.domain.domains.coupon.domain;


import band.gosrock.common.annotation.EnumClass;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
@EnumClass
public enum DiscountType {
// 정액 할인
AMOUNT("AMOUNT"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ public class Event extends BaseTimeEntity {
private EventStatus status = PREPARING;

public LocalDateTime getStartAt() {
if (this.eventBasic == null) {
return null;
}
if (this.eventBasic == null) return null;
return this.getEventBasic().getStartAt();
}

public LocalDateTime getEndAt() {
if (this.eventBasic == null) {
return null;
}
if (this.eventBasic == null) return null;
return this.getEventBasic().endAt();
}

Expand Down Expand Up @@ -100,15 +96,11 @@ public void validateOpenStatus() {
}

public void validateStatusOpen() {
if (status != OPEN) {
throw EventNotOpenException.EXCEPTION;
}
if (status != OPEN) throw EventNotOpenException.EXCEPTION;
}

public void validateTicketingTime() {
if (!isTimeBeforeStartAt()) {
throw EventTicketingTimeIsPassedException.EXCEPTION;
}
if (!isTimeBeforeStartAt()) throw EventTicketingTimeIsPassedException.EXCEPTION;
}

public Boolean isRefundDateNotPassed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import band.gosrock.domain.common.util.SliceUtil;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.event.domain.EventStatus;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -37,7 +39,7 @@ public Slice<Event> querySliceEventsByStatus(EventStatus status, Pageable pageab
queryFactory
.selectFrom(event)
.where(eqStatusOpen())
.orderBy(event.id.desc())
.orderBy(startAtAsc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + 1)
.fetch();
Expand Down Expand Up @@ -68,4 +70,8 @@ private BooleanExpression eqStatusOpen() {
private BooleanExpression nameContains(String keyword) {
return keyword == null ? null : event.eventBasic.name.containsIgnoreCase(keyword);
}

private OrderSpecifier<LocalDateTime> startAtAsc() {
return event.eventBasic.startAt.desc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public void saveAll(List<IssuedTicket> issuedTickets) {
issuedTicketRepository.saveAll(issuedTickets);
}

public IssuedTicket findForUser(Long currentUserId, Long issuedTicketId) {
public IssuedTicket findForUser(Long currentUserId, String uuid) {
IssuedTicket issuedTicket =
issuedTicketRepository
.find(issuedTicketId)
.findByUuid(uuid)
.orElseThrow(() -> IssuedTicketNotFoundException.EXCEPTION);
if (!Objects.equals(issuedTicket.getUserInfo().getUserId(), currentUserId)) {
throw IssuedTicketUserNotMatchedException.EXCEPTION;
Expand Down Expand Up @@ -80,4 +80,10 @@ public IssuedTicket queryByIssuedTicketNo(String issuedTicketNo) {
.findByIssuedTicketNo(issuedTicketNo)
.orElseThrow(() -> IssuedTicketNotFoundException.EXCEPTION);
}

public IssuedTicket queryByIssuedTicketUuid(String uuid) {
return issuedTicketRepository
.findByUuid(uuid)
.orElseThrow(() -> IssuedTicketNotFoundException.EXCEPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface IssuedTicketRepository
Optional<IssuedTicket> findByIssuedTicketNo(String issuedTicketNo);

Boolean existsByEventId(Long eventId);

Optional<IssuedTicket> findByUuid(String uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public void doneOrderEventAfterRollBackWithdrawIssuedTickets(Long itemId, String
/*
발급 티켓 입장 처리 로직
*/
public IssuedTicketInfoVo processingEntranceIssuedTicket(Long eventId, Long issuedTicketId) {
IssuedTicket issuedTicket = issuedTicketAdaptor.queryIssuedTicket(issuedTicketId);
public IssuedTicketInfoVo processingEntranceIssuedTicket(Long eventId, String uuid) {
IssuedTicket issuedTicket = issuedTicketAdaptor.queryByIssuedTicketUuid(uuid);
issuedTicketValidator.validIssuedTicketEventIdEqualEvent(issuedTicket, eventId);
issuedTicket.entrance();
return issuedTicket.toIssuedTicketInfoVo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package band.gosrock.domain.domains.coupon.domain;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import band.gosrock.domain.common.vo.DateTimePeriod;
import band.gosrock.domain.domains.coupon.exception.NotIssuingCouponPeriodException;
import band.gosrock.domain.domains.coupon.exception.WrongDiscountAmountException;
import java.time.LocalDateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class CouponCampaignTest {
CouponCampaign couponCampaign;

@BeforeEach
void setUp() {
LocalDateTime nowTime = LocalDateTime.now();
DateTimePeriod dateTimePeriod =
new DateTimePeriod(nowTime.minusDays(2), nowTime.minusDays(1));

CouponStockInfo couponStockInfo =
CouponStockInfo.builder().issuedAmount(3L).remainingAmount(1L).build();
couponCampaign =
CouponCampaign.builder()
.discountType(DiscountType.PERCENTAGE)
.couponStockInfo(couponStockInfo)
.dateTimePeriod(dateTimePeriod)
.build();
}

@Test
public void testValidatePercentageAmount() {
assertThrows(
WrongDiscountAmountException.class,
() -> {
couponCampaign.validatePercentageAmount(DiscountType.PERCENTAGE, 101L);
});
}

@Test
public void testDecreaseCouponStock() {
// given
// when
couponCampaign.decreaseCouponStock();
// then
assertEquals(couponCampaign.getCouponStockInfo().getRemainingAmount(), 0L);
}

@Test
public void testValidateIssuePeriod() {
assertThrows(
NotIssuingCouponPeriodException.class,
() -> {
couponCampaign.validateIssuePeriod();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package band.gosrock.domain.domains.coupon.domain;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import band.gosrock.domain.domains.coupon.exception.NoCouponStockLeftException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class CouponStockInfoTest {

CouponStockInfo zeroCouponStockInfo;
CouponStockInfo leftCouponStockInfo;

@BeforeEach
void setUp() {
zeroCouponStockInfo =
CouponStockInfo.builder().remainingAmount(0L).issuedAmount(3L).build();
leftCouponStockInfo =
CouponStockInfo.builder().remainingAmount(1L).issuedAmount(3L).build();
}

@Test
public void 쿠폰_남은_재고_없음() {
// given
zeroCouponStockInfo =
CouponStockInfo.builder().remainingAmount(0L).issuedAmount(3L).build();
// when, then
assertThrows(
NoCouponStockLeftException.class, () -> zeroCouponStockInfo.decreaseCouponStock());
}

@Test
public void 쿠폰_남은_재고_있음() {
// given
leftCouponStockInfo =
CouponStockInfo.builder().remainingAmount(1L).issuedAmount(3L).build();
// when
leftCouponStockInfo.decreaseCouponStock();
// then
assertEquals(leftCouponStockInfo.getRemainingAmount(), 0L);
}
}
Loading

0 comments on commit fe73c86

Please sign in to comment.