Skip to content

Commit

Permalink
Merge pull request #49 from KUSITMS-30th-TEAM-A/feature/#47/s3
Browse files Browse the repository at this point in the history
[feat] : 구역 추천 결과 - 프로필 정보 조회 시 이미지를 함께 반환한다
  • Loading branch information
bbbang105 authored Nov 6, 2024
2 parents c1fed80 + cddfe77 commit 5ee0b96
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 9 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ dependencies {

// MacOS Silicon 라이브러리 누락 문제
runtimeOnly 'io.netty:netty-resolver-dns-native-macos:4.1.104.Final:osx-aarch_64'

// S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
}

ext {
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/kusitms/backend/global/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package kusitms.backend.global.config;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.BucketCrossOriginConfiguration;
import com.amazonaws.services.s3.model.CORSRule;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class S3Config {

@Value("${cloud.aws.credentials.access-key}")
private String accessKey;

@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;

@Value("${cloud.aws.region.static}")
private String region;

@Value("${cloud.aws.s3.endpoint}")
private String endPoint;

@Value("${cloud.aws.credentials.bucket}")
private String bucketName;

@Bean
public AmazonS3 amazonS3() {
return AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, region))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
.build();
}

@Bean
public BucketCrossOriginConfiguration bucketCrossOriginConfiguration(AmazonS3 amazonS3) {
configureS3Cors(amazonS3);
return new BucketCrossOriginConfiguration();
}

