-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from lotteon2/sqs
✨ SQS publisher 작성
- Loading branch information
Showing
16 changed files
with
385 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kr.bb.store.client; | ||
|
||
|
||
import bloomingblooms.response.CommonResponse; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
@FeignClient(name = "user-service", url="${endpoint.user-service}") | ||
public interface UserClient { | ||
@GetMapping("/client/users/{userId}/phone-number") | ||
CommonResponse<String> getPhoneNumber(@PathVariable(name = "userId") Long userId); | ||
|
||
} |
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,41 @@ | ||
package kr.bb.store.config; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.sqs.AmazonSQSAsync; | ||
import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
|
||
@Configuration | ||
public class AWSConfiguration { | ||
@Value("${cloud.aws.credentials.ACCESS_KEY_ID}") | ||
private String accessKeyId; | ||
|
||
@Value("${cloud.aws.credentials.SECRET_ACCESS_KEY}") | ||
private String secretAccessKey; | ||
|
||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
public AwsCredentialsProvider getAwsCredentials() { | ||
AwsBasicCredentials awsBasicCredentials = | ||
AwsBasicCredentials.create(accessKeyId, secretAccessKey); | ||
return () -> awsBasicCredentials; | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public AmazonSQSAsync amazonSQSAsync() { | ||
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKeyId, secretAccessKey); | ||
return AmazonSQSAsyncClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials)) | ||
.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
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
56 changes: 56 additions & 0 deletions
56
src/main/java/kr/bb/store/domain/question/facade/QuestionFacade.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,56 @@ | ||
package kr.bb.store.domain.question.facade; | ||
|
||
import kr.bb.store.client.UserClient; | ||
import kr.bb.store.domain.question.controller.request.QuestionCreateRequest; | ||
import kr.bb.store.domain.question.controller.response.*; | ||
import kr.bb.store.domain.question.entity.Question; | ||
import kr.bb.store.domain.question.service.QuestionService; | ||
import kr.bb.store.message.AnswerSQSPublisher; | ||
import kr.bb.store.message.QuestionSQSPublisher; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class QuestionFacade { | ||
private final QuestionService questionService; | ||
private final QuestionSQSPublisher questionSQSPublisher; | ||
private final AnswerSQSPublisher answerSQSPublisher; | ||
private final UserClient userClient; | ||
|
||
public void createQuestion(Long userId, QuestionCreateRequest questionCreateRequest) { | ||
questionService.createQuestion(userId, questionCreateRequest); | ||
Long storeId = questionCreateRequest.getStoreId(); | ||
questionSQSPublisher.publish(storeId); | ||
} | ||
|
||
public QuestionDetailInfoResponse getQuestionInfo(Long questionId) { | ||
return questionService.getQuestionInfo(questionId); | ||
} | ||
|
||
public void createAnswer(Long questionId, String content) { | ||
questionService.createAnswer(questionId, content); | ||
Question question = questionService.getQuestionById(questionId); | ||
Long userId = question.getUserId(); | ||
String phoneNumber = userClient.getPhoneNumber(userId).getData(); | ||
answerSQSPublisher.publish(userId, phoneNumber); | ||
} | ||
|
||
public QuestionsForOwnerPagingResponse getQuestionsForStoreOwner(Long storeId, Boolean isReplied, Pageable pageable) { | ||
return questionService.getQuestionsForStoreOwner(storeId, isReplied, pageable); | ||
} | ||
|
||
public QuestionsInProductPagingResponse getQuestionsInProduct(Long userId, String productId, Boolean isReplied, Pageable pageable) { | ||
return questionService.getQuestionsInProduct(userId, productId, isReplied, pageable); | ||
} | ||
|
||
public MyQuestionsInProductPagingResponse getMyQuestionsInProduct(Long userId, String productId, Boolean isReplied, Pageable pageable) { | ||
return questionService.getMyQuestionsInProduct(userId, productId, isReplied, pageable); | ||
} | ||
|
||
public MyQuestionsInMypagePagingResponse getMyQuestions(Long userId, Boolean isReplied, Pageable pageable) { | ||
return questionService.getMyQuestions(userId, isReplied, pageable); | ||
} | ||
|
||
} |
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.