Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 15, 2023
2 parents b240034 + b1b8ed8 commit d3d22e8
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Diary(
this.tagList,
this.image,
this.user.name,
this.commentList.size
this.commentList.size,
this.createdAt.toLocalDate()
)
}
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -10,5 +11,6 @@ data class TimelineResponse(
val tagList: MutableList<String>,
val image: String?,
val writer: String,
val commentCount: Int
val commentCount: Int,
val date: LocalDate
)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface UserService {
fun rename(name: String): UserProfileResponse

fun getProfile(): UserProfileResponse

fun changeTheme(themeId: String): UserProfileResponse
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
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

@Service
@Transactional(readOnly = true)
class UserServiceImpl(
private val userRepository: UserRepository,
private val userFacade: UserFacade
private val userFacade: UserFacade,
private val themeRepository: ThemeRepository
) : UserService {

@Transactional
override fun rename(name: String): UserProfileResponse {

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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "์„œ๋ฒ„ ๋‚ด๋ถ€ ์—๋Ÿฌ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d3d22e8

Please sign in to comment.