-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat : 티켓 상품 생성 #164
feat : 티켓 상품 생성 #164
Changes from 4 commits
b6805b3
dc783d4
9527785
b6da6e5
b7c8eda
03f9178
2a0e993
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package band.gosrock.api.ticketItem.controller; | ||
|
||
|
||
import band.gosrock.api.ticketItem.dto.request.CreateTicketItemRequest; | ||
import band.gosrock.api.ticketItem.dto.response.CreateTicketItemResponse; | ||
import band.gosrock.api.ticketItem.service.CreateTicketItemUseCase; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@SecurityRequirement(name = "access-token") | ||
@Tag(name = "티켓 상품 관련 컨트롤러") | ||
@RestController | ||
@RequestMapping("/v1/ticket_items") | ||
@RequiredArgsConstructor | ||
public class TicketItemController { | ||
|
||
public final CreateTicketItemUseCase createTicketItemUseCase; | ||
|
||
@Operation( | ||
summary = "특정 이벤트에 속하는 티켓 상품을 생성합니다.", | ||
description = "제휴 되지 않은 회원은 티켓 가격 0으로 강제해 보내주세요!") | ||
@PostMapping | ||
public CreateTicketItemResponse createTicketItem( | ||
@RequestBody @Valid CreateTicketItemRequest createTicketItemRequest) { | ||
return createTicketItemUseCase.execute(createTicketItemRequest); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package band.gosrock.api.ticketItem.dto.request; | ||
|
||
|
||
import band.gosrock.domain.common.vo.Money; | ||
import band.gosrock.domain.domains.event.domain.Event; | ||
import band.gosrock.domain.domains.ticket_item.domain.TicketItem; | ||
import band.gosrock.domain.domains.ticket_item.domain.TicketType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.lang.Nullable; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class CreateTicketItemRequest { | ||
|
||
@NotNull | ||
@Schema(nullable = false, example = "1") | ||
private Long eventId; | ||
|
||
@NotNull | ||
@Schema(nullable = false, defaultValue = "FIRST_COME_FIRST_SERVED") | ||
private TicketType type; | ||
|
||
@NotNull | ||
@Schema(nullable = false, example = "일반 티켓") | ||
private String name; | ||
|
||
@Nullable | ||
@Schema(nullable = true, example = "일반 입장 티켓입니다.") | ||
private String description; | ||
|
||
@NotNull | ||
@Schema(nullable = false, example = "4000") | ||
private Long price; | ||
|
||
@NotNull | ||
@Schema(nullable = false, example = "100") | ||
private Long supplyCount; | ||
|
||
@NotNull | ||
@Schema(nullable = false, example = "1") | ||
private Long purchaseLimit; | ||
|
||
public TicketItem toEntity(Event event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 처음에 request dto에 넣었었는데 mapper 만들어서 거기서 빌더쓰는 게 좀 더 깔끔해 보이는 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오케이 저두 리펙해보겠슴다 |
||
|
||
return TicketItem.builder() | ||
.type(type) | ||
.name(name) | ||
.description(description) | ||
.price(Money.wons(price)) | ||
.quantity(supplyCount) | ||
.supplyCount(supplyCount) | ||
.purchaseLimit(purchaseLimit) | ||
.isSellable(true) | ||
.event(event) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package band.gosrock.api.ticketItem.dto.response; | ||
|
||
|
||
import band.gosrock.domain.common.vo.Money; | ||
import band.gosrock.domain.domains.ticket_item.domain.TicketItem; | ||
import band.gosrock.domain.domains.ticket_item.domain.TicketType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class CreateTicketItemResponse { | ||
@Schema(description = "티켓상품 id") | ||
private final Long ticketItemId; | ||
|
||
@Schema(description = "이름") | ||
private final String ticketName; | ||
|
||
@Schema(description = "설명") | ||
private final String description; | ||
|
||
@Schema(description = "가격") | ||
private final Money price; | ||
|
||
@Schema(description = "티켓 타입") | ||
private final TicketType type; | ||
|
||
@Schema(description = "1인당 구매 제한 매수") | ||
private final Long purchaseLimit; | ||
|
||
@Schema(description = "공급량") | ||
private final Long supplyCount; | ||
|
||
@Schema(description = "재고") | ||
private final Long quantity; | ||
|
||
public static CreateTicketItemResponse from(TicketItem ticketItem) { | ||
|
||
return CreateTicketItemResponse.builder() | ||
.ticketItemId(ticketItem.getId()) | ||
.ticketName(ticketItem.getName()) | ||
.description(ticketItem.getDescription()) | ||
.price(ticketItem.getPrice()) | ||
.type(ticketItem.getType()) | ||
.purchaseLimit(ticketItem.getPurchaseLimit()) | ||
.supplyCount(ticketItem.getSupplyCount()) | ||
.quantity(ticketItem.getQuantity()) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package band.gosrock.api.ticketItem.service; | ||
|
||
|
||
import band.gosrock.api.common.UserUtils; | ||
import band.gosrock.api.ticketItem.dto.request.CreateTicketItemRequest; | ||
import band.gosrock.api.ticketItem.dto.response.CreateTicketItemResponse; | ||
import band.gosrock.common.annotation.UseCase; | ||
import band.gosrock.domain.common.vo.Money; | ||
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.host.service.HostService; | ||
import band.gosrock.domain.domains.ticket_item.domain.TicketItem; | ||
import band.gosrock.domain.domains.ticket_item.service.TicketItemService; | ||
import band.gosrock.domain.domains.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class CreateTicketItemUseCase { | ||
|
||
private final EventAdaptor eventAdaptor; | ||
private final HostAdaptor hostAdaptor; | ||
private final UserUtils userUtils; | ||
private final HostService hostService; | ||
private final TicketItemService ticketItemService; | ||
|
||
@Transactional | ||
public CreateTicketItemResponse execute(CreateTicketItemRequest createTicketItemRequest) { | ||
User user = userUtils.getCurrentUser(); | ||
Event event = eventAdaptor.findById(createTicketItemRequest.getEventId()); | ||
Host host = hostAdaptor.findById(event.getHostId()); | ||
// 권한 체크 ( 해당 이벤트의 호스트인지 ) | ||
hostService.hasHostUser(host, user.getId()); | ||
// 호스트 제휴 여부에 따른 가격 체크 | ||
if (!host.getPartner()) { | ||
ticketItemService.checkTicketPrice(Money.wons(createTicketItemRequest.getPrice())); | ||
} | ||
TicketItem ticketItem = | ||
ticketItemService.createTicketItem(createTicketItemRequest.toEntity(event)); | ||
return CreateTicketItemResponse.from(ticketItem); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 약간 이부분이 맘에 안들긴하는데.. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package band.gosrock.domain.domains.ticket_item.exception; | ||
|
||
|
||
import band.gosrock.common.exception.DuDoongCodeException; | ||
|
||
public class InvalidTicketPriceException extends DuDoongCodeException { | ||
|
||
public static final DuDoongCodeException EXCEPTION = new InvalidTicketPriceException(); | ||
|
||
private InvalidTicketPriceException() { | ||
super(TicketItemErrorCode.INVALID_TICKET_PRICE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package band.gosrock.domain.domains.ticket_item.service; | ||
|
||
|
||
import band.gosrock.common.annotation.DomainService; | ||
import band.gosrock.domain.common.vo.Money; | ||
import band.gosrock.domain.domains.ticket_item.adaptor.TicketItemAdaptor; | ||
import band.gosrock.domain.domains.ticket_item.domain.TicketItem; | ||
import band.gosrock.domain.domains.ticket_item.exception.InvalidTicketPriceException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@DomainService | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class TicketItemService { | ||
|
||
private final TicketItemAdaptor ticketItemAdaptor; | ||
|
||
@Transactional | ||
public TicketItem createTicketItem(TicketItem ticketItem) { | ||
return ticketItemAdaptor.save(ticketItem); | ||
} | ||
|
||
@Transactional | ||
public void checkTicketPrice(Money ticketPrice) { | ||
if (!Money.ZERO.equals(ticketPrice)) { | ||
throw InvalidTicketPriceException.EXCEPTION; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ticketItems 로 해유!
저희 이렇게 컨벤션 자연스래? 맞춰진것같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
뉑뉑