-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: user #2
Open
23tae
wants to merge
21
commits into
main
Choose a base branch
from
feat/user
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: user #2
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b8ad1fa
feat: controller, service ์์ฑ
23tae e3be647
chore: ์์กด์ฑ ์ฃผ์
23tae 2cd815d
chore: ์๋ต์ฉ ์ ์ ์ ๋ณด dto
23tae 6575451
chore: verificationMethod ํ๋ ์ถ๊ฐ
23tae bd2b2dc
chore: param DTO ์์ฑ
23tae 00a94e2
feat: ์์ ์ ํ๋กํ ์ ๋ณด ์กฐํ
23tae c889057
Merge remote-tracking branch 'origin/feat/redis' into feat/user
23tae 046464c
build: redis ์ค์
23tae 01dffdd
feat: id๋ก ์ฌ์ฉ์๋ฅผ ์ฐพ๋ ๋ฉ์๋ ์ ์
23tae 8847a0d
chore: ์์ธ ์ ์
23tae 2d516e2
chore: ํํด์ผ์ ํ๋ ์ถ๊ฐ
23tae 73c5f25
chore: userId๊ฐ null์ธ ๊ฒฝ์ฐ ์๋ฌ์ฝ๋ ์ถ๊ฐ
23tae 5cf6355
feat: ์ ์ ํ๋กํ ์กฐํ ๋น์ฆ๋์ค ๋ก์ง
23tae 4e54a5d
chore: jpa ๋ฐํ๊ฐ ์์
23tae 542ddd9
feat: user entity๋ฅผ Dto์ ๋งคํ
23tae 117cd82
feat: ์ ์ ํ๋กํ ์กฐํ API
23tae 196f2c0
style: ktfmt ์ ์ฉ
23tae e71cef8
chore: database ๊ด๋ จ ์ค์
23tae ae0a7e0
fix: Redis ์ฌ์ฉ ๋ฐฉ์ ๋ณ๊ฒฝ
23tae 54ab978
merge main into feat/user
23tae 5b057bf
fix: ํ ํฐ์์ userId ์ฌ์ฉ ๋ฐฉ์ ๋ณ๊ฒฝ
23tae 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 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
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/uoslife/springaccount/app/user/controller/UserController.kt
This file contains 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,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 | ||
import uoslife.springaccount.common.security.annotation.UserId | ||
|
||
@RestController | ||
@RequestMapping("/v2/user") | ||
class UserController(private val userService: UserService) { | ||
|
||
@GetMapping("/me") | ||
fun getMyProfile( | ||
@UserId userId: Long | ||
): ResponseEntity<UserProfileDto.UserProfileResponse> { | ||
return ResponseEntity.ok(userService.getProfile(userId)) | ||
} | ||
|
||
@GetMapping("/{userId}") | ||
fun getProfile( | ||
@PathVariable userId: Long, | ||
): ResponseEntity<UserProfileDto.UserProfileResponse> { | ||
return ResponseEntity.ok(userService.getProfile(userId)) | ||
} | ||
} |
This file contains 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 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
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/uoslife/springaccount/app/user/dto/param/CreateUserDto.kt
This file contains 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,3 @@ | ||
package uoslife.springaccount.app.user.dto.param | ||
|
||
data class CreateUserDto(val nickname: String, val phoneNumber: String) |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/uoslife/springaccount/app/user/dto/param/UpdateUserDto.kt
This file contains 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,3 @@ | ||
package uoslife.springaccount.app.user.dto.param | ||
|
||
data class UpdateUserDto(val nickname: String?) |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/uoslife/springaccount/app/user/dto/param/UserWithInfoDto.kt
This file contains 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,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<Identity>, | ||
val portalAccounts: List<PortalAccounts>, | ||
val verifications: List<Verifications>, | ||
val moderator: Moderators?, | ||
) |
79 changes: 79 additions & 0 deletions
79
src/main/kotlin/uoslife/springaccount/app/user/dto/response/UserProfileDto.kt
This file contains 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,79 @@ | ||
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 { | ||
|
||
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, | ||
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 | ||
) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/uoslife/springaccount/app/user/service/UserService.kt
This file contains 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,44 @@ | ||
package uoslife.springaccount.app.user.service | ||
|
||
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 redisClient: RedissonClient, | ||
) { | ||
|
||
fun getProfile(userId: Long): UserProfileDto.UserProfileResponse { | ||
val cacheKey = getProfileCacheKey(userId) | ||
|
||
// ์บ์๋ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ | ||
val bucket: RBucket<UserProfileDto.UserProfileResponse> = redisClient.getBucket(cacheKey) | ||
val cachedData = bucket.get() | ||
if (cachedData != null) { | ||
return cachedData | ||
} | ||
|
||
// DB์์ ์ ์ ์กฐํ | ||
val user = | ||
userRepository.findByIdAndDeletedAtIsNull(userId) ?: throw UserNotFoundException() | ||
|
||
// User ์ํฐํฐ๋ฅผ DTO๋ก ๋ณํ | ||
val userProfileResponse = UserProfileDto.toUserProfileResponse(user) | ||
|
||
// ์บ์ ์ ์ฅ | ||
bucket.set(userProfileResponse, UserConfig.USER_PROFILE_CACHE_TTL, TimeUnit.SECONDS) | ||
|
||
return userProfileResponse | ||
} | ||
|
||
private fun getProfileCacheKey(userId: Long): String { | ||
return "uoslife:user:profile:$userId" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/uoslife/springaccount/app/user/util/UserConfig.kt
This file contains 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,7 @@ | ||
package uoslife.springaccount.app.user.util | ||
|
||
class UserConfig { | ||
companion object { | ||
const val USER_PROFILE_CACHE_TTL: Long = 60 * 60 // ์ ์ ์ ๋ณด ์ ์ฅ ์๊ฐ. 1์๊ฐ | ||
} | ||
} |
This file contains 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
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/uoslife/springaccount/common/error/user/UserNotFoundException.kt
This file contains 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,6 @@ | ||
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) {} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BusinessException์ ErrorCode๋ฅผ ๋ฃ๋ ๊ฒ๋ณด๋ค BusinessException ๊ฐ์ฒด๋ฅผ ์์ํ UserNullException ๊ฐ์ ๊ฑธ ๋ง๋ค์ด ์ฐ๋ ๊ฒ ๊ฐ์ต๋๋ค