-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feat: 장바구니 옵션 수정 API 구현 및 장바구니 담기 API 수정
- Loading branch information
1 parent
32d6d4f
commit b07b383
Showing
11 changed files
with
186 additions
and
19 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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/umc/TheGoods/repository/cart/CartRepository.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,7 +1,17 @@ | ||
package com.umc.TheGoods.repository.cart; | ||
|
||
import com.umc.TheGoods.domain.item.Item; | ||
import com.umc.TheGoods.domain.item.ItemOption; | ||
import com.umc.TheGoods.domain.member.Member; | ||
import com.umc.TheGoods.domain.order.Cart; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface CartRepository extends JpaRepository<Cart, Long> { | ||
|
||
Optional<Cart> findByMemberAndItemAndItemOption(Member member, Item item, ItemOption itemOption); | ||
|
||
Optional<Cart> findByMemberAndItem(Member member, Item item); | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/umc/TheGoods/service/CartService/CartCommandService.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,9 +1,12 @@ | ||
package com.umc.TheGoods.service.CartService; | ||
|
||
import com.umc.TheGoods.domain.member.Member; | ||
import com.umc.TheGoods.domain.order.Cart; | ||
import com.umc.TheGoods.web.dto.cart.CartRequestDTO; | ||
|
||
public interface CartCommandService { | ||
|
||
void addCart(CartRequestDTO.cartAddDTO request, Member member); | ||
|
||
Cart updateCart(CartRequestDTO.cartUpdateDTO request, Member member); | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/umc/TheGoods/service/CartService/CartQueryService.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,6 @@ | ||
package com.umc.TheGoods.service.CartService; | ||
|
||
public interface CartQueryService { | ||
|
||
boolean isExistCart(Long cartId); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/umc/TheGoods/service/CartService/CartQueryServiceImpl.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,20 @@ | ||
package com.umc.TheGoods.service.CartService; | ||
|
||
import com.umc.TheGoods.repository.cart.CartRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CartQueryServiceImpl implements CartQueryService { | ||
|
||
private final CartRepository cartRepository; | ||
|
||
|
||
@Override | ||
public boolean isExistCart(Long cartId) { | ||
return cartRepository.existsById(cartId); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/umc/TheGoods/validation/annotation/ExistCart.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 com.umc.TheGoods.validation.annotation; | ||
|
||
import com.umc.TheGoods.validation.validator.CartExistValidator; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Constraint(validatedBy = CartExistValidator.class) | ||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ExistCart { | ||
String message() default "해당 장바구니 내역을 찾을 수 없습니다."; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/umc/TheGoods/validation/validator/CartExistValidator.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,32 @@ | ||
package com.umc.TheGoods.validation.validator; | ||
|
||
import com.umc.TheGoods.apiPayload.code.status.ErrorStatus; | ||
import com.umc.TheGoods.service.CartService.CartQueryService; | ||
import com.umc.TheGoods.validation.annotation.ExistCart; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CartExistValidator implements ConstraintValidator<ExistCart, Long> { | ||
|
||
private final CartQueryService cartQueryService; | ||
|
||
@Override | ||
public void initialize(ExistCart constraintAnnotation) { | ||
ConstraintValidator.super.initialize(constraintAnnotation); | ||
} | ||
|
||
@Override | ||
public boolean isValid(Long value, ConstraintValidatorContext context) { | ||
boolean isValid = cartQueryService.isExistCart(value); | ||
if (!isValid) { | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate(ErrorStatus.CART_NOT_FOUND.getMessage()).addConstraintViolation(); | ||
} | ||
return isValid; | ||
} | ||
} |
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