Skip to content

Commit

Permalink
refactor(ticketItem) : 티켓 재고 숨기기 기능 추가 / 어드미용 조회 API 생성 (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-wonjin authored Feb 12, 2023
1 parent 4ebedfe commit f73c514
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
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);
}
}

0 comments on commit f73c514

Please sign in to comment.