From 97819dabb98d82ed5fa73eaf0750748578e78b0a Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Thu, 16 Nov 2023 17:04:58 +0900 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20profile=20theme?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/presentation/UserController.kt | 7 +++++++ .../dto/request/ChangeProfileThemeRequest.kt | 9 +++++++++ .../onui/domain/user/service/UserService.kt | 2 ++ .../onui/domain/user/service/UserServiceImpl.kt | 17 +++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeProfileThemeRequest.kt 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 7e8a1e3..03d29db 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,6 +1,7 @@ package com.example.onui.domain.user.presentation import com.example.onui.domain.user.presentation.dto.request.ChangeFilterRequest +import com.example.onui.domain.user.presentation.dto.request.ChangeProfileThemeRequest import com.example.onui.domain.user.presentation.dto.request.ChangeThemeRequest import com.example.onui.domain.user.presentation.dto.request.RenameRequest import com.example.onui.domain.user.presentation.dto.response.ThemeResponse @@ -26,6 +27,12 @@ class UserController( @GetMapping("/profile") fun getProfile(): UserProfileResponse = userService.getProfile() + @PatchMapping("/profile") + fun changeProfileTheme( + @RequestBody @Valid + req: ChangeProfileThemeRequest + ): UserProfileResponse = userService.changeProfileTheme(req.profileTheme!!) + @PatchMapping("/theme") fun changeTheme( @RequestBody @Valid diff --git a/src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeProfileThemeRequest.kt b/src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeProfileThemeRequest.kt new file mode 100644 index 0000000..b43526b --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/user/presentation/dto/request/ChangeProfileThemeRequest.kt @@ -0,0 +1,9 @@ +package com.example.onui.domain.user.presentation.dto.request + +import javax.validation.constraints.NotBlank + +data class ChangeProfileThemeRequest( + + @field:NotBlank(message = "profile_theme가 null일 수 없습니다.") + val profileTheme: String? +) 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 1b553db..af49e74 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 @@ -16,4 +16,6 @@ interface UserService { fun changeFilter(onFiltering: Boolean): UserProfileResponse fun getTheme(): ThemeResponse + + fun changeProfileTheme(profileTheme: 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 fed19eb..1c9c9f8 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 @@ -90,4 +90,21 @@ class UserServiceImpl( } override fun getTheme() = ThemeResponse(userFacade.getCurrentUser().theme.id) + + @Transactional + override fun changeProfileTheme(profileTheme: String): UserProfileResponse { + val user = userFacade.getCurrentUser() + + return userRepository.save( + User( + user.sub, + user.name, + profileTheme, + user.theme, + user.id, + user.role, + user.onFiltering + ) + ).toResponse() + } } \ No newline at end of file