-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
전남대 BE_나제법 5주차 과제(2단계) #303
Open
nove1080
wants to merge
84
commits into
kakao-tech-campus-2nd-step2:nove1080
Choose a base branch
from
nove1080:step2
base: nove1080
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 73 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
5123667
init: 4주차 코드 업로드
nove1080 e9daf63
docs: README.md Step5 1단계 요구사항 반영
nove1080 7efd229
chore: build.gradle OpenFeign 의존성 추가
nove1080 0a0504e
feat: KakaoClient.java 추가
nove1080 1d4ff4d
feat: KakaoInfo.java 추가
nove1080 3e12882
feat: KakaoProfile.java 추가
nove1080 f9ebe69
feat: KakaoProperties.java 추가
nove1080 e52db54
feat: KakaoToken.java 추가
nove1080 6f3cf67
feat: KakaoAccount.java 추가
nove1080 e1ea3bb
feat: LoginService.java 추가
nove1080 12cfa98
feat: LoginResponse.java 필드명 변경
nove1080 2fb0b8d
feat: MemberService.java findOrCreateMember() 추가
nove1080 6f2c4b1
feat: Member.java Password 필드 삭제
nove1080 1102c74
feat: KakaoAccount.java toMember() 추가
nove1080 a83c654
feat: AuthenticationFilter.java ignorePaths 변경
nove1080 f2e2b93
feat: CreateMemberRequest.java Password 필드 삭제
nove1080 489f789
feat: WebConfig.java feignClient 추가
nove1080 8734b45
feat: data.sql Member 테이블 password 필드 삭제
nove1080 d712d3f
feat: JwtProvider.java Token 생성 시, SocialToken 클레임 추가
nove1080 db2e428
feat: JwtResolver.java resolveSocialToken 추가
nove1080 6d6c1ae
refactor: MemberService.java findOrCreateMember 회원 생성 시 dto 사용
nove1080 60a31a4
feat: ReadMemberResponse.java password 필드 삭제
nove1080 f5e2c2d
remove: 사용하지 않는 파일 제거
nove1080 2fbf175
feat: LoginController.java 추가
nove1080 4df68c1
feat: Application.java 어노테이션 추가
nove1080 0e270a1
test: MemberDummyDataProvider.java Password 필드 제거
nove1080 512fb5c
test: MemberServiceTest.java MemberService 변경에 따른 수정
nove1080 96c3bc5
test: MemberApiControllerTest.java 주석 처리
nove1080 0fd0b11
feat: MemberApiController.java 단일 회원 조회 API 추가
nove1080 2df743f
chore: .gitignore application-secret.yml 추가
nove1080 45ced48
removed cached
nove1080 ff75fd3
Merge branch 'nove1080' into step1
nove1080 f4a7c77
docs: README.md step5 2단계 요구사항 반영
nove1080 c2f5566
feat: Password.java 추가
nove1080 1a0e449
feat: Platform.java 추가
nove1080 b52b12a
feat: Member.java password, platform 필드 추가
nove1080 595ce3d
feat: MemberDetails.java platform 필드 추가
nove1080 bdad4aa
feat: LoginRequest.java 추가
nove1080 697f03d
feat: MemberService.java login() 추가
nove1080 11130e8
refactor: Product.java 사용하지 않는 메서드 삭제
nove1080 3b0b785
feat: CreateMemberRequest.java password 필드 추가
nove1080 7a68629
feat: ReadMemberResponse.java password 필드 추가
nove1080 e62bf41
chore: data.sql member의 password 필드 추가
nove1080 8acbdeb
feat: AuthenticationFilter.java ignorePaths 추가 등록
nove1080 9ef54f6
refactor: KakaoAccount.java Member 변환 로직 수정
nove1080 9ef88e9
test: 테스트 코드 수정
nove1080 e0b14df
feat: MemberApiController.java 회원가입/로그인 구현
nove1080 7835c2b
Merge remote-tracking branch 'origin/step1' into step1
nove1080 37cd143
feat: ProductViewController.java form 화면 추가
nove1080 9732f2b
feat: MemberDetails.java getEmailValue() 추가
nove1080 c8b954b
feat: script.js
nove1080 b61599c
feat: login-callback.html 추가
nove1080 74dca82
feat: login-call.html 추가
nove1080 9093d5a
feat: register-form.html 추가
nove1080 c5436da
refactor: index.html 주소변경
nove1080 5c338df
docs: README.md step5 2단계 요구사항 반영
nove1080 173b1b3
Merge remote-tracking branch 'origin/step2' into step2
nove1080 7ab1d22
Merge branch 'nove1080' into step2
nove1080 81385f0
feat: Token.java fromBearer() 추가
nove1080 1bbf57b
feat: KakaoClient.java sendMessage() 추가
nove1080 b786ed0
feat: KakaoCommerce.java 추가
nove1080 859b8bb
feat: KakaoMessageResult.java 추가
nove1080 099f45f
feat: CreateOrderRequest.java 추가
nove1080 15fb123
feat: KakaoProperties.java messageUrl 필드 추가
nove1080 9fe6cb3
feat: OrderResponse.java 추가
nove1080 0fd1a92
feat: ProductOptionService.java validateExistsProduct() 추가
nove1080 2fcfc26
feat: ReadProductResponse.java Options 필드 추가
nove1080 08c2fef
feat: OrderService.java 추가
nove1080 d32f7a1
feat: ProductApiController.java 상품 주문 API 구현
nove1080 a2a6af5
refactor: LoginService.java 리팩토링
nove1080 55a3efa
feat: script.js 사용하지 않는 함수 제거
nove1080 6425fc1
feat: ProductViewController.java loginForm() modelAttribute 추가
nove1080 e34cbd4
refactor: login-form.html 민감한 정보 제거
nove1080 abcf464
refactor: ReadProductResponse.java fromEntity 코드 리팩토링
nove1080 3da6446
feat: Order.java 추가
nove1080 7564f1a
feat: OrderRepository.java 추가
nove1080 3b5f4ff
feat: OrderResponse.java 불필요한 필드 제거 및 fromEntity 추가
nove1080 0ce5bb7
feat: OrderStatus.java 추가
nove1080 b304b28
feat: CreateOrderRequest.java toEntity() 추가
nove1080 eed7e4e
feat: OrderService.java 코드 리팩토링 및 주문 정보 저장 로직 추가
nove1080 9c32ba4
feat: ProductApiController.java 주문 생성 API MemberDetail 파라미터 추가
nove1080 0ecae3f
style: ReadProductResponse.java 줄바꿈 추가
nove1080 15ca808
feat: OrderRepository.java @Repository 추가
nove1080 0a7c565
feat: OrderService.java @Transactional(readOnly = true) 제거
nove1080 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,71 @@ | ||
package gift.service; | ||
|
||
import gift.authentication.token.JwtResolver; | ||
import gift.authentication.token.Token; | ||
import gift.config.KakaoProperties; | ||
import gift.web.client.KakaoClient; | ||
import gift.web.client.dto.KakaoCommerce; | ||
import gift.web.dto.request.order.CreateOrderRequest; | ||
import gift.web.dto.response.order.OrderResponse; | ||
import gift.web.dto.response.product.ReadProductResponse; | ||
import gift.web.dto.response.productoption.SubtractProductOptionQuantityResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
public class OrderService { | ||
|
||
private final KakaoClient kakaoClient; | ||
private final JwtResolver jwtResolver; | ||
private final ProductOptionService productOptionService; | ||
private final ProductService productService; | ||
private final KakaoProperties kakaoProperties; | ||
|
||
public OrderService(KakaoClient kakaoClient, JwtResolver jwtResolver, ProductOptionService productOptionService, | ||
ProductService productService, KakaoProperties kakaoProperties) { | ||
this.kakaoClient = kakaoClient; | ||
this.jwtResolver = jwtResolver; | ||
this.productOptionService = productOptionService; | ||
this.productService = productService; | ||
this.kakaoProperties = kakaoProperties; | ||
} | ||
|
||
@Transactional | ||
public OrderResponse createOrder(String accessToken, Long productId, CreateOrderRequest request) { | ||
//상품 옵션 수량 차감 | ||
SubtractProductOptionQuantityResponse subtractOptionStockResponse = productOptionService.subtractOptionStock(request); | ||
|
||
ReadProductResponse product = productService.readProductById(productId); | ||
KakaoCommerce kakaoCommerce = KakaoCommerce.of(product, request.getMessage()); | ||
|
||
sendOrderMessageIfSocialMember(accessToken, kakaoCommerce); | ||
return new OrderResponse( | ||
productId, | ||
request.getOptionId(), | ||
subtractOptionStockResponse.getStock(), | ||
request.getQuantity(), | ||
product.getName(), | ||
request.getMessage()); | ||
} | ||
|
||
/** | ||
* 소셜 로그인을 통해 주문한 경우 카카오톡 메시지를 전송합니다 | ||
* @param accessToken Bearer Token | ||
* @param kakaoCommerce 카카오 상거래 메시지 | ||
*/ | ||
private void sendOrderMessageIfSocialMember(String accessToken, KakaoCommerce kakaoCommerce) { | ||
jwtResolver.resolveSocialToken(Token.fromBearer(accessToken)) | ||
.ifPresent(socialToken -> { | ||
String json = kakaoCommerce.toJson(); | ||
kakaoClient.sendMessage( | ||
kakaoProperties.getMessageUrlAsUri(), | ||
getBearerToken(socialToken), | ||
json); | ||
}); | ||
} | ||
|
||
private String getBearerToken(String token) { | ||
return "Bearer " + token; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
카카오톡 메시지 전송하는건 같은 트랜잭션에 묶일 필요가 있을까요?
주문 및 수량 차감은 핵심 로직인데, 카카오톡 메시지 전송 api 가 실패해서 주문까지 실패하면 안될 . 것같아요
외부 api를 사용할 때는 이런 트랜잭션에 대해서 잘 고려해야됩니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 그리고 주문 데이터는 따로 저장안할까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
과제 진행이 좀 늦어져서 제출기한을 고려할 때 빠듯할 것 같아서 주문 데이터를 저장하는 부분은 만들지 않았습니다! 이제 만들도록 하겠습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 생각하지 못했네요 아무 생각없이 트랜잭션으로 묶었던 것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 동건님! 리팩토링을 하는 과정에서 궁금한 부분이 있어서 여쭤보고 싶습니다!
주문 도메인이 추가되면서 주문 생성 시, 해당 주문을 DB에 저장하도록 구현하였습니다.
이 때, 주문 저장 로직이 추가되면서 해당 메서드를 트랜잭션으로 묶어야겠다고 생각했습니다.
주문 정보 저장이 실패하였지만, 상품 옵션 수량이 차감되는 문제가 발생할 수 있어 같은 트랜잭션에서 수행되도록 하는 것이 좋겠다고 생각했습니다.
그런데 이 경우에는 카카오 메시지 전송에 실패하여 주문이 생성되지 않는 경우도 존재하는데
Q1. 이런 경우에는 이 부분만 트랜잭션에서 제외시켜줄 수 있나요? 그러지 못한다면 일종의 트레이드 오프라고 생각해야할까요?
Q2. 만약 트랜잭션을 붙이지 않은 경우
코드의 실행 순서 상
상품 옵션 수량 차감
이 먼저 수행되기 때문에주문 정보를 저장
에 성공한 경우에는 100% 상품 옵션 수량이 성공적으로 차감되었다고 보장할 수 있나요?한 트랜잭션 안에서 실행되지 않은 작업들은 실행 순서를 신중하게 고려해야하나요?