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

πŸ”€ :: λ ˆλ””μŠ€ μΊμ‹œ 적용 #347

Merged
merged 27 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bd4efc8
add :: RedisCacheConfig μΆ”κ°€
Umjiseung Sep 1, 2024
10d3c08
add :: Spring Cache μ˜μ‘΄μ„± μΆ”κ°€
Umjiseung Sep 1, 2024
ba8f29f
add :: CacheEvict μΆ”κ°€
Umjiseung Sep 1, 2024
1028570
add :: JsonProperty μΆ”κ°€
Umjiseung Sep 1, 2024
9b3c22d
add :: Cacheable μΆ”κ°€
Umjiseung Sep 1, 2024
447b116
add :: EnableCaching μΆ”κ°€
Umjiseung Sep 1, 2024
e3fb033
add :: userCacheManager μΆ”κ°€
Umjiseung Sep 1, 2024
a259f59
add :: Cacheable μΆ”κ°€
Umjiseung Sep 1, 2024
0f29e9a
add :: CacheEvict μΆ”κ°€
Umjiseung Sep 1, 2024
69b46a8
add :: Primary μΆ”κ°€
Umjiseung Sep 1, 2024
70d11c6
delete :: λΉˆμ€„ μ‚­μ œ
Umjiseung Sep 1, 2024
3183a00
update :: μ½”λ“œ μŠ€νƒ€μΌμ— 맞게 μˆ˜μ •
Umjiseung Sep 1, 2024
091b556
update :: 1λΆ„ -> 10λΆ„ λ³€κ²½
Umjiseung Sep 2, 2024
6cf0b02
update :: clientCacheManager 1λΆ„ -> 10λΆ„ λ³€κ²½
Umjiseung Sep 2, 2024
ded532f
add :: JsonProperty μΆ”κ°€
Umjiseung Sep 3, 2024
4597c4b
update :: redisCacheManager둜 톡일
Umjiseung Sep 5, 2024
1e03118
update :: cacheManagerλ₯Ό redisCacheManager둜 λ³€κ²½
Umjiseung Sep 5, 2024
d04c3c5
add :: redis에 μ •μ μœΌλ‘œ μΊμ‹œ μ €μž₯μ†Œκ°€ λ§Œλ“€μ–΄μ§€κ²Œ μ„€μ •
Umjiseung Sep 5, 2024
58f6240
delete :: import μ‚­μ œ
Umjiseung Sep 5, 2024
df5a677
update :: AcceptUser -> AcceptUsers λ³€κ²½
Umjiseung Sep 6, 2024
2fa0c71
add :: condition 속성 μΆ”κ°€
Umjiseung Sep 17, 2024
5035b5e
Update src/main/kotlin/com/msg/gauth/domain/user/service/GetAcceptedU…
Umjiseung Sep 18, 2024
515e287
update :: μ‹€μˆ˜λ‘œ μ§€μš΄ cacheManager λ‹€μ‹œ μΆ”κ°€
Umjiseung Sep 18, 2024
51d9ee6
Update src/main/kotlin/com/msg/gauth/domain/user/service/GetAcceptedU…
Umjiseung Sep 18, 2024
702b62b
Update src/main/kotlin/com/msg/gauth/domain/user/service/AcceptUserSi…
Umjiseung Sep 18, 2024
2a738f8
Update src/main/kotlin/com/msg/gauth/domain/admin/service/ExcelParsin…
Umjiseung Sep 18, 2024
ffd00fa
update :: cacheManager λ³€κ²½
Umjiseung Sep 18, 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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
testImplementation(Dependencies.SPRING_SECURITY_TEST)
implementation(Dependencies.SPRING_AOP)
implementation(Dependencies.SPRING_ACTUATOR)
implementation(Dependencies.SPRING_CACHE)

