-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: user message payload 핸들러 및 user save service 구현
- Loading branch information
Showing
7 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
community-application/src/main/kotlin/gloddy/user/port/in/dto/UserSaveRequest.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,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 | ||
) |
7 changes: 7 additions & 0 deletions
7
community-application/src/main/kotlin/gloddy/user/port/out/UserCommandPort.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 gloddy.user.port.out | ||
|
||
import gloddy.user.User | ||
|
||
interface UserCommandPort { | ||
fun save(user: User): User | ||
} |
16 changes: 16 additions & 0 deletions
16
community-application/src/main/kotlin/gloddy/user/service/UserCommandService.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,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()) | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...rastructure/src/main/kotlin/gloddy/inMessage/payload/handler/UserMessagePayloadHandler.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,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 | ||
) | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...nity-infrastructure/src/main/kotlin/gloddy/persistence/user/adapter/UserCommandAdapter.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,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() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
community-infrastructure/src/main/kotlin/gloddy/persistence/util/mapper/UserMapper.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,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 | ||
) |