-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 지난주차 코드 가져옴 feat: 지난주차 코드 가져옴 * feat: schema.sql 업데이트 - 카테고리 추가 - product 도메인 수정 * feat: Category 도메인 추가 * feat: Category 도메인 추가 feat: Category 도메인 추가 * feat: 위시리스트 생성 로직 수정 - 위시 리스트를 생성한다 * feat: 로그인 토큰 앞에 Bearer * feat: 유저 조회 API 생성 * refactor: user 로그인 후 위시리스트에 상품을 추가할 수 있다 * feat: 카테고리 생성/조회 로직 추가 - 카테고리 조회 - 카테고리 추가 * refactor: code style 통일 - intellij 코드 스타일 적용이 안되고 있었네요 - 전체 파일 일괄 적용시켜줬습니다. * feat: 연관관계 설정 - Product & Category 연관관계 설정 * feat: 카테고리 도메인 추가 - 카테고리 생성 - 카테고리 프로퍼티 추가 (색상, 이미지, 설명) - schema.sql 추가 * feat: 상품 추가 로직 카테고리 validate - 상품 추가시 필수적으로 상품 카테고리 추가 - validate 카테고리 * docs: README.md * refactor: jwt 의존성 버전업 - 0.11.5 -> 0.12.3 * refactor: jwt 의존성 버전업 - 0.11.5 -> 0.12.3 * feat: user Role 포함 * feat: role 기반 인가 - 상품/카테고리 생성 자체는 ADMIN만 가능하다 * feat: 카테고리 생성 관리자 인가 * feat: Product Option 도메인 추가 * feat: 가격은 제외 * feat: 상품 옵션 추가 API 구현 - 관리자는 상품 옵션을 추가할 수 있다 - 동일한 이름의 옵션은 추가할 수 없다 * feat: WishList 레포지토리 분리 - Jpa 레포지토리/순수 Java 레포지토리 분리 * feat: WishList 레포지토리 분리 - Jpa 레포지토리/순수 Java 레포지토리 분리 * feat: WishList 레포지토리 분리 - Jpa 레포지토리/순수 Java 레포지토리 분리 * feat: 상품 옵션 선택해서 추가 - 회원이 위시리스트에 상품을 추가할 때 option id까지 추가하도록 한다 * feat: kakao id는 여기 없는데 왜 추가한거지? * feat: 구매 로직 구현 - 구매를 수행할 경우 stoke -- * feat: 상품에 대한 개수 추가 * feat: quentity type 수정 - Long * feat: 클래스단위 read only 해제 * refactor: Category 생성자 수정 - 파라미터 분해 x * refactor: ProductOption 생성자 수정 - 파라미터 분해 x * refactor: Product 생성자 수정 - 파라미터 분해 x * refactor: WishList 생성자 수정 - 파라미터 분해 x
- Loading branch information
Showing
14 changed files
with
217 additions
and
47 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/gift/payment/application/PaymentService.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,44 @@ | ||
package gift.payment.application; | ||
|
||
import gift.product.domain.Product; | ||
import gift.product.domain.ProductOption; | ||
import gift.product.domain.WishList; | ||
import gift.product.domain.WishListProduct; | ||
import gift.product.exception.ProductException; | ||
import gift.product.infra.ProductRepository; | ||
import gift.product.infra.WishListRepository; | ||
import gift.util.ErrorCode; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Objects; | ||
|
||
@Service | ||
public class PaymentService { | ||
|
||
private final WishListRepository wishListRepository; | ||
private final ProductRepository productRepository; | ||
|
||
public PaymentService(WishListRepository wishListRepository, ProductRepository productRepository) { | ||
this.wishListRepository = wishListRepository; | ||
this.productRepository = productRepository; | ||
} | ||
|
||
@Transactional | ||
public void processPayment(Long userId, Long wishListId) { | ||
WishList wishList = wishListRepository.findById(wishListId); | ||
|
||
if (!Objects.equals(wishList.getUser().getId(), userId)) { | ||
throw new ProductException(ErrorCode.NOT_USER_OWNED); | ||
} | ||
|
||
for (WishListProduct product : wishList.getWishListProducts()) { | ||
Product wishListProduct = product.getProduct(); | ||
ProductOption productOption = product.getProductOption(); | ||
productOption.decreaseQuantity(product.getQuantity()); | ||
|
||
productRepository.save(wishListProduct); | ||
} | ||
wishListRepository.delete(wishList); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/gift/payment/controller/PaymentController.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,33 @@ | ||
package gift.payment.presentation; | ||
|
||
import gift.payment.application.PaymentService; | ||
import gift.util.CommonResponse; | ||
import gift.util.annotation.JwtAuthenticated; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/payment") | ||
public class PaymentController { | ||
|
||
private final PaymentService paymentService; | ||
|
||
public PaymentController(PaymentService paymentService) { | ||
this.paymentService = paymentService; | ||
} | ||
|
||
@PostMapping("/process/{wishListId}") | ||
@JwtAuthenticated | ||
public ResponseEntity<?> processPayment(@PathVariable Long wishListId) { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
Long userId = Long.valueOf(authentication.getName()); | ||
|
||
paymentService.processPayment(userId, wishListId); | ||
return ResponseEntity.ok(new CommonResponse<>( | ||
null, "결제 완료", true | ||
)); | ||
} | ||
|
||
} |
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
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,37 @@ | ||
package gift.product.domain; | ||
|
||
public class AddWishListRequest { | ||
private Long userId; | ||
private Long wishlistId; | ||
private Long productId; | ||
private Long optionId; | ||
private Long quantity; | ||
|
||
public Long getUserId() { | ||
return userId; | ||
} | ||
|
||
public Long getWishlistId() { | ||
return wishlistId; | ||
} | ||
|
||
public Long getProductId() { | ||
return productId; | ||
} | ||
|
||
public Long getOptionId() { | ||
return optionId; | ||
} | ||
|
||
public Long getQuantity() { | ||
return quantity; | ||
} | ||
|
||
public AddWishListRequest(Long userId, Long wishlistId, Long productId, Long optionId, Long quantity) { | ||
this.userId = userId; | ||
this.wishlistId = wishlistId; | ||
this.productId = productId; | ||
this.optionId = optionId; | ||
this.quantity = quantity; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gift.product.infra; | ||
|
||
import gift.product.domain.WishList; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public class WishListRepository { | ||
private final WishListJpaRepository wishListJpaRepository; | ||
|
||
public WishListRepository(WishListJpaRepository wishListJpaRepository) { | ||
this.wishListJpaRepository = wishListJpaRepository; | ||
} | ||
|
||
public WishList findByUserId(Long userId) { | ||
return wishListJpaRepository.findByUserId(userId) | ||
.orElseThrow(() -> new IllegalArgumentException("해당 ID의 위시리스트가 존재하지 않습니다.")); | ||
} | ||
|
||
public Page<WishList> findByUserId(Long userId, Pageable pageable) { | ||
return wishListJpaRepository.findByUserId(userId, pageable); | ||
} | ||
|
||
public void save(WishList wishList) { | ||
wishListJpaRepository.save(wishList); | ||
} | ||
|
||
public WishList findById(Long id) { | ||
return wishListJpaRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("해당 ID의 위시리스트가 존재하지 않습니다.")); | ||
} | ||
|
||
public void delete(WishList wishList) { | ||
wishListJpaRepository.delete(wishList); | ||
} | ||
} |
Oops, something went wrong.