Skip to content
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

๐Ÿ”€ :: ์กฐํšŒ ๋กœ์ง์— ์บ์‹œ ์ ์šฉ #112

Merged
merged 22 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5dd9d35
:memo: EnableCachingConfig ๊ตฌํ˜„
uuuuuuuk Apr 22, 2024
d2a8168
:memo: RedisCacheConfig ๊ตฌํ˜„
uuuuuuuk Apr 22, 2024
effdab6
:memo: DetailEnvironmentDto ํ•„๋“œ ์ดˆ๊ธฐํ™”
uuuuuuuk Apr 22, 2024
be2d407
:memo: DetailItemDto ํ•„๋“œ ์ดˆ๊ธฐํ™”
uuuuuuuk Apr 22, 2024
29a7852
:memo: DetailNotificationDto ํ•„๋“œ ์ดˆ๊ธฐํ™”
uuuuuuuk Apr 22, 2024
0d20d9c
:memo: DetailRecyclablesDto ํ•„๋“œ ์ดˆ๊ธฐํ™”
uuuuuuuk Apr 22, 2024
25df91b
:memo: ItemDto ํ•„๋“œ ์ดˆ๊ธฐํ™”
uuuuuuuk Apr 22, 2024
8b9024d
:memo: PointDto ํ•„๋“œ ์ดˆ๊ธฐํ™”
uuuuuuuk Apr 22, 2024
d7f9e09
:memo: UserInfoDto ํ•„๋“œ ์ดˆ๊ธฐํ™”
uuuuuuuk Apr 22, 2024
004bc39
:memo: RedisConfig ์—์„œ redisTemplate ํ•จ์ˆ˜ ์ด๋ฆ„์„ redisTemplateManager ๋กœ ๋ณ€๊ฒฝ
uuuuuuuk Apr 22, 2024
cce5285
:memo: DetailEnvironmentService ์— look aside ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
9505576
:memo: DetailItemService ์— look aside ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
8f5897e
:memo: DetailNotificationService ์— look aside ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
872d843
:memo: DetailRecyclablesService ์— look aside ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
233fded
:memo: GetPointService ์— look aside ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
2bdf7ba
:memo: UserInfoService ์— look aside ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
ea5c32f
:memo: DeleteItemService ์— write around ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
d8dde74
:memo: DeleteRecyclablesService ์— write around ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
52ccd0b
:memo: EditItemService ์— write around ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
386a4ae
:memo: EditRecyclablesService ์— write around ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
509f7e6
:memo: GivePointService ์— write around ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
25999d6
:memo: PurchaseItemService ์— write around ์บ์‹œ ์ „๋žต ์ ์šฉ
uuuuuuuk Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions src/main/kotlin/andreas311/miso/global/redis/RedisCacheConfig.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RedisConfig(
LettuceConnectionFactory(redisProperties.host, redisProperties.port)

@Bean
fun redisTemplate(): RedisTemplate<String, String> {
fun redisTemplateManager(): RedisTemplate<String, String> {
val redisTemplate = RedisTemplate<String, String>()
redisTemplate.keySerializer = StringRedisSerializer()
redisTemplate.valueSerializer = StringRedisSerializer()
Expand Down
Loading