-
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.
- Loading branch information
Showing
4 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
api-module/src/main/java/com/likelion/apimodule/cart/application/CartSaveUseCase.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,34 @@ | ||
package com.likelion.apimodule.cart.application; | ||
|
||
import com.likelion.apimodule.cart.dto.CartSaveReq; | ||
import com.likelion.apimodule.security.util.JwtUtil; | ||
import com.likelion.coremodule.cart.domain.Cart; | ||
import com.likelion.coremodule.cart.service.CartQueryService; | ||
import com.likelion.coremodule.menu.domain.Menu; | ||
import com.likelion.coremodule.menu.service.MenuQueryService; | ||
import com.likelion.coremodule.user.application.UserQueryService; | ||
import com.likelion.coremodule.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CartSaveUseCase { | ||
|
||
private final CartQueryService cartQueryService; | ||
private final JwtUtil jwtUtil; | ||
private final UserQueryService userQueryService; | ||
private final MenuQueryService menuQueryService; | ||
|
||
public void saveMyCart(String accessToken, CartSaveReq saveReq) { | ||
|
||
String email = jwtUtil.getEmail(accessToken); | ||
User user = userQueryService.findByEmail(email); | ||
|
||
Menu menu = menuQueryService.findMenuById(saveReq.menuId()); | ||
|
||
final Cart cart = Cart.builder().user(user).menu(menu).quantity(saveReq.quantity()).build(); | ||
cartQueryService.saveCart(cart); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
api-module/src/main/java/com/likelion/apimodule/cart/dto/CartSaveReq.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,7 @@ | ||
package com.likelion.apimodule.cart.dto; | ||
|
||
public record CartSaveReq( | ||
Long menuId, | ||
Integer 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