-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 아바타 프로필을 DB로 마이그레이션 #132
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
92167ea
[#130] feat(yml): 한글 깨짐 현상 해결
jaejoong0529 803ab1f
[#130] feat(survey): 아바타 프로필을 DB로 마이그레이션
jaejoong0529 a6d2545
[#130] feat(survey): 캐시 설정 추가
jaejoong0529 62c640a
[#130] feat(survey): 에러 코드 추가
jaejoong0529 bc798bf
[#130] feat(survey): AvatarProfileResponse를 dto 패키지 안으로 이동
jaejoong0529 1cab196
[#130] feat(survey): log를 debug에서 info로 변경
jaejoong0529 09d067f
[#130] feat(survey): ttl 시간이 기본이 1시간이라 중복 코드 제거
jaejoong0529 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 hidden or 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 hidden or 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,36 @@ | ||
| package com.dduru.gildongmu.config; | ||
|
|
||
| import org.springframework.cache.CacheManager; | ||
| import org.springframework.cache.annotation.EnableCaching; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
| import org.springframework.data.redis.cache.RedisCacheManager; | ||
| import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
| import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| @Configuration | ||
| @EnableCaching | ||
| public class CacheConfig { | ||
|
|
||
| @Bean | ||
| public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { | ||
| RedisCacheConfiguration defaultConfig = RedisCacheConfiguration.defaultCacheConfig() | ||
| .entryTtl(Duration.ofHours(1)) | ||
| .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) | ||
| .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) | ||
| .disableCachingNullValues(); | ||
|
|
||
| // 아바타 프로필 캐시 설정 (1시간) | ||
| RedisCacheConfiguration avatarProfilesConfig = defaultConfig.entryTtl(Duration.ofHours(1)); | ||
|
|
||
| return RedisCacheManager.builder(redisConnectionFactory) | ||
| .cacheDefaults(defaultConfig) | ||
| .withCacheConfiguration("avatarProfiles", avatarProfilesConfig) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or 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
49 changes: 49 additions & 0 deletions
49
src/main/java/com/dduru/gildongmu/survey/domain/AvatarProfile.java
This file contains hidden or 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,49 @@ | ||
| package com.dduru.gildongmu.survey.domain; | ||
|
|
||
| import com.dduru.gildongmu.common.entity.BaseTimeEntity; | ||
| import com.dduru.gildongmu.survey.domain.enums.AvatarType; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "avatar_profiles") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class AvatarProfile extends BaseTimeEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "avatar_type", nullable = false, unique = true) | ||
| private AvatarType avatarType; | ||
|
|
||
| @Column(nullable = false, length = 200) | ||
| private String description; | ||
|
|
||
| @Column(nullable = false, columnDefinition = "TEXT") | ||
| private String personality; | ||
|
|
||
| @Column(nullable = false, columnDefinition = "TEXT") | ||
| private String strength; | ||
|
|
||
| @Column(nullable = false, columnDefinition = "TEXT") | ||
| private String tip; | ||
|
|
||
| @Column(nullable = false, columnDefinition = "JSON") | ||
| private String tags; | ||
|
|
||
| @Builder | ||
| public AvatarProfile(AvatarType avatarType, String description, String personality, String strength, String tip, String tags) { | ||
| this.avatarType = avatarType; | ||
| this.description = description; | ||
| this.personality = personality; | ||
| this.strength = strength; | ||
| this.tip = tip; | ||
| this.tags = tags; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/dduru/gildongmu/survey/exception/AvatarProfileNotFoundException.java
This file contains hidden or 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,19 @@ | ||
| package com.dduru.gildongmu.survey.exception; | ||
|
|
||
| import com.dduru.gildongmu.common.exception.BusinessException; | ||
| import com.dduru.gildongmu.common.exception.ErrorCode; | ||
| import com.dduru.gildongmu.survey.domain.enums.AvatarType; | ||
|
|
||
| public class AvatarProfileNotFoundException extends BusinessException { | ||
| public AvatarProfileNotFoundException() { | ||
| super(ErrorCode.AVATAR_PROFILE_NOT_FOUND, "아바타 프로필을 찾을 수 없습니다"); | ||
| } | ||
|
|
||
| public AvatarProfileNotFoundException(String message) { | ||
| super(ErrorCode.AVATAR_PROFILE_NOT_FOUND, message); | ||
| } | ||
|
|
||
| public static AvatarProfileNotFoundException of(AvatarType avatarType) { | ||
| return new AvatarProfileNotFoundException("아바타 프로필을 찾을 수 없습니다. avatarType=" + avatarType); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dduru/gildongmu/survey/repository/AvatarProfileRepository.java
This file contains hidden or 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,11 @@ | ||
| package com.dduru.gildongmu.survey.repository; | ||
|
|
||
| import com.dduru.gildongmu.survey.domain.AvatarProfile; | ||
| import com.dduru.gildongmu.survey.domain.enums.AvatarType; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface AvatarProfileRepository extends JpaRepository<AvatarProfile, Long> { | ||
| Optional<AvatarProfile> findByAvatarType(AvatarType avatarType); | ||
| } |
69 changes: 0 additions & 69 deletions
69
src/main/java/com/dduru/gildongmu/survey/service/AvatarProfileProvider.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
src/main/java/com/dduru/gildongmu/survey/service/AvatarProfileService.java
This file contains hidden or 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,49 @@ | ||
| package com.dduru.gildongmu.survey.service; | ||
|
|
||
| import com.dduru.gildongmu.common.util.JsonConverter; | ||
| import com.dduru.gildongmu.survey.domain.AvatarProfile; | ||
| import com.dduru.gildongmu.survey.domain.enums.AvatarType; | ||
| import com.dduru.gildongmu.survey.exception.AvatarProfileNotFoundException; | ||
| import com.dduru.gildongmu.survey.repository.AvatarProfileRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.cache.annotation.Cacheable; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class AvatarProfileService { | ||
|
|
||
| private final AvatarProfileRepository avatarProfileRepository; | ||
| private final JsonConverter jsonConverter; | ||
|
|
||
| @Cacheable(value = "avatarProfiles", key = "#avatarType.name()") | ||
| public AvatarProfileResponse getProfile(AvatarType avatarType) { | ||
| log.debug("아바타 프로필 조회 - avatarType: {}", avatarType); | ||
|
|
||
| AvatarProfile profile = avatarProfileRepository.findByAvatarType(avatarType) | ||
| .orElseThrow(() -> { | ||
| log.error("아바타 프로필을 찾을 수 없음 - avatarType: {}", avatarType); | ||
| return AvatarProfileNotFoundException.of(avatarType); | ||
| }); | ||
|
|
||
| List<String> tags = jsonConverter.convertJsonToList(profile.getTags()); | ||
|
|
||
| log.debug("아바타 프로필 조회 완료 - avatarType: {}", avatarType); | ||
jaejoong0529 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return new AvatarProfileResponse( | ||
| profile.getDescription(), | ||
| profile.getPersonality(), | ||
| profile.getStrength(), | ||
| profile.getTip(), | ||
| tags | ||
| ); | ||
| } | ||
|
|
||
| public record AvatarProfileResponse(String description, String personality, String strength, String tip, List<String> tags) { | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.