From 056567cdd546c2a7c29b3c1535db3dfcdc4ab85d Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Tue, 14 Nov 2023 09:03:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=93=9D=20::=20""=20->=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/example/onui/global/config/jwt/TokenProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/example/onui/global/config/jwt/TokenProvider.kt b/src/main/kotlin/com/example/onui/global/config/jwt/TokenProvider.kt index c0e2b6a..cabff44 100644 --- a/src/main/kotlin/com/example/onui/global/config/jwt/TokenProvider.kt +++ b/src/main/kotlin/com/example/onui/global/config/jwt/TokenProvider.kt @@ -72,7 +72,7 @@ class TokenProvider( val authDetails = authDetailsService.loadUserByUsername(subject) as AuthDetails - return UsernamePasswordAuthenticationToken(authDetails, "", authDetails.authorities) + return UsernamePasswordAuthenticationToken(authDetails, null, authDetails.authorities) } fun reissue(token: String): TokenResponse { From 289a0e18b99302d695804f053616634cda53cefe Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Wed, 15 Nov 2023 11:42:57 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20Date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt | 3 ++- .../timeline/presentation/dto/response/TimelineResponse.kt | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt b/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt index dd425da..9973d9c 100644 --- a/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt +++ b/src/main/kotlin/com/example/onui/domain/diary/entity/Diary.kt @@ -81,6 +81,7 @@ Diary( this.tagList, this.image, this.user.name, - this.commentList.size + this.commentList.size, + this.createdAt.toLocalDate() ) } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt index 0f93e6c..b1875d1 100644 --- a/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt +++ b/src/main/kotlin/com/example/onui/domain/timeline/presentation/dto/response/TimelineResponse.kt @@ -1,6 +1,7 @@ package com.example.onui.domain.timeline.presentation.dto.response import com.example.onui.domain.diary.entity.Mood +import java.time.LocalDate import java.util.* data class TimelineResponse( @@ -10,5 +11,6 @@ data class TimelineResponse( val tagList: MutableList, val image: String?, val writer: String, - val commentCount: Int + val commentCount: Int, + val date: LocalDate ) From b1b8ed8e6e2258c383cb046c1bd1a51fee6d81f2 Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Wed, 15 Nov 2023 11:43:34 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20theme=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/exception/ThemeNotFoundException.kt | 6 +++++ .../user/presentation/UserController.kt | 7 ++++++ .../presentation/dto/request/ChangeRequest.kt | 9 +++++++ .../onui/domain/user/service/UserService.kt | 2 ++ .../domain/user/service/UserServiceImpl.kt | 25 ++++++++++++------- .../global/config/error/data/ErrorCode.kt | 1 + 6 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/com/example/onui/domain/user/exception/ThemeNotFoundException.kt create mode 100644 src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeRequest.kt diff --git a/src/main/kotlin/com/example/onui/domain/user/exception/ThemeNotFoundException.kt b/src/main/kotlin/com/example/onui/domain/user/exception/ThemeNotFoundException.kt new file mode 100644 index 0000000..da99036 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/user/exception/ThemeNotFoundException.kt @@ -0,0 +1,6 @@ +package com.example.onui.domain.user.exception + +import com.example.onui.global.config.error.data.ErrorCode +import com.example.onui.global.config.error.exception.BusinessException + +object ThemeNotFoundException : BusinessException(ErrorCode.THEME_NOT_FOUND) \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/user/presentation/UserController.kt b/src/main/kotlin/com/example/onui/domain/user/presentation/UserController.kt index 530e19e..18a2292 100644 --- a/src/main/kotlin/com/example/onui/domain/user/presentation/UserController.kt +++ b/src/main/kotlin/com/example/onui/domain/user/presentation/UserController.kt @@ -1,5 +1,6 @@ package com.example.onui.domain.user.presentation +import com.example.onui.domain.user.presentation.dto.request.ChangeRequest import com.example.onui.domain.user.presentation.dto.request.RenameRequest import com.example.onui.domain.user.presentation.dto.response.UserProfileResponse import com.example.onui.domain.user.service.UserService @@ -22,4 +23,10 @@ class UserController( @GetMapping("/profile") fun getProfile(): UserProfileResponse = userService.getProfile() + + @PatchMapping("/theme") + fun changeTheme( + @RequestBody @Valid + req: ChangeRequest + ): UserProfileResponse = userService.changeTheme(req.theme) } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeRequest.kt b/src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeRequest.kt new file mode 100644 index 0000000..d379a44 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeRequest.kt @@ -0,0 +1,9 @@ +package com.example.onui.domain.user.presentation.dto.request + +import javax.validation.constraints.NotBlank + +data class ChangeRequest( + + @field:NotBlank(message = "theme가 null일 수 없습니다.") + val theme: String +) \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/user/service/UserService.kt b/src/main/kotlin/com/example/onui/domain/user/service/UserService.kt index 8e19ce4..b9f3dd4 100644 --- a/src/main/kotlin/com/example/onui/domain/user/service/UserService.kt +++ b/src/main/kotlin/com/example/onui/domain/user/service/UserService.kt @@ -7,4 +7,6 @@ interface UserService { fun rename(name: String): UserProfileResponse fun getProfile(): UserProfileResponse + + fun changeTheme(themeId: String): UserProfileResponse } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/user/service/UserServiceImpl.kt b/src/main/kotlin/com/example/onui/domain/user/service/UserServiceImpl.kt index 063b382..939af9b 100644 --- a/src/main/kotlin/com/example/onui/domain/user/service/UserServiceImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/user/service/UserServiceImpl.kt @@ -1,9 +1,12 @@ package com.example.onui.domain.user.service import com.example.onui.domain.user.entity.User +import com.example.onui.domain.user.exception.ThemeNotFoundException import com.example.onui.domain.user.presentation.dto.response.UserProfileResponse +import com.example.onui.domain.user.repository.ThemeRepository import com.example.onui.domain.user.repository.UserRepository import com.example.onui.global.common.facade.UserFacade +import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -11,7 +14,8 @@ import org.springframework.transaction.annotation.Transactional @Transactional(readOnly = true) class UserServiceImpl( private val userRepository: UserRepository, - private val userFacade: UserFacade + private val userFacade: UserFacade, + private val themeRepository: ThemeRepository ) : UserService { @Transactional @@ -19,15 +23,18 @@ class UserServiceImpl( val user = userFacade.getCurrentUser() - return userRepository.save( - User( - user.sub, - name, - user.theme, - user.id - ) - ).toResponse() + return userRepository.save(User(user.sub, name, user.theme, user.id)).toResponse() } override fun getProfile(): UserProfileResponse = userFacade.getCurrentUser().toResponse() + + @Transactional + override fun changeTheme(themeId: String): UserProfileResponse { + + val user = userFacade.getCurrentUser() + + val theme = themeRepository.findByIdOrNull(themeId) ?: throw ThemeNotFoundException + + return userRepository.save(User(user.sub, user.name, theme, user.id, user.role)).toResponse() + } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt b/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt index b4100ad..d1c80c9 100644 --- a/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt +++ b/src/main/kotlin/com/example/onui/global/config/error/data/ErrorCode.kt @@ -24,6 +24,7 @@ enum class ErrorCode( // 404 DIARY_NOT_FOUND(HttpStatus.NOT_FOUND, "감정 기록을 찾을 수 없습니다."), TIMELINE_NOT_FOUND(HttpStatus.NOT_FOUND, "타임라인을 찾을 수 없습니다."), + THEME_NOT_FOUND(HttpStatus.NOT_FOUND, "테마를 찾을 수 없습니다."), // 500 INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 에러")