From b8ad1fa6a37ddd9621bb3f2b9eaa561e9e7214e0 Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 13 Aug 2024 19:18:35 +0900 Subject: [PATCH 01/19] =?UTF-8?q?feat:=20controller,=20service=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springaccount/app/user/controller/UserController.kt | 7 +++++++ .../uoslife/springaccount/app/user/service/UserService.kt | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt create mode 100644 src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt new file mode 100644 index 0000000..a66e25d --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt @@ -0,0 +1,7 @@ +package uoslife.springaccount.app.user.controller + +import org.springframework.web.bind.annotation.RestController + +@RestController +class UserController { +} \ No newline at end of file diff --git a/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt b/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt new file mode 100644 index 0000000..ddb293e --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt @@ -0,0 +1,7 @@ +package uoslife.springaccount.app.user.service + +import org.springframework.stereotype.Service + +@Service +class UserService { +} \ No newline at end of file From e3be647e0ed94fc35e009d57d3d3663ff05d6b27 Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 13 Aug 2024 19:26:13 +0900 Subject: [PATCH 02/19] =?UTF-8?q?chore:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springaccount/app/user/controller/UserController.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt index a66e25d..89a5a6e 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt @@ -1,7 +1,8 @@ package uoslife.springaccount.app.user.controller import org.springframework.web.bind.annotation.RestController +import uoslife.springaccount.app.user.service.UserService @RestController -class UserController { +class UserController(private val userService: UserService) { } \ No newline at end of file From 2cd815d3d4ab708ff5b8ea4a0ed240d06204fa27 Mon Sep 17 00:00:00 2001 From: 23tae Date: Wed, 21 Aug 2024 00:18:28 +0900 Subject: [PATCH 03/19] =?UTF-8?q?chore:=20=EC=9D=91=EB=8B=B5=EC=9A=A9=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/dto/response/UserProfileDto.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt b/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt new file mode 100644 index 0000000..6f5f7ae --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt @@ -0,0 +1,38 @@ +package uoslife.springaccount.app.user.dto.response + +class UserProfileDto { + + data class UserRealm( + val code: String, + val name: String, + ) + + data class UserProfileIdentity( + val id: String, + val type: String, + val status: String, + val idNumber: String, + val university: String?, + val department: String?, + val major: String?, + ) + + data class UserProfileModerator( + val generation: String, + val chapter: String, + val role: String, + ) + + data class UserProfileResponse( + val id: Long, + val nickname: String, + val phone: String, + val name: String?, + val email: String?, + val realm: UserRealm?, + val identity: UserProfileIdentity?, + val moderator: UserProfileModerator?, + val isLinkedPortal: Boolean, + val isVerified: Boolean, + ) +} From 65754510b420b3296da3a2260e8982b2749ee469 Mon Sep 17 00:00:00 2001 From: 23tae Date: Wed, 21 Aug 2024 00:38:46 +0900 Subject: [PATCH 04/19] =?UTF-8?q?chore:=20verificationMethod=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springaccount/app/user/dto/response/UserProfileDto.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt b/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt index 6f5f7ae..d0ced77 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt @@ -1,5 +1,7 @@ package uoslife.springaccount.app.user.dto.response +import uoslife.springaccount.app.verification.domain.entity.VerificationMethod + class UserProfileDto { data class UserRealm( @@ -34,5 +36,6 @@ class UserProfileDto { val moderator: UserProfileModerator?, val isLinkedPortal: Boolean, val isVerified: Boolean, + val verificationMethod: VerificationMethod?, ) } From bd2b2dcfdd7746c1e3b32cf408dc8a6426fc0f17 Mon Sep 17 00:00:00 2001 From: 23tae Date: Wed, 21 Aug 2024 00:43:41 +0900 Subject: [PATCH 05/19] =?UTF-8?q?chore:=20param=20DTO=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/dto/param/CreateUserDto.kt | 3 +++ .../app/user/dto/param/UpdateUserDto.kt | 3 +++ .../app/user/dto/param/UserWithInfoDto.kt | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/app/user/dto/param/CreateUserDto.kt create mode 100644 src/main/kotlin/uoslife/springaccount/app/user/dto/param/UpdateUserDto.kt create mode 100644 src/main/kotlin/uoslife/springaccount/app/user/dto/param/UserWithInfoDto.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/user/dto/param/CreateUserDto.kt b/src/main/kotlin/uoslife/springaccount/app/user/dto/param/CreateUserDto.kt new file mode 100644 index 0000000..bd0c037 --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/user/dto/param/CreateUserDto.kt @@ -0,0 +1,3 @@ +package uoslife.springaccount.app.user.dto.param + +data class CreateUserDto(val nickname: String, val phoneNumber: String) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/dto/param/UpdateUserDto.kt b/src/main/kotlin/uoslife/springaccount/app/user/dto/param/UpdateUserDto.kt new file mode 100644 index 0000000..8fde5e0 --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/user/dto/param/UpdateUserDto.kt @@ -0,0 +1,3 @@ +package uoslife.springaccount.app.user.dto.param + +data class UpdateUserDto(val nickname: String?) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/dto/param/UserWithInfoDto.kt b/src/main/kotlin/uoslife/springaccount/app/user/dto/param/UserWithInfoDto.kt new file mode 100644 index 0000000..55e6976 --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/user/dto/param/UserWithInfoDto.kt @@ -0,0 +1,13 @@ +package uoslife.springaccount.app.user.dto.param + +import uoslife.springaccount.app.identity.domain.entity.Identity +import uoslife.springaccount.app.moderator.domain.entity.Moderators +import uoslife.springaccount.app.verification.domain.entity.PortalAccounts +import uoslife.springaccount.app.verification.domain.entity.Verifications + +data class UserWithInfoDto( + val identities: List, + val portalAccounts: List, + val verifications: List, + val moderator: Moderators?, +) From 00a94e25c27dae73c871fac8ca069db73c70d0ec Mon Sep 17 00:00:00 2001 From: 23tae Date: Sun, 25 Aug 2024 13:47:33 +0900 Subject: [PATCH 06/19] =?UTF-8?q?feat:=20=EC=9E=90=EC=8B=A0=EC=9D=98=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/controller/UserController.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt index 89a5a6e..2d66323 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt @@ -1,8 +1,16 @@ package uoslife.springaccount.app.user.controller +import org.springframework.security.core.annotation.AuthenticationPrincipal +import org.springframework.security.core.userdetails.UserDetails +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController import uoslife.springaccount.app.user.service.UserService @RestController class UserController(private val userService: UserService) { -} \ No newline at end of file + + @GetMapping("/me") + fun getMyProfile(@AuthenticationPrincipal userDetails: UserDetails) { + val userId = userDetails.username.toLong() + } +} From 046464c435b71e86f6f32299a2ee655b8a86e72f Mon Sep 17 00:00:00 2001 From: 23tae Date: Sun, 25 Aug 2024 23:16:24 +0900 Subject: [PATCH 07/19] =?UTF-8?q?build:=20redis=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 1 + .../uoslife/springaccount/SpringAccountApplication.kt | 4 +++- src/main/resources/application.yml | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d7137ef..11c0fe2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -49,6 +49,7 @@ dependencies { implementation("org.springframework.cloud:spring-cloud-starter-openfeign") developmentOnly("org.springframework.boot:spring-boot-devtools") implementation("org.redisson:redisson-spring-boot-starter:3.18.0") + implementation("org.springframework.boot:spring-boot-starter-cache") // Kotlin implementation("com.fasterxml.jackson.module:jackson-module-kotlin") diff --git a/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt b/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt index 32c2a16..377a3e4 100644 --- a/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt +++ b/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt @@ -2,8 +2,10 @@ package uoslife.springaccount import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.cache.annotation.EnableCaching + +@SpringBootApplication @EnableCaching class SpringAccountApplication -@SpringBootApplication class SpringAccountApplication fun main(args: Array) { runApplication(*args) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 97d8d66..c65b411 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -5,4 +5,8 @@ spring: title: SPRING-ACCOUNT version: 1.0.1 banner: - location: classpath:/app-banner.dat \ No newline at end of file + location: classpath:/app-banner.dat + data: + redis: + host: ${REDIS_HOST} + port: ${REDIS_PORT} \ No newline at end of file From 01dffdd8857032f355b2f2dc8d9c219df6adf6f0 Mon Sep 17 00:00:00 2001 From: 23tae Date: Sun, 25 Aug 2024 23:38:04 +0900 Subject: [PATCH 08/19] =?UTF-8?q?feat:=20id=EB=A1=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EB=A5=BC=20=EC=B0=BE=EB=8A=94=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/domain/repository/jpa/UserRepository.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt b/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt index dad6f98..c364241 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt @@ -2,5 +2,8 @@ package uoslife.springaccount.app.user.domain.repository.jpa import org.springframework.data.jpa.repository.JpaRepository import uoslife.springaccount.app.user.domain.entity.User +import java.util.* -interface UserRepository : JpaRepository +interface UserRepository : JpaRepository { + fun findByIdAndDeletedAtIsNull(id: Long): Optional +} From 8847a0d02d86d4307f747fef5b8c93c403827e1e Mon Sep 17 00:00:00 2001 From: 23tae Date: Mon, 26 Aug 2024 00:17:30 +0900 Subject: [PATCH 09/19] =?UTF-8?q?chore:=20=EC=98=88=EC=99=B8=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/uoslife/springaccount/common/error/ErrorCode.kt | 4 ++++ .../common/error/user/UserNotFoundException.kt | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt diff --git a/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt b/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt index 1327143..4627110 100644 --- a/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt +++ b/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt @@ -12,4 +12,8 @@ enum class ErrorCode(val code: String, val message: String, var status: Int) { "Internal Server Error.", HttpStatus.INTERNAL_SERVER_ERROR.value() ), + + // User + USER_NOT_FOUND("U01", "User Not Found.", HttpStatus.NOT_FOUND.value()), + } diff --git a/src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt b/src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt new file mode 100644 index 0000000..57ffd15 --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt @@ -0,0 +1,7 @@ +package uoslife.springaccount.common.error.user + +import uoslife.springaccount.common.error.ErrorCode +import uoslife.springaccount.common.error.baseexception.EntityNotFoundException + +class UserNotFoundException: EntityNotFoundException(ErrorCode.USER_NOT_FOUND) { +} \ No newline at end of file From 2d516e29c02ba9277cdfe26b154e4f5e5fce2420 Mon Sep 17 00:00:00 2001 From: 23tae Date: Mon, 26 Aug 2024 00:19:22 +0900 Subject: [PATCH 10/19] =?UTF-8?q?chore:=20=ED=83=88=ED=87=B4=EC=9D=BC?= =?UTF-8?q?=EC=8B=9C=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uoslife/springaccount/app/user/domain/entity/User.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt b/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt index 4ec9ad2..a05db41 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt @@ -7,6 +7,7 @@ import uoslife.springaccount.app.moderator.domain.entity.Moderators import uoslife.springaccount.app.verification.domain.entity.PortalAccounts import uoslife.springaccount.app.verification.domain.entity.Verifications import uoslife.springaccount.common.domain.config.TimeStamp +import java.time.LocalDateTime @Entity @Table(name = "`user`") @@ -40,6 +41,9 @@ class User( var avatarUrl: String? = avatarUrl protected set + @Column(name = "deleted_at") + var deletedAt: LocalDateTime? = null + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = [CascadeType.ALL]) protected val mutableDevices: MutableList = mutableListOf() val devices: List From 73c5f25d595f0531374ca16d6a255216930cade2 Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 27 Aug 2024 00:34:36 +0900 Subject: [PATCH 11/19] =?UTF-8?q?chore:=20userId=EA=B0=80=20null=EC=9D=B8?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt b/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt index 4627110..e84bee0 100644 --- a/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt +++ b/src/main/kotlin/uoslife/springaccount/common/error/ErrorCode.kt @@ -15,5 +15,5 @@ enum class ErrorCode(val code: String, val message: String, var status: Int) { // User USER_NOT_FOUND("U01", "User Not Found.", HttpStatus.NOT_FOUND.value()), - + USER_ID_NULL("U02", "User ID is Null", HttpStatus.INTERNAL_SERVER_ERROR.value()) } From 5cf6355d9182defdc3b43c50e3ca501edf5a9a99 Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 27 Aug 2024 00:36:24 +0900 Subject: [PATCH 12/19] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=A1=B0=ED=9A=8C=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/service/UserService.kt | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt b/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt index ddb293e..81b48cf 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt @@ -1,7 +1,36 @@ package uoslife.springaccount.app.user.service +import org.springframework.cache.CacheManager import org.springframework.stereotype.Service +import uoslife.springaccount.app.user.domain.repository.jpa.UserRepository +import uoslife.springaccount.app.user.dto.response.UserProfileDto +import uoslife.springaccount.common.error.user.UserNotFoundException @Service -class UserService { -} \ No newline at end of file +class UserService( + private val userRepository: UserRepository, + private val cacheManager: CacheManager, +) { + fun getProfile(userId: Long): UserProfileDto.UserProfileResponse { + val cacheKey = "uoslife:user:profile:$userId" + val cache = cacheManager.getCache("userProfileCache") + + // 캐시에서 데이터 가져오기 + val cachedData = cache?.get(cacheKey, UserProfileDto.UserProfileResponse::class.java) + if (cachedData != null) { + return cachedData + } + + // DB에서 유저 조회 + val user = + userRepository.findByIdAndDeletedAtIsNull(userId) ?: throw UserNotFoundException() + + // 유저 엔티티를 UserProfileResponse DTO로 변환 + val userProfileResponse = UserProfileDto.toUserProfileResponse(user) + + // 캐시에 저장 + cache?.put(cacheKey, userProfileResponse) + + return userProfileResponse + } +} From 4e54a5da00b46121a1234619650c558b8f965272 Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 27 Aug 2024 00:37:02 +0900 Subject: [PATCH 13/19] =?UTF-8?q?chore:=20jpa=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EA=B0=92=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/domain/repository/jpa/UserRepository.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt b/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt index c364241..5038d57 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/domain/repository/jpa/UserRepository.kt @@ -2,8 +2,7 @@ package uoslife.springaccount.app.user.domain.repository.jpa import org.springframework.data.jpa.repository.JpaRepository import uoslife.springaccount.app.user.domain.entity.User -import java.util.* interface UserRepository : JpaRepository { - fun findByIdAndDeletedAtIsNull(id: Long): Optional + fun findByIdAndDeletedAtIsNull(id: Long): User? } From 542ddd9c669ce0a3409c0288f3213053302b7eb6 Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 27 Aug 2024 00:38:13 +0900 Subject: [PATCH 14/19] =?UTF-8?q?feat:=20user=20entity=EB=A5=BC=20Dto?= =?UTF-8?q?=EC=97=90=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/dto/response/UserProfileDto.kt | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt b/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt index d0ced77..57c27ce 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt @@ -1,6 +1,9 @@ package uoslife.springaccount.app.user.dto.response +import uoslife.springaccount.app.user.domain.entity.User import uoslife.springaccount.app.verification.domain.entity.VerificationMethod +import uoslife.springaccount.common.error.ErrorCode +import uoslife.springaccount.common.error.baseexception.BusinessException class UserProfileDto { @@ -31,11 +34,46 @@ class UserProfileDto { val phone: String, val name: String?, val email: String?, - val realm: UserRealm?, + // val realm: UserRealm?, val identity: UserProfileIdentity?, val moderator: UserProfileModerator?, val isLinkedPortal: Boolean, val isVerified: Boolean, val verificationMethod: VerificationMethod?, ) + + companion object { + fun toUserProfileResponse(user: User): UserProfileResponse { + return UserProfileResponse( + id = user.id ?: throw BusinessException(ErrorCode.USER_ID_NULL), + nickname = user.nickname ?: "No Nickname", + phone = user.phoneNumber, + name = user.name, + email = user.email, + identity = + user.identities.firstOrNull()?.let { identity -> + UserProfileIdentity( + id = identity.id, + type = identity.type, + status = identity.status, + idNumber = identity.idNumber, + university = identity.university, + department = identity.department, + major = identity.major + ) + }, + moderator = + user.moderators.firstOrNull()?.let { + UserProfileModerator( + generation = it.generation, + chapter = it.chapter, + role = it.role + ) + }, + isLinkedPortal = user.portalAccounts.isNotEmpty(), + isVerified = user.verifications.isNotEmpty(), + verificationMethod = user.verifications.firstOrNull()?.method + ) + } + } } From 117cd82dcfd75f81dcb797026291113be0470ab1 Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 27 Aug 2024 00:44:23 +0900 Subject: [PATCH 15/19] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/controller/UserController.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt index 2d66323..e3f6892 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt @@ -1,16 +1,31 @@ package uoslife.springaccount.app.user.controller +import org.springframework.http.ResponseEntity import org.springframework.security.core.annotation.AuthenticationPrincipal import org.springframework.security.core.userdetails.UserDetails import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import uoslife.springaccount.app.user.dto.response.UserProfileDto import uoslife.springaccount.app.user.service.UserService @RestController +@RequestMapping("/v2/user") class UserController(private val userService: UserService) { @GetMapping("/me") - fun getMyProfile(@AuthenticationPrincipal userDetails: UserDetails) { + fun getMyProfile( + @AuthenticationPrincipal userDetails: UserDetails + ): ResponseEntity { val userId = userDetails.username.toLong() + return ResponseEntity.ok(userService.getProfile(userId)) + } + + @GetMapping("/{userId}") + fun getProfile( + @PathVariable userId: Long, + ): ResponseEntity { + return ResponseEntity.ok(userService.getProfile(userId)) } } From 196f2c02e947b1c50dbe208c2099c2634c9719ce Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 27 Aug 2024 00:45:21 +0900 Subject: [PATCH 16/19] =?UTF-8?q?style:=20ktfmt=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/uoslife/springaccount/SpringAccountApplication.kt | 1 - .../uoslife/springaccount/app/user/domain/entity/User.kt | 5 ++--- .../springaccount/common/error/user/UserNotFoundException.kt | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt b/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt index 377a3e4..5bdc0ad 100644 --- a/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt +++ b/src/main/kotlin/uoslife/springaccount/SpringAccountApplication.kt @@ -6,7 +6,6 @@ import org.springframework.cache.annotation.EnableCaching @SpringBootApplication @EnableCaching class SpringAccountApplication - fun main(args: Array) { runApplication(*args) } diff --git a/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt b/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt index a05db41..9f43811 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/domain/entity/User.kt @@ -1,13 +1,13 @@ package uoslife.springaccount.app.user.domain.entity import jakarta.persistence.* +import java.time.LocalDateTime import uoslife.springaccount.app.device.domain.entity.Device import uoslife.springaccount.app.identity.domain.entity.Identity import uoslife.springaccount.app.moderator.domain.entity.Moderators import uoslife.springaccount.app.verification.domain.entity.PortalAccounts import uoslife.springaccount.app.verification.domain.entity.Verifications import uoslife.springaccount.common.domain.config.TimeStamp -import java.time.LocalDateTime @Entity @Table(name = "`user`") @@ -41,8 +41,7 @@ class User( var avatarUrl: String? = avatarUrl protected set - @Column(name = "deleted_at") - var deletedAt: LocalDateTime? = null + @Column(name = "deleted_at") var deletedAt: LocalDateTime? = null @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = [CascadeType.ALL]) protected val mutableDevices: MutableList = mutableListOf() diff --git a/src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt b/src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt index 57ffd15..8f0a5de 100644 --- a/src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt +++ b/src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt @@ -3,5 +3,4 @@ package uoslife.springaccount.common.error.user import uoslife.springaccount.common.error.ErrorCode import uoslife.springaccount.common.error.baseexception.EntityNotFoundException -class UserNotFoundException: EntityNotFoundException(ErrorCode.USER_NOT_FOUND) { -} \ No newline at end of file +class UserNotFoundException : EntityNotFoundException(ErrorCode.USER_NOT_FOUND) {} From e71cef88da09c2a65b82e1be918aeb14c4496e3f Mon Sep 17 00:00:00 2001 From: 23tae Date: Tue, 27 Aug 2024 16:44:41 +0900 Subject: [PATCH 17/19] =?UTF-8?q?chore:=20database=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c65b411..3507c11 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,4 +9,20 @@ spring: data: redis: host: ${REDIS_HOST} - port: ${REDIS_PORT} \ No newline at end of file + port: ${REDIS_PORT} + datasource: + url: jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_DATABASE}?stringtype=unspecified + username: ${DATABASE_USERNAME} + password: ${DATABASE_PASSWORD} + driver-class-name: org.postgresql.Driver + jpa: + hibernate: + ddl-auto: validate + database-platform: org.hibernate.dialect.PostgreSQLDialect + generate-ddl: false + open-in-view: false + properties: + hibernate: + default_batch_fetch_size: 1000 + show_sql: true + format_sql: true From ae0a7e06e68ca232da6c5e5cfbc07d0679b6a87e Mon Sep 17 00:00:00 2001 From: 23tae Date: Wed, 28 Aug 2024 18:16:31 +0900 Subject: [PATCH 18/19] =?UTF-8?q?fix:=20Redis=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/user/service/UserService.kt | 26 ++++++++++++------- .../springaccount/app/user/util/UserConfig.kt | 7 +++++ 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/uoslife/springaccount/app/user/util/UserConfig.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt b/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt index 81b48cf..26e066a 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt @@ -1,22 +1,26 @@ package uoslife.springaccount.app.user.service -import org.springframework.cache.CacheManager +import java.util.concurrent.TimeUnit +import org.redisson.api.RBucket +import org.redisson.api.RedissonClient import org.springframework.stereotype.Service import uoslife.springaccount.app.user.domain.repository.jpa.UserRepository import uoslife.springaccount.app.user.dto.response.UserProfileDto +import uoslife.springaccount.app.user.util.UserConfig import uoslife.springaccount.common.error.user.UserNotFoundException @Service class UserService( private val userRepository: UserRepository, - private val cacheManager: CacheManager, + private val redisClient: RedissonClient, ) { + fun getProfile(userId: Long): UserProfileDto.UserProfileResponse { - val cacheKey = "uoslife:user:profile:$userId" - val cache = cacheManager.getCache("userProfileCache") + val cacheKey = getProfileCacheKey(userId) - // 캐시에서 데이터 가져오기 - val cachedData = cache?.get(cacheKey, UserProfileDto.UserProfileResponse::class.java) + // 캐시된 데이터 가져오기 + val bucket: RBucket = redisClient.getBucket(cacheKey) + val cachedData = bucket.get() if (cachedData != null) { return cachedData } @@ -25,12 +29,16 @@ class UserService( val user = userRepository.findByIdAndDeletedAtIsNull(userId) ?: throw UserNotFoundException() - // 유저 엔티티를 UserProfileResponse DTO로 변환 + // User 엔티티를 DTO로 변환 val userProfileResponse = UserProfileDto.toUserProfileResponse(user) - // 캐시에 저장 - cache?.put(cacheKey, userProfileResponse) + // 캐시 저장 + bucket.set(userProfileResponse, UserConfig.USER_PROFILE_CACHE_TTL, TimeUnit.SECONDS) return userProfileResponse } + + private fun getProfileCacheKey(userId: Long): String { + return "uoslife:user:profile:$userId" + } } diff --git a/src/main/kotlin/uoslife/springaccount/app/user/util/UserConfig.kt b/src/main/kotlin/uoslife/springaccount/app/user/util/UserConfig.kt new file mode 100644 index 0000000..402b20f --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/user/util/UserConfig.kt @@ -0,0 +1,7 @@ +package uoslife.springaccount.app.user.util + +class UserConfig { + companion object { + const val USER_PROFILE_CACHE_TTL: Long = 60 * 60 // 유저 정보 저장 시간. 1시간 + } +} From 5b057bf9d66515376295767915dc3c33c58c0f63 Mon Sep 17 00:00:00 2001 From: 23tae Date: Thu, 26 Sep 2024 18:28:42 +0900 Subject: [PATCH 19/19] =?UTF-8?q?fix:=20=ED=86=A0=ED=81=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20userId=20=EC=82=AC=EC=9A=A9=20=EB=B0=A9=EC=8B=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springaccount/app/user/controller/UserController.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt index e3f6892..f5e3030 100644 --- a/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt +++ b/src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import uoslife.springaccount.app.user.dto.response.UserProfileDto import uoslife.springaccount.app.user.service.UserService +import uoslife.springaccount.common.security.annotation.UserId @RestController @RequestMapping("/v2/user") @@ -16,9 +17,8 @@ class UserController(private val userService: UserService) { @GetMapping("/me") fun getMyProfile( - @AuthenticationPrincipal userDetails: UserDetails + @UserId userId: Long ): ResponseEntity { - val userId = userDetails.username.toLong() return ResponseEntity.ok(userService.getProfile(userId)) }