diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/DetailEnvironmentDto.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/DetailEnvironmentDto.kt index 76e2dde1..802431f9 100644 --- a/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/DetailEnvironmentDto.kt +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/DetailEnvironmentDto.kt @@ -3,9 +3,9 @@ package andreas311.miso.domain.environment.application.port.input.dto import andreas311.miso.domain.environment.domain.TodayEnvironment data class DetailEnvironmentDto( - val title: String, - val content: String, - val imageUrl: String? + val title: String = "", + val content: String = "", + val imageUrl: String? = "" ) { constructor(todayEnvironment: TodayEnvironment): this( title = todayEnvironment.title, diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/service/DetailEnvironmentService.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/service/DetailEnvironmentService.kt index f8c3e83c..094286a1 100644 --- a/src/main/kotlin/andreas311/miso/domain/environment/application/service/DetailEnvironmentService.kt +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/service/DetailEnvironmentService.kt @@ -4,11 +4,13 @@ import andreas311.miso.common.annotation.ReadOnlyRollbackService import andreas311.miso.domain.environment.application.port.input.DetailEnvironmentUseCase import andreas311.miso.domain.environment.application.port.input.dto.DetailEnvironmentDto import andreas311.miso.domain.environment.application.port.output.QueryTodayEnvironmentPort +import org.springframework.cache.annotation.Cacheable @ReadOnlyRollbackService class DetailEnvironmentService( private val queryTodayEnvironmentPort: QueryTodayEnvironmentPort ) : DetailEnvironmentUseCase { + @Cacheable(cacheNames = ["environment"], key = "'todayEnvironment'", cacheManager = "redisCacheManager") override fun execute(): DetailEnvironmentDto { val environment = queryTodayEnvironmentPort.findOne() diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/DetailItemDto.kt b/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/DetailItemDto.kt index bc3d5ffc..8be7a0be 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/DetailItemDto.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/DetailItemDto.kt @@ -3,12 +3,12 @@ package andreas311.miso.domain.item.application.port.input.dto import andreas311.miso.domain.item.domain.Item data class DetailItemDto( - val id: Long, - val price: Int, - val amount: Int, - val name: String, - val content: String, - val imageUrl: String? + val id: Long = 0L, + val price: Int = 0, + val amount: Int = 0, + val name: String = "", + val content: String = "", + val imageUrl: String? = "" ) { constructor(item: Item) : this( id = item.id, diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/ItemDto.kt b/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/ItemDto.kt index fa27a7dd..ce758fb1 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/ItemDto.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/application/port/input/dto/ItemDto.kt @@ -3,11 +3,11 @@ package andreas311.miso.domain.item.application.port.input.dto import andreas311.miso.domain.item.domain.Item data class ItemDto( - val id: Long, - val price: Int, - val amount: Int, - val name: String, - val imageUrl: String? + val id: Long = 0L, + val price: Int = 0, + val amount: Int = 0, + val name: String = "", + val imageUrl: String? = "" ) { constructor(item: Item) : this( id = item.id, diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt b/src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt index dfb10559..9a2d5b9f 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt @@ -5,12 +5,14 @@ import andreas311.miso.domain.item.application.exception.ItemNotFoundException import andreas311.miso.domain.item.application.port.input.DeleteItemUseCase import andreas311.miso.domain.item.application.port.output.CommandItemPort import andreas311.miso.domain.item.application.port.output.QueryItemPort +import org.springframework.cache.annotation.CacheEvict @RollbackService class DeleteItemService( private val queryItemPort: QueryItemPort, private val commandItemPort: CommandItemPort ) : DeleteItemUseCase { + @CacheEvict(cacheNames = ["item"], key = "#id", cacheManager = "redisCacheManager") override fun execute(id: Long) { val itemEntity = queryItemPort.findByIdOrNull(id) ?: throw ItemNotFoundException() diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/service/DetailItemService.kt b/src/main/kotlin/andreas311/miso/domain/item/application/service/DetailItemService.kt index e9eb288d..37ea2dd2 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/application/service/DetailItemService.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/application/service/DetailItemService.kt @@ -5,11 +5,13 @@ import andreas311.miso.domain.item.application.exception.ItemNotFoundException import andreas311.miso.domain.item.application.port.input.DetailItemUseCase import andreas311.miso.domain.item.application.port.input.dto.DetailItemDto import andreas311.miso.domain.item.application.port.output.QueryItemPort +import org.springframework.cache.annotation.Cacheable @ReadOnlyRollbackService class DetailItemService( private val queryItemPort: QueryItemPort ) : DetailItemUseCase { + @Cacheable(cacheNames = ["item"], key = "#id", cacheManager = "redisCacheManager") override fun execute(id: Long): DetailItemDto { val item = queryItemPort.findByIdOrNull(id) ?: throw ItemNotFoundException() diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/service/EditItemService.kt b/src/main/kotlin/andreas311/miso/domain/item/application/service/EditItemService.kt index d32609a5..bfe1f044 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/application/service/EditItemService.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/application/service/EditItemService.kt @@ -7,6 +7,7 @@ import andreas311.miso.domain.item.application.port.output.CommandItemPort import andreas311.miso.domain.item.application.port.output.QueryItemPort import andreas311.miso.domain.item.domain.Item import andreas311.miso.thirdparty.aws.s3.util.S3Util +import org.springframework.cache.annotation.CacheEvict import org.springframework.stereotype.Component import org.springframework.web.multipart.MultipartFile @@ -16,6 +17,7 @@ class EditItemService( private val queryItemPort: QueryItemPort, private val commandItemPort: CommandItemPort ) : EditItemUseCase { + @CacheEvict(cacheNames = ["item"], key = "#id", cacheManager = "redisCacheManager") override fun execute(id: Long, editItemDto: EditItemDto, multipartFile: MultipartFile?) { val item = queryItemPort.findByIdOrNull(id) ?: throw ItemNotFoundException() diff --git a/src/main/kotlin/andreas311/miso/domain/notification/application/port/input/dto/DetailNotificationDto.kt b/src/main/kotlin/andreas311/miso/domain/notification/application/port/input/dto/DetailNotificationDto.kt index 2205d9a6..e3e7888e 100644 --- a/src/main/kotlin/andreas311/miso/domain/notification/application/port/input/dto/DetailNotificationDto.kt +++ b/src/main/kotlin/andreas311/miso/domain/notification/application/port/input/dto/DetailNotificationDto.kt @@ -3,7 +3,7 @@ package andreas311.miso.domain.notification.application.port.input.dto import andreas311.miso.domain.notification.domain.Notification data class DetailNotificationDto( - val answer: String + val answer: String = "" ) { constructor(notification: Notification) : this( answer = notification.answer diff --git a/src/main/kotlin/andreas311/miso/domain/notification/application/service/DetailNotificationService.kt b/src/main/kotlin/andreas311/miso/domain/notification/application/service/DetailNotificationService.kt index 0843cc40..1865a835 100644 --- a/src/main/kotlin/andreas311/miso/domain/notification/application/service/DetailNotificationService.kt +++ b/src/main/kotlin/andreas311/miso/domain/notification/application/service/DetailNotificationService.kt @@ -5,11 +5,13 @@ import andreas311.miso.domain.notification.application.exception.NotificationNot import andreas311.miso.domain.notification.application.port.input.DetailNotificationUseCase import andreas311.miso.domain.notification.application.port.input.dto.DetailNotificationDto import andreas311.miso.domain.notification.application.port.output.QueryNotificationPort +import org.springframework.cache.annotation.Cacheable @ReadOnlyRollbackService class DetailNotificationService( private val queryNotificationPort: QueryNotificationPort ) : DetailNotificationUseCase { + @Cacheable(cacheNames = ["inquiryRespond"], key = "#id", cacheManager = "redisCacheManager") override fun execute(id: Long): DetailNotificationDto { val notification = queryNotificationPort.findByInquiryIdOrNull(id) ?: throw NotificationNotFoundException() diff --git a/src/main/kotlin/andreas311/miso/domain/purchase/application/service/PurchaseItemService.kt b/src/main/kotlin/andreas311/miso/domain/purchase/application/service/PurchaseItemService.kt index 4196d647..f1473efc 100644 --- a/src/main/kotlin/andreas311/miso/domain/purchase/application/service/PurchaseItemService.kt +++ b/src/main/kotlin/andreas311/miso/domain/purchase/application/service/PurchaseItemService.kt @@ -11,6 +11,7 @@ import andreas311.miso.domain.purchase.application.port.input.PurchaseItemUseCas import andreas311.miso.domain.purchase.application.port.output.CommandPurchasePort import andreas311.miso.domain.purchase.domain.Purchase import andreas311.miso.domain.user.application.port.output.CommandUserPort +import org.springframework.cache.annotation.CacheEvict import java.time.LocalDateTime @RollbackService @@ -21,6 +22,7 @@ class PurchaseItemService( private val userSecurityPort: UserSecurityPort, private val commandPurchasePort: CommandPurchasePort ) : PurchaseItemUseCase { + @CacheEvict(cacheNames = ["userPoint"], key = "'userPoint'", cacheManager = "redisCacheManager") override fun execute(id: Long) { val user = userSecurityPort.currentUser() diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt index 5055cdd0..0917b078 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt @@ -4,15 +4,15 @@ import andreas311.miso.domain.recyclables.domain.Recyclables import andreas311.miso.domain.recyclables.domain.RecyclablesType data class DetailRecyclablesDto( - val id: Long, - val title: String, - val subTitle: String, - val recycleMethod: String, - val recycleTip: String, - val recycleCaution: String, - val imageUrl: String?, - val recyclablesType: RecyclablesType, - val recycleMark: String + val id: Long = 0L, + val title: String = "", + val subTitle: String = "", + val recycleMethod: String = "", + val recycleTip: String = "", + val recycleCaution: String = "", + val imageUrl: String? = "", + val recyclablesType: RecyclablesType = RecyclablesType.BAG, + val recycleMark: String = "" ) { constructor(recyclables: Recyclables) : this( id = recyclables.id, diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DeleteRecyclablesService.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DeleteRecyclablesService.kt index 6bf76bdc..de8b397c 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DeleteRecyclablesService.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DeleteRecyclablesService.kt @@ -5,12 +5,14 @@ import andreas311.miso.domain.recyclables.application.exception.RecyclablesNotFo import andreas311.miso.domain.recyclables.application.port.input.DeleteRecyclablesUseCase import andreas311.miso.domain.recyclables.application.port.output.CommandRecyclablesPort import andreas311.miso.domain.recyclables.application.port.output.QueryRecyclablesPort +import org.springframework.cache.annotation.CacheEvict @RollbackService class DeleteRecyclablesService( private val queryRecyclablesPort: QueryRecyclablesPort, private val commandRecyclablesPort: CommandRecyclablesPort ) : DeleteRecyclablesUseCase { + @CacheEvict(cacheNames = ["recyclables"], key = "#id", cacheManager = "redisCacheManager") override fun execute(id: Long) { val recyclablesEntity = queryRecyclablesPort.findByIdOrNull(id) ?: throw RecyclablesNotFoundException() diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt index 4650fb7d..c0c619d7 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt @@ -6,11 +6,13 @@ import andreas311.miso.domain.recyclables.application.port.input.DetailRecyclabl import andreas311.miso.domain.recyclables.application.port.input.dto.DetailRecyclablesDto import andreas311.miso.domain.recyclables.application.port.output.QueryRecyclablesPort import andreas311.miso.domain.recyclables.domain.RecyclablesType +import org.springframework.cache.annotation.Cacheable @ReadOnlyRollbackService class DetailRecyclablesService( private val queryRecyclablesPort: QueryRecyclablesPort ) : DetailRecyclablesUseCase { + @Cacheable(cacheNames = ["recyclables"], key = "#recyclablesType", cacheManager = "redisCacheManager") override fun execute(recyclablesType: RecyclablesType): DetailRecyclablesDto { val recyclables = queryRecyclablesPort.findByRecyclablesTypeOrNull(recyclablesType) ?: throw RecyclablesNotFoundException() diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/EditRecyclablesService.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/EditRecyclablesService.kt index 07e8ef12..b6c0f126 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/EditRecyclablesService.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/EditRecyclablesService.kt @@ -8,6 +8,7 @@ import andreas311.miso.domain.recyclables.application.port.output.CommandRecycla import andreas311.miso.domain.recyclables.application.port.output.QueryRecyclablesPort import andreas311.miso.domain.recyclables.domain.Recyclables import andreas311.miso.thirdparty.aws.s3.util.S3Util +import org.springframework.cache.annotation.CacheEvict import org.springframework.web.multipart.MultipartFile @RollbackService @@ -16,6 +17,7 @@ class EditRecyclablesService( private val queryRecyclablesPort: QueryRecyclablesPort, private val commandRecyclablesPort: CommandRecyclablesPort ) : EditRecyclablesUseCase { + @CacheEvict(cacheNames = ["recyclables"], key = "#editRecyclablesDto.recyclablesType", cacheManager = "redisCacheManager") override fun execute(id: Long, editRecyclablesDto: EditRecyclablesDto, multipartFile: MultipartFile?) { val recyclables = queryRecyclablesPort.findByIdOrNull(id) ?: throw RecyclablesNotFoundException() diff --git a/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/PointDto.kt b/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/PointDto.kt index e98cdd37..dd21f99f 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/PointDto.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/PointDto.kt @@ -3,7 +3,7 @@ package andreas311.miso.domain.user.application.port.input.dto import andreas311.miso.domain.user.domain.User data class PointDto( - val point: Int + val point: Int = 0 ) { constructor(user: User) : this( point = user.point diff --git a/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/UserInfoDto.kt b/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/UserInfoDto.kt index cb0af6f5..20fe5fa3 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/UserInfoDto.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/application/port/input/dto/UserInfoDto.kt @@ -5,9 +5,9 @@ import andreas311.miso.domain.user.domain.User import java.util.* data class UserInfoDto( - val id: UUID, - val email: String, - val role: Role + val id: UUID = UUID.randomUUID(), + val email: String = "", + val role: Role = Role.ROLE_USER ) { constructor(user: User) : this( id = user.id, diff --git a/src/main/kotlin/andreas311/miso/domain/user/application/service/GetPointService.kt b/src/main/kotlin/andreas311/miso/domain/user/application/service/GetPointService.kt index 72e8fdf3..13fbaf44 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/application/service/GetPointService.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/application/service/GetPointService.kt @@ -4,11 +4,13 @@ import andreas311.miso.common.annotation.ReadOnlyRollbackService import andreas311.miso.domain.auth.application.port.output.UserSecurityPort import andreas311.miso.domain.user.application.port.input.GetPointUseCase import andreas311.miso.domain.user.application.port.input.dto.PointDto +import org.springframework.cache.annotation.Cacheable @ReadOnlyRollbackService class GetPointService( private val userSecurityPort: UserSecurityPort ) : GetPointUseCase { + @Cacheable(cacheNames = ["userPoint"], key = "'userPoint'", cacheManager = "redisCacheManager") override fun execute(): PointDto { val user = userSecurityPort.currentUser() diff --git a/src/main/kotlin/andreas311/miso/domain/user/application/service/GivePointService.kt b/src/main/kotlin/andreas311/miso/domain/user/application/service/GivePointService.kt index 6d5ed38e..f8616600 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/application/service/GivePointService.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/application/service/GivePointService.kt @@ -4,12 +4,14 @@ import andreas311.miso.common.annotation.RollbackService import andreas311.miso.domain.auth.application.port.output.UserSecurityPort import andreas311.miso.domain.user.application.port.input.GivePointUseCase import andreas311.miso.domain.user.application.port.output.CommandUserPort +import org.springframework.cache.annotation.CacheEvict @RollbackService class GivePointService( private val commandUserPort: CommandUserPort, private val userSecurityPort: UserSecurityPort ) : GivePointUseCase { + @CacheEvict(cacheNames = ["userPoint"], key = "'userPoint'", cacheManager = "redisCacheManager") override fun execute() { val user = userSecurityPort.currentUser() diff --git a/src/main/kotlin/andreas311/miso/domain/user/application/service/UserInfoService.kt b/src/main/kotlin/andreas311/miso/domain/user/application/service/UserInfoService.kt index e1fa8df5..b42613f6 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/application/service/UserInfoService.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/application/service/UserInfoService.kt @@ -4,11 +4,13 @@ import andreas311.miso.common.annotation.ReadOnlyRollbackService import andreas311.miso.domain.auth.application.port.output.UserSecurityPort import andreas311.miso.domain.user.application.port.input.UserInfoUseCase import andreas311.miso.domain.user.application.port.input.dto.UserInfoDto +import org.springframework.cache.annotation.Cacheable @ReadOnlyRollbackService class UserInfoService( private val userSecurityPort: UserSecurityPort ) : UserInfoUseCase { + @Cacheable(cacheNames = ["user"], key = "'userInfo'", cacheManager = "redisCacheManager") override fun execute(): UserInfoDto { val user = userSecurityPort.currentUser() diff --git a/src/main/kotlin/andreas311/miso/global/config/EnableCachingConfig.kt b/src/main/kotlin/andreas311/miso/global/config/EnableCachingConfig.kt new file mode 100644 index 00000000..d085daf3 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/global/config/EnableCachingConfig.kt @@ -0,0 +1,8 @@ +package andreas311.miso.global.config + +import org.springframework.cache.annotation.EnableCaching +import org.springframework.context.annotation.Configuration + +@Configuration +@EnableCaching +class EnableCachingConfig \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/global/redis/RedisCacheConfig.kt b/src/main/kotlin/andreas311/miso/global/redis/RedisCacheConfig.kt new file mode 100644 index 00000000..646a6fac --- /dev/null +++ b/src/main/kotlin/andreas311/miso/global/redis/RedisCacheConfig.kt @@ -0,0 +1,31 @@ +package andreas311.miso.global.redis + +import org.springframework.cache.CacheManager +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 +class RedisCacheConfig { + @Bean + fun redisCacheManager(redisConnectionFactory: RedisConnectionFactory): CacheManager { + val redisCacheConfiguration = RedisCacheConfiguration + .defaultCacheConfig() + .disableCachingNullValues() + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(GenericJackson2JsonRedisSerializer())) + .entryTtl(Duration.ofMinutes(30)) + + return RedisCacheManager + .RedisCacheManagerBuilder + .fromConnectionFactory(redisConnectionFactory) + .cacheDefaults(redisCacheConfiguration) + .build() + } +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/global/redis/RedisConfig.kt b/src/main/kotlin/andreas311/miso/global/redis/RedisConfig.kt index 388ddf10..8f8ad6d5 100644 --- a/src/main/kotlin/andreas311/miso/global/redis/RedisConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/redis/RedisConfig.kt @@ -19,7 +19,7 @@ class RedisConfig( LettuceConnectionFactory(redisProperties.host, redisProperties.port) @Bean - fun redisTemplate(): RedisTemplate { + fun redisTemplateManager(): RedisTemplate { val redisTemplate = RedisTemplate() redisTemplate.keySerializer = StringRedisSerializer() redisTemplate.valueSerializer = StringRedisSerializer()