public void configureS3Cors(AmazonS3 s3) {
List<CORSRule.AllowedMethods> methodRule = new ArrayList<>();
methodRule.add(CORSRule.AllowedMethods.PUT);
methodRule.add(CORSRule.AllowedMethods.GET);
methodRule.add(CORSRule.AllowedMethods.POST);
CORSRule rule = new CORSRule().withId("CORSRule")
.withAllowedMethods(methodRule)
.withAllowedHeaders(List.of("*"))
.withAllowedOrigins(List.of("*"))
.withMaxAgeSeconds(3000);

List<CORSRule> rules = new ArrayList<>();
rules.add(rule);

BucketCrossOriginConfiguration configuration = new BucketCrossOriginConfiguration();
configuration.setRules(rules);

s3.setBucketCrossOriginConfiguration(bucketName, configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public <T extends Enum<T> & StadiumStatusType> SaveTopRankedZoneResponseDto save

Profile profile = Profile.builder()
.result(result)
.imgUrl(recommendedProfile.getImgUrl())
.nickname(recommendedProfile.getNickName())
.type(recommendedProfile.getType())
.explanation(recommendedProfile.getExplanation())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class Profile {
@JoinColumn(name = "result_id", nullable = false)
private Result result;

@Column(nullable = false)
private String imgUrl;

@Column(nullable = false)
private String nickname;

Expand All @@ -38,8 +41,9 @@ public class Profile {
private List<String> hashTags;

@Builder
public Profile(Result result, String nickname, String type, String explanation, List<String> hashTags) {
public Profile(Result result, String imgUrl, String nickname, String type, String explanation, List<String> hashTags) {
this.result = result;
this.imgUrl = imgUrl;
this.nickname = nickname;
this.type = type;
this.explanation = explanation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@RequiredArgsConstructor
public enum ProfileStatusType {

EATING("이러다 공까지 먹어버러",
EATING("https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/recommendation/eating.png",
"이러다 공까지 먹어버러",
"야구가 참 맛있고 음식이 재밌어요",
"야구장에서 먹는 재미까지 놓치지 않는 당신!\n야구장을 두 배로 재밌게 즐기는군요?",
List.of("#먹으러왔는데야구도한다?", "#그래서여기구장맛있는거뭐라고?"),
Expand All @@ -18,7 +19,8 @@ public enum ProfileStatusType {
List.of(),
List.of("선수들 가까이", "열정적인 응원")
),
LIFE("주6일 야구장 출퇴근러",
LIFE("https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/recommendation/life.png",
"주6일 야구장 출퇴근러",
"야구가 나의 삶이고, 야구가 나의 숨",
"야구장에서 열정적인 응원을 보여주는 당신!\n당신의 응원 덕에 선수들이 더 행복해 질 거예요!",
List.of("#월요일은심심해", "#18시를공기로안다"),
Expand All @@ -27,7 +29,8 @@ public enum ProfileStatusType {
List.of(),
List.of("다른 팀 팬과")
),
ANGRY("마운드 직진러",
ANGRY("https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/recommendation/angry.png",
"마운드 직진러",
"나와. 이럴 거면 내가 경기 뛸게",
"야구를 통해 희노애락을 다 느끼는 당신!\n몰입하며 보는 야구가 얼마나 재밌는 지 아시는군요?",
List.of("#오늘부터내가야구선수", "#우리팀승리기원n일차"),
Expand All @@ -36,7 +39,8 @@ public enum ProfileStatusType {
List.of(),
List.of("다른 팀 팬과")
),
CALM("뜨거운 열기 속 침착러",
CALM("https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/recommendation/calm.png",
"뜨거운 열기 속 침착러",
"야구란 자고로 그라운드의 열기 속에서 고요함을 느끼는 것",
"경기를 조용하게 관람하는걸 좋아하는 당신!\n경기를 음미하는 것을 좋아하시는군요?",
List.of("#나는나의갈길을간다", "#진짜는조용한법"),
Expand All @@ -45,7 +49,8 @@ public enum ProfileStatusType {
List.of(),
List.of("열정적인 응원")
),
TRAVEL("베이스 낭만 여행러",
TRAVEL("https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/recommendation/travel.png",
"베이스 낭만 여행러",
"야구장에서 한 페이지가 될 수 있게",
"나의 소중한 직관 메이트와 추억을 쌓는 것이 좋은 당신!\n야구장에서의 추억이 행복하길 바라요~",
List.of("#너와함께하는9이닝", "#우리다음에또갈까?"),
Expand All @@ -55,7 +60,7 @@ public enum ProfileStatusType {
List.of("나 혼자")
);


private final String imgUrl;
private final String nickName;
private final String type;
private final String explanation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

public record GetProfileResponseDto(
Long profileId,
String imgUrl,
String nickname,
String type,
String explanation,
List<String> hashTags
) {
public static GetProfileResponseDto from(Profile profile) {
return new GetProfileResponseDto(profile.getId(), profile.getNickname(), profile.getType(), profile.getExplanation(), profile.getHashTags());
return new GetProfileResponseDto(profile.getId(), profile.getImgUrl(), profile.getNickname(), profile.getType(), profile.getExplanation(), profile.getHashTags());
}
}
19 changes: 18 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,21 @@ clova:
api-key: ${CLOVA_API_KEY}
api-gateway-key: ${CLOVA_API_GATEWAY_KEY}
prompt:
baseball: ${BASEBALL_PROMPT}
baseball: ${BASEBALL_PROMPT}

cloud:
aws:
s3:
endpoint: ${S3_ENDPOINT}
chatbot-directory: ${S3_CHATBOT_DIRECTORY}
guide-directory: ${S3_GUIDE_DIRECTORY}
recommendation-directory: ${S3_RECOMMENDATION_DIRECTORY}
credentials:
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
bucket: ${S3_BUCKET}
region:
static: ${S3_REGION}
auto: false
stack:
auto: false
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void getRecommendedProfile() throws Exception {
// given
GetProfileResponseDto getProfileResponseDto = new GetProfileResponseDto(
1L,
"https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/recommendation/eating.png",
"이러다 공까지 먹어버러",
"야구가 참 맛있고 음식이 재밌어요",
"야구장에서 먹는 재미까지 놓치지 않는 당신!\n야구장을 두 배로 재밌게 즐기는군요?",
Expand All @@ -126,6 +127,7 @@ public void getRecommendedProfile() throws Exception {
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.message").value("해당 결과의 프로필 정보를 조회하였습니다."))
.andExpect(jsonPath("$.payload.profileId").value(1L))
.andExpect(jsonPath("$.payload.imgUrl").value("https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/recommendation/eating.png"))
.andExpect(jsonPath("$.payload.nickname").value("이러다 공까지 먹어버러"))
.andExpect(jsonPath("$.payload.type").value("야구가 참 맛있고 음식이 재밌어요"))
.andExpect(jsonPath("$.payload.explanation").value("야구장에서 먹는 재미까지 놓치지 않는 당신!\n야구장을 두 배로 재밌게 즐기는군요?"))
Expand All @@ -147,6 +149,7 @@ public void getRecommendedProfile() throws Exception {
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("payload").description("응답 데이터").optional(),
fieldWithPath("payload.profileId").description("해당 결과의 프로필 ID"),
fieldWithPath("payload.imgUrl").description("해당 결과의 이미지 URL"),
fieldWithPath("payload.nickname").description("해당 결과의 프로필의 닉네임"),
fieldWithPath("payload.type").description("해당 결과의 프로필의 타입"),
fieldWithPath("payload.explanation").description("해당 결과의 프로필 설명"),
Expand Down

0 comments on commit 5ee0b96

Please sign in to comment.