// kotlin
implementation(Dependencies.JACKSON_MODULE_KOTLIN)
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object Dependencies {
const val SPRING_SECURITY_TEST = "org.springframework.security:spring-security-test"
const val SPRING_AOP = "org.springframework.boot:spring-boot-starter-aop"
const val SPRING_ACTUATOR = "org.springframework.boot:spring-boot-starter-actuator"
const val SPRING_CACHE = "org.springframework.boot:spring-boot-starter-cache"

// jackson
const val JACKSON_MODULE_KOTLIN = "com.fasterxml.jackson.module:jackson-module-kotlin"
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/com/msg/gauth/GauthBackendApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.msg.gauth
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication
import org.springframework.cache.annotation.EnableCaching
import java.util.*

@SpringBootApplication
@ConfigurationPropertiesScan
@EnableCaching
class GauthBackendApplication

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.apache.tika.Tika
import org.springframework.cache.annotation.CacheEvict
import org.springframework.web.multipart.MultipartFile

@TransactionalService
class ExcelParsingService(
private val userRepository: UserRepository,
) {

@CacheEvict(value = ["AcceptedUser"], allEntries = true, cacheManager = "userCacheManager")
Umjiseung marked this conversation as resolved.
Show resolved Hide resolved
fun execute(file: MultipartFile) {
val tika = Tika()
val detect = tika.detect(file.bytes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.msg.gauth.domain.client.presentation.dto.response

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.msg.gauth.domain.client.Client
import com.msg.gauth.domain.client.enums.ServiceScope

data class SingleClientResDto(
val id: Long,
val clientId: String,
val serviceName: String,
val serviceUri: String,
val serviceScope: ServiceScope,
val serviceImgUrl: String
data class SingleClientResDto @JsonCreator constructor(
@JsonProperty("id") val id: Long,
@JsonProperty("clientId") val clientId: String,
@JsonProperty("serviceName") val serviceName: String,
@JsonProperty("serviceUri") val serviceUri: String,
@JsonProperty("serviceScope") val serviceScope: ServiceScope,
@JsonProperty("serviceImgUrl") val serviceImgUrl: String
) {

constructor(client: Client) : this(
id = client.id,
clientId = client.clientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.msg.gauth.domain.client.exception.UserNotMatchException
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.util.UserUtil
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.cache.annotation.CacheEvict
import org.springframework.data.repository.findByIdOrNull

@TransactionalService
Expand All @@ -13,6 +14,7 @@ class DeleteClientService(
private val userUtil: UserUtil,
) {

@CacheEvict(value = ["Clients"], allEntries = true, cacheManager = "redisCacheManager")
fun execute(id: Long) {
val client = clientRepository.findByIdOrNull(id)
?: throw ClientNotFindException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.msg.gauth.domain.client.service
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.util.UserUtil
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.cache.annotation.CacheEvict

@TransactionalService
class DeleteClientsService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil
) {

@CacheEvict(value = ["Clients"], allEntries = true, cacheManager = "redisCacheManager")
fun execute(ids: List<Long>) {
val user = userUtil.fetchCurrentUser()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import com.msg.gauth.domain.client.enums.ServiceScope
import com.msg.gauth.domain.client.presentation.dto.response.SingleClientResDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.global.annotation.service.ReadOnlyService
import org.springframework.cache.annotation.Cacheable

@ReadOnlyService
class GetAllClientsService(
private val clientRepository: ClientRepository
) {

@Cacheable(value = ["Clients"], cacheManager = "redisCacheManager")
fun execute(): List<SingleClientResDto> =
clientRepository.findByServiceScope(ServiceScope.PUBLIC)
.map { SingleClientResDto(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.msg.gauth.domain.client.presentation.dto.response.ClientRegisterResDt
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.util.UserUtil
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.cache.annotation.CacheEvict
import java.util.UUID

@TransactionalService
Expand All @@ -13,6 +14,7 @@ class RegisterClientService(
private val userUtil: UserUtil,
) {

@CacheEvict(value = ["Clients"], allEntries = true, cacheManager = "redisCacheManager")
fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto {
val (clientSecret, clientId) = createUUID() to createUUID()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.presentation.dto.request.ClientUpdateReqDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.cache.annotation.CacheEvict
import org.springframework.data.repository.findByIdOrNull

@TransactionalService
class UpdateAnyClientService(
private val clientRepository: ClientRepository
) {

@CacheEvict(value = ["Clients"], allEntries = true, cacheManager = "redisCacheManager")
fun execute(id: Long, clientUpdateReqDto: ClientUpdateReqDto) {
val client: Client = clientRepository.findByIdOrNull(id)
?: throw ClientNotFindException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.msg.gauth.domain.client.presentation.dto.request.ClientUpdateReqDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.util.UserUtil
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.cache.annotation.CacheEvict

@TransactionalService
class UpdateClientService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil
) {

@CacheEvict(value = ["Clients"], allEntries = true, cacheManager = "redisCacheManager")
fun updateClient(id: Long, clientUpdateReqDto: ClientUpdateReqDto) {
val client = clientRepository.findByIdAndCreatedBy(id, userUtil.fetchCurrentUser())
?: throw ClientNotFindException()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.msg.gauth.domain.user.presentation.dto.response

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.msg.gauth.domain.user.User

data class SingleAcceptedUserResDto(
val id: Long,
val name: String,
val email: String,
val grade: Int?,
val classNum: Int?,
val num: Int?,
val profileUrl: String?
data class SingleAcceptedUserResDto @JsonCreator constructor(
@JsonProperty("id") val id: Long,
@JsonProperty("name") val name: String,
@JsonProperty("email") val email: String,
@JsonProperty("grade") val grade: Int?,
@JsonProperty("classNum") val classNum: Int?,
@JsonProperty("num") val num: Int?,
@JsonProperty("profileUrl") val profileUrl: String?
) {

constructor(user: User) : this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import com.msg.gauth.domain.user.presentation.dto.request.AcceptUserReqDto
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.domain.user.repository.UserRoleRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.cache.annotation.CacheEvict

@TransactionalService
class AcceptUserSignUpService(
private val userRepository: UserRepository,
private val userRoleRepository: UserRoleRepository
) {

@CacheEvict(value = ["AcceptedUser"], allEntries = true, cacheManager = "redisCacheManager")
Umjiseung marked this conversation as resolved.
Show resolved Hide resolved
fun execute(id: Long, acceptUserReqDto: AcceptUserReqDto) {
val user = userRepository.findByIdAndState(id, UserState.PENDING)
?: throw UserNotFoundException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import com.msg.gauth.domain.user.presentation.dto.request.AcceptedUserRequest
import com.msg.gauth.domain.user.presentation.dto.response.SingleAcceptedUserResDto
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.ReadOnlyService
import org.springframework.cache.annotation.Cacheable

@ReadOnlyService
class GetAcceptedUsersService(
private val userRepository: UserRepository,
) {

@Cacheable(value = ["AcceptedUser"], cacheManager = "redisCacheManager")
fun execute(request: AcceptedUserRequest): List<SingleAcceptedUserResDto> =
when (request.role) {
UserRoleType.ROLE_STUDENT -> userRepository.search(request.grade, request.classNum, request.keyword)
Expand Down
36 changes: 36 additions & 0 deletions src/main/kotlin/com/msg/gauth/global/redis/RedisCacheConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.msg.gauth.global.redis

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
class RedisCacheConfig {

@Bean
fun redisCacheManager(factory: RedisConnectionFactory?): CacheManager {
val cacheConfig = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer()))
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(
GenericJackson2JsonRedisSerializer()
)
)
.entryTtl(Duration.ofMinutes(10))

return RedisCacheManager
.RedisCacheManagerBuilder
.fromConnectionFactory(factory!!)
.cacheDefaults(cacheConfig)
.build()
}
}
5 changes: 5 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ spring:
password: ${DB_PASSWORD}
driver-class-name: ${DB_DRIVER_CLASS}

cache:
type: redis
cache-names:
- Clients
- AcceptedUser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄μ œλ³΄λ‹ˆ μΊμ‹œ 이름이 AcceptedUser λ³΄λ‹€λŠ” λ³΅μˆ˜ν˜•μΈ AcceptedUsersκ°€ 더 μ μ ˆν•΄ λ³΄μž…λ‹ˆλ‹€

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df5a677
저도 그런 것 κ°™λ„€μš” μˆ˜μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€


redis:
host: ${REDIS_HOST}
Expand Down
Loading