-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π :: Api-v0.0.5
- Loading branch information
Showing
97 changed files
with
1,738 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
DuDoong-Api/src/main/java/band/gosrock/api/cart/docs/CreateCartExceptionDocs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package band.gosrock.api.cart.docs; | ||
|
||
|
||
import band.gosrock.common.annotation.ExceptionDoc; | ||
import band.gosrock.common.annotation.ExplainError; | ||
import band.gosrock.common.exception.DuDoongCodeException; | ||
import band.gosrock.common.interfaces.SwaggerExampleExceptions; | ||
import band.gosrock.domain.domains.cart.exception.CartInvalidItemKindPolicyException; | ||
import band.gosrock.domain.domains.cart.exception.CartInvalidOptionAnswerException; | ||
|
||
@ExceptionDoc | ||
public class CreateCartExceptionDocs implements SwaggerExampleExceptions { | ||
|
||
@ExplainError("μμ΄ν μ λν μ΅μ μ λν μλ΅μ μ¬λ°λ₯΄κ² μνμλ ( ν μ΅μ κ·Έλ£Ήμ ν μλ΅, μ΅μ κ·Έλ£Ήμ μλ΅μνμλ)") | ||
public DuDoongCodeException μλ΅_μ¬λ°λ₯΄κ²_μνμ_λ = CartInvalidOptionAnswerException.EXCEPTION; | ||
|
||
@ExplainError("μΉ΄νΈλ₯Ό λ΄μ λ ν μμ΄ν μ’ λ₯ ( ν μμ΄λλ‘λ§ λ΄μμ£ΌμΈμ ), μ μ± μλ°μ λλ€.") | ||
public DuDoongCodeException ν_μ’ λ₯_μμ΄ν λ§_μ₯λ°κ΅¬λμ = CartInvalidItemKindPolicyException.EXCEPTION; | ||
} |
24 changes: 2 additions & 22 deletions
24
DuDoong-Api/src/main/java/band/gosrock/api/cart/model/dto/request/AddCartLineDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,20 @@ | ||
package band.gosrock.api.cart.model.dto.request; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
import javax.validation.constraints.Min; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class AddCartLineDto { | ||
@Schema(description = "μ£Όλ¬Έν μμ΄ν μμ΄λ", defaultValue = "1") | ||
private final Long itemId; | ||
private Long itemId; | ||
|
||
@Schema(description = "μν μλ", defaultValue = "1") | ||
@Min(1) | ||
private final Long quantity; | ||
private Long quantity; | ||
|
||
@Schema(description = "μν κ΄λ ¨ μ΅μ μ λν λ΅λ³") | ||
private List<AddCartOptionAnswerDto> options; | ||
|
||
@JsonIgnore | ||
public List<Long> getOptionIds() { | ||
return options.stream().map(AddCartOptionAnswerDto::getOptionId).toList(); | ||
} | ||
|
||
// public CartLineItem toCartLineItem(Long userId) { | ||
// List<CartOptionAnswer> cartOptionAnswers = | ||
// addCartOptionAnswerDtos.stream() | ||
// .map(AddCartOptionAnswerDto::toCartOptionAnswer) | ||
// .toList(); | ||
// return CartLineItem.builder() | ||
// .itemId(itemId) | ||
// .quantity(quantity) | ||
// .cartOptionAnswers(cartOptionAnswers) | ||
// .build(); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
DuDoong-Api/src/main/java/band/gosrock/api/cart/model/mapper/CartMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package band.gosrock.api.cart.model.mapper; | ||
|
||
|
||
import band.gosrock.api.cart.model.dto.request.AddCartLineDto; | ||
import band.gosrock.api.cart.model.dto.request.AddCartOptionAnswerDto; | ||
import band.gosrock.api.cart.model.dto.request.AddCartRequest; | ||
import band.gosrock.api.cart.model.dto.response.CartItemResponse; | ||
import band.gosrock.api.cart.model.dto.response.CartResponse; | ||
import band.gosrock.common.annotation.Mapper; | ||
import band.gosrock.domain.domains.cart.adaptor.CartAdaptor; | ||
import band.gosrock.domain.domains.cart.domain.Cart; | ||
import band.gosrock.domain.domains.cart.domain.CartLineItem; | ||
import band.gosrock.domain.domains.cart.domain.CartOptionAnswer; | ||
import band.gosrock.domain.domains.ticket_item.adaptor.OptionAdaptor; | ||
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.repository.OptionRepository; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Mapper | ||
@RequiredArgsConstructor | ||
public class CartMapper { | ||
private final TicketItemAdaptor ticketItemAdaptor; | ||
private final OptionAdaptor optionAdaptor; | ||
private final OptionRepository optionRepository; | ||
|
||
private final CartAdaptor cartAdaptor; | ||
|
||
@Transactional(readOnly = true) | ||
public CartResponse toCartResponse(Long cartId) { | ||
Cart cart = cartAdaptor.queryCart(cartId); | ||
return getCartResponse(cart); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public CartResponse toCartResponse(Cart cart) { | ||
return getCartResponse(cart); | ||
} | ||
|
||
private CartResponse getCartResponse(Cart cart) { | ||
List<CartLineItem> newCartLineItems = cart.getCartLineItems(); | ||
Long totalQuantity = cart.getTotalQuantity(); | ||
|
||
List<CartItemResponse> cartItemResponses = | ||
getCartItemResponses(newCartLineItems, totalQuantity); | ||
|
||
return CartResponse.of(cartItemResponses, cart); | ||
} | ||
|
||
private List<CartItemResponse> getCartItemResponses( | ||
List<CartLineItem> newCartLineItems, Long totalQuantity) { | ||
int startNum = 1; | ||
List<CartItemResponse> cartItemResponses = new ArrayList<>(); | ||
for (CartLineItem cartLineItem : newCartLineItems) { | ||
cartItemResponses.add( | ||
CartItemResponse.of( | ||
generateCartLineName(cartLineItem, startNum, totalQuantity), | ||
cartLineItem)); | ||
startNum += cartLineItem.getQuantity(); | ||
} | ||
return cartItemResponses; | ||
} | ||
|
||
public Cart toEntity(AddCartRequest addCartRequest, Long currentUserId) { | ||
List<AddCartLineDto> addCartLineDtos = addCartRequest.getItems(); | ||
|
||
List<CartLineItem> cartLineItems = | ||
addCartLineDtos.stream() | ||
.map( | ||
addCartLineDto -> | ||
CartLineItem.builder() | ||
.ticketItem(getTicketItem(addCartLineDto)) | ||
.cartOptionAnswers( | ||
getCartOptionAnswers(addCartLineDto)) | ||
.quantity(addCartLineDto.getQuantity()) | ||
.build()) | ||
.toList(); | ||
return Cart.builder().cartLineItems(cartLineItems).userId(currentUserId).build(); | ||
} | ||
|
||
@NotNull | ||
private TicketItem getTicketItem(AddCartLineDto addCartLineDto) { | ||
return ticketItemAdaptor.queryTicketItem(addCartLineDto.getItemId()); | ||
} | ||
|
||
/** | ||
* μΌλ°ν°μΌ(1/3) - 4000μ κ³Ό κ°μ μ₯λ°κ΅¬λ μνμ μλ΅μ λ°νν©λλ€ μΉ΄νΈλΌμΈ κΈ°μ€μ λλ€. μΉ΄νΈλΌμΈμ 3κ°μ μνμ΄ κ°μ΄ λ΄κΈ°λ©΄ ( μ΅μ μ΄ κ°μ μν© ) | ||
* μΌλ°ν°μΌ(1-3/3) μ΄λ°μμΌλ‘ ννλ©λλ€. | ||
* | ||
* @param cartLineItem | ||
* @param startNum | ||
* @param totalQuantity | ||
* @return | ||
*/ | ||
private String generateCartLineName( | ||
CartLineItem cartLineItem, int startNum, Long totalQuantity) { | ||
Long cartLineQuantity = cartLineItem.getQuantity(); | ||
if (cartLineQuantity.equals(1L)) { | ||
return String.format( | ||
"%s (%s/%d) - %s", | ||
cartLineItem.getTicketName(), | ||
startNum, | ||
totalQuantity, | ||
cartLineItem.getTotalCartLinePrice().toString()); | ||
} | ||
int endNum = (int) (cartLineQuantity - 1 + startNum); | ||
return String.format( | ||
"%s (%s/%d) - %s", | ||
cartLineItem.getTicketName(), | ||
startNum + "-" + endNum, | ||
totalQuantity, | ||
cartLineItem.getTotalCartLinePrice().toString()); | ||
} | ||
|
||
private List<CartOptionAnswer> getCartOptionAnswers(AddCartLineDto addCartLineDto) { | ||
return addCartLineDto.getOptions().stream().map(this::getCartOptionAnswer).toList(); | ||
} | ||
|
||
private CartOptionAnswer getCartOptionAnswer(AddCartOptionAnswerDto addCartOptionAnswerDto) { | ||
return CartOptionAnswer.builder() | ||
.option(optionAdaptor.queryOption(addCartOptionAnswerDto.getOptionId())) | ||
.answer(addCartOptionAnswerDto.getAnswer()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.