Skip to content

Commit b0c87f8

Browse files
authored
[T3-124] S3 설정 추가 및 감정구슬 전체 조회 수정 (#38)
* feat: s3 config 생성 * fix: 감정구슬 전체 조회 API 수정 * feat: EmotionMarbleMapper 추가 및 서비스 로직 수정
1 parent bed67cb commit b0c87f8

8 files changed

Lines changed: 82 additions & 19 deletions

File tree

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ dependencies {
5959

6060
// bouncycastle
6161
implementation 'org.bouncycastle:bcpkix-jdk18on:1.80'
62+
63+
// aws
64+
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
6265
}
6366

6467
tasks.named('test') {

src/main/java/bitnagil/bitnagil_backend/emotionMarble/controller/EmotionMarbleController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package bitnagil.bitnagil_backend.emotionMarble.controller;
22

33
import bitnagil.bitnagil_backend.emotionMarble.controller.spec.EmotionMarbleSpec;
4-
import bitnagil.bitnagil_backend.emotionMarble.domain.EmotionMarble;
5-
import bitnagil.bitnagil_backend.emotionMarble.domain.enums.EmotionMarbleType;
64
import bitnagil.bitnagil_backend.emotionMarble.request.RegisterEmotionMarbleRequest;
75
import bitnagil.bitnagil_backend.emotionMarble.response.EmotionMarbleTypeResponse;
86
import bitnagil.bitnagil_backend.emotionMarble.response.RegisterEmotionMarbleResponse;
@@ -13,6 +11,8 @@
1311
import lombok.RequiredArgsConstructor;
1412
import org.springframework.web.bind.annotation.*;
1513

14+
import java.util.List;
15+
1616
@RestController
1717
@RequiredArgsConstructor
1818
@RequestMapping(value = "/api/v1/emotion-marbles")
@@ -21,7 +21,7 @@ public class EmotionMarbleController implements EmotionMarbleSpec {
2121

2222
// 감정구슬 조회 API
2323
@GetMapping("")
24-
public CustomResponseDto<EmotionMarbleTypeResponse> getEmotionMarbles() {
24+
public CustomResponseDto<List<EmotionMarbleTypeResponse>> getEmotionMarbles() {
2525
return CustomResponseDto.from(emotionMarbleService.getEmotionMarbles());
2626
}
2727

src/main/java/bitnagil/bitnagil_backend/emotionMarble/controller/spec/EmotionMarbleSpec.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import io.swagger.v3.oas.annotations.Operation;
1212
import io.swagger.v3.oas.annotations.tags.Tag;
1313

14+
import java.util.List;
15+
1416
@Tag(name = ApiTags.EMOTION_MARBLE)
1517
public interface EmotionMarbleSpec {
1618

1719
@Operation(summary = "감정 구슬을 조회합니다")
18-
public CustomResponseDto<EmotionMarbleTypeResponse> getEmotionMarbles();
20+
public CustomResponseDto<List<EmotionMarbleTypeResponse>> getEmotionMarbles();
1921

2022
@Operation(summary = "감정 구슬을 등록합니다. 감정 구슬에 따른 추천 루틴을 응답합니다.")
2123
@ApiErrorCodeExamples({ErrorCode.NOT_FOUND_RECOMMENDED_ROUTINE})

src/main/java/bitnagil/bitnagil_backend/emotionMarble/domain/enums/EmotionMarbleType.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
@RequiredArgsConstructor
88
@Getter
99
public enum EmotionMarbleType implements EnumType {
10-
CALM("평온함", 5L),
11-
VITALITY("활기참", 6L),
12-
LETHARGY("무기력함", 7L),
13-
ANXIETY("불안함", 8L),
14-
SATISFACTION("만족함", 9L),
15-
FATIGUE("피로함", 10L)
10+
CALM("평온함", 5L, "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_calm.png", "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/marble_calm.png"),
11+
VITALITY("활기참", 6L, "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_vitality.png", "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/marble_vitality.png"),
12+
LETHARGY("무기력함", 7L, "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_lethargy.png", "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/marble_lethargy.png"),
13+
ANXIETY("불안함", 8L, "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_anxiety.png", "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/marble_anxiety.png"),
14+
SATISFACTION("만족함", 9L, "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png", "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/marble_satisfaction.png"),
15+
FATIGUE("피로함", 10L, "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_fatigue.png", "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/marble_fatigue.png")
1616
;
1717

1818
private final String description;
1919
private final Long caseId;
20+
private final String homeMarbleImageUrl;
21+
private final String marbleImageUrl;
2022
}

src/main/java/bitnagil/bitnagil_backend/emotionMarble/response/EmotionMarbleTypeResponse.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
@Builder
1212
@Schema(description = "감정 구슬 조회 DTO")
1313
public class EmotionMarbleTypeResponse {
14-
@Schema(
15-
description = "감정 구슬 enum 배열",
16-
type = "array",
17-
example = "[\"CALM\", \"VITALITY\", \"LETHARGY\", \"ANXIETY\", \"SATISFACTION\", \"FATIGUE\"]"
18-
)
19-
private EmotionMarbleType[] emotionMarbleTypes;
14+
@Schema(description = "감정 구슬 타입", example = "CALM")
15+
private EmotionMarbleType emotionMarbleType;
16+
17+
@Schema(description = "감정 구슬 명칭", example = "평온함")
18+
private String emotionMarbleName;
19+
20+
@Schema(description = "감정 구슬 이미지 URL", example = "https://example.com/image/calm.png")
21+
private String imageUrl;
2022
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.service;
2+
3+
import bitnagil.bitnagil_backend.emotionMarble.domain.enums.EmotionMarbleType;
4+
import bitnagil.bitnagil_backend.emotionMarble.response.EmotionMarbleTypeResponse;
5+
import org.springframework.stereotype.Component;
6+
7+
import java.util.List;
8+
9+
/**
10+
* 감정구슬에 대한 가공된 데이터를 DTO로 변환하는 Mapper 클래스입니다.
11+
*/
12+
@Component
13+
public class EmotionMarbleMapper {
14+
15+
public EmotionMarbleTypeResponse toEmotionMarbleTypeResponse(EmotionMarbleType emotionMarbleType) {
16+
return EmotionMarbleTypeResponse.builder()
17+
.emotionMarbleName(emotionMarbleType.getDescription())
18+
.emotionMarbleType(emotionMarbleType)
19+
.imageUrl(emotionMarbleType.getMarbleImageUrl())
20+
.build();
21+
}
22+
}

src/main/java/bitnagil/bitnagil_backend/emotionMarble/service/EmotionMarbleService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.time.LocalDate;
2121
import java.time.LocalDateTime;
2222
import java.time.LocalTime;
23+
import java.util.Arrays;
2324
import java.util.List;
25+
import java.util.stream.Collectors;
2426

2527
/**
2628
* 감정 구슬에 대한 로직을 관리하는 클래스입니다.
@@ -33,11 +35,13 @@ public class EmotionMarbleService {
3335

3436
private final RecommendedRoutineManager recommendedRoutineManager;
3537
private final EmotionMarbleFactory emotionMarbleFactory;
38+
private final EmotionMarbleMapper emotionMarbleMapper;
3639

3740
// 감정 구술 조회(enum의 value를 가져온다.)
38-
public EmotionMarbleTypeResponse getEmotionMarbles() {
39-
EmotionMarbleType[] values = EmotionMarbleType.values();
40-
return EmotionMarbleTypeResponse.builder().emotionMarbleTypes(values).build();
41+
public List<EmotionMarbleTypeResponse> getEmotionMarbles() {
42+
return Arrays.stream(EmotionMarbleType.values())
43+
.map(emotionMarbleType -> emotionMarbleMapper.toEmotionMarbleTypeResponse(emotionMarbleType))
44+
.collect(Collectors.toList());
4145
}
4246

4347
// 감정 구슬 등록(1일 1회)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package bitnagil.bitnagil_backend.global.config;
2+
3+
import com.amazonaws.auth.AWSStaticCredentialsProvider;
4+
import com.amazonaws.auth.BasicAWSCredentials;
5+
import com.amazonaws.services.s3.AmazonS3Client;
6+
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
@Configuration
12+
public class S3Config {
13+
@Value("${cloud.aws.credentials.access-key}")
14+
private String accessKey;
15+
@Value("${cloud.aws.credentials.secret-key}")
16+
private String secretKey;
17+
@Value("${cloud.aws.region.static}")
18+
private String region;
19+
20+
@Bean
21+
public AmazonS3Client amazonS3Client() {
22+
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
23+
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
24+
.withRegion(region)
25+
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
26+
.build();
27+
}
28+
}

0 commit comments

Comments
 (0)