Skip to content

Commit

Permalink
feat: user message payload 핸들러 및 user save service 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jihwan2da committed Feb 4, 2024
1 parent bc17c91 commit ea87a1b
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gloddy.user.port.`in`.dto

import gloddy.user.User

data class UserSaveRequest(
val id: Long,
val isCertifiedStudent: Boolean,
val profileImage: String,
val nickName: String,
val countryName: String?,
val countryImage: String?,
val reliabilityLevel: String
)

fun UserSaveRequest.toDomain(): User =
User(
id = this.id,
isCertifiedStudent = this.isCertifiedStudent,
profileImage = this.profileImage,
nickname = this.nickName,
countryName = this.countryName,
countryImage = this.countryImage,
reliabilityLevel = this.reliabilityLevel
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gloddy.user.port.out

import gloddy.user.User

interface UserCommandPort {
fun save(user: User): User
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gloddy.user.service

import gloddy.user.port.`in`.dto.UserSaveRequest
import gloddy.user.port.`in`.dto.toDomain
import gloddy.user.port.out.UserCommandPort
import org.springframework.stereotype.Service

@Service
class UserCommandService(
private val userCommandPort: UserCommandPort
) {

fun save(request: UserSaveRequest) {
userCommandPort.save(request.toDomain())
}
}
5 changes: 4 additions & 1 deletion community-domain/src/main/kotlin/gloddy/core/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ enum class ErrorCode(
ARTICLE_NO_AUTHORIZATION(401, "ARTICLE_003", "해당 게시글에 권한이 없습니다."),

// Category
CATEGORY_NOT_FOUND(404, "CATEGORY_001", "해당 카테고리를 찾을 수 없습니다.")
CATEGORY_NOT_FOUND(404, "CATEGORY_001", "해당 카테고리를 찾을 수 없습니다."),

// User
USER_NOT_FOUND(404, "COMMUNITY_USER_001", "해당 유저를 찾을 수 없습니다.")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gloddy.inMessage.payload.handler

import gloddy.inMessage.payload.UserMessagePayload
import gloddy.internal.client.UserQueryClient
import gloddy.user.port.`in`.dto.UserSaveRequest
import gloddy.user.service.UserCommandService
import org.springframework.stereotype.Component

@Component
class UserMessagePayloadHandler(
private val userQueryClient: UserQueryClient,
private val userCommandService: UserCommandService
) {

fun handle(payload: UserMessagePayload) {
val userPreviewPayload = userQueryClient.getUserPreview(payload.userId)
userCommandService.save(
UserSaveRequest(
id = userPreviewPayload.id,
isCertifiedStudent = userPreviewPayload.isCertifiedStudent,
profileImage = userPreviewPayload.profileImage,
nickName = userPreviewPayload.nickName,
countryName = userPreviewPayload.countryName,
countryImage = userPreviewPayload.countryImage,
reliabilityLevel = userPreviewPayload.reliabilityLevel
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gloddy.persistence.user.adapter

import gloddy.persistence.user.repository.UserJpaRepository
import gloddy.persistence.util.mapper.toDomain
import gloddy.persistence.util.mapper.toEntity
import gloddy.user.User
import gloddy.user.port.out.UserCommandPort
import org.springframework.stereotype.Component

@Component
class UserCommandAdapter(
private val userJpaRepository: UserJpaRepository,
) : UserCommandPort {

override fun save(user: User): User {
return userJpaRepository.save(user.toEntity()).toDomain()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gloddy.persistence.util.mapper

import gloddy.persistence.user.UserJpaEntity
import gloddy.user.User

fun User.toEntity(): UserJpaEntity =
UserJpaEntity(
id = this.id,
isCertifiedStudent = this.isCertifiedStudent,
profileImage = this.profileImage,
nickname = this.nickname,
countryName = this.countryName,
countryImage = this.countryImage,
reliabilityLevel = this.reliabilityLevel
)

fun UserJpaEntity.toDomain(): User =
User(
id = this.id,
isCertifiedStudent = this.isCertifiedStudent,
profileImage = this.profileImage,
nickname = this.nickname,
countryName = this.countryName,
countryImage = this.countryImage,
reliabilityLevel = this.reliabilityLevel
)

0 comments on commit ea87a1b

Please sign in to comment.