Skip to content

Commit

Permalink
refactor(user): Add user domain convert oas model (#41)
Browse files Browse the repository at this point in the history
* add user domain convert oas model

* rm new line

* lint check

* Change use object model
  • Loading branch information
dojinyou authored Dec 17, 2024
1 parent e8b3505 commit d2afb97
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.threedays.bootstrap.api.user

import com.threedays.oas.model.BirthYearRange
import com.threedays.oas.model.CompanyDisplayInfo
import com.threedays.oas.model.Gender
import com.threedays.oas.model.JobOccupation
import com.threedays.oas.model.JobOccupationDisplayInfo
import com.threedays.oas.model.LocationDisplayInfo
import com.threedays.oas.model.PreferDistance
import com.threedays.oas.model.ProfileImage
import com.threedays.oas.model.ProfileImageExtension
import com.threedays.oas.model.ProfileWidget
import com.threedays.oas.model.ProfileWidgetType
import com.threedays.oas.model.UserDesiredPartner
import com.threedays.oas.model.UserProfile
import com.threedays.oas.model.UserProfileDisplayInfo

object OASModelAdapter {
fun toOASModel(domainModel: com.threedays.domain.user.entity.UserProfileImage): ProfileImage = ProfileImage(
id = domainModel.id.value,
url = domainModel.url.toURI(),
extension = ProfileImageExtension.valueOf(domainModel.extension.name),
)

fun toUserProfileDisplayInfo(domainModel: com.threedays.domain.user.entity.UserProfile): UserProfileDisplayInfo =
UserProfileDisplayInfo(
gender = Gender.valueOf(domainModel.gender.name),
birthYear = domainModel.birthYear.value,
jobOccupation = JobOccupationDisplayInfo(
code = JobOccupation.valueOf(domainModel.jobOccupation.name),
display = domainModel.jobOccupation.koreanName
),
locations = domainModel.locations.map {
LocationDisplayInfo(
id = it.id.value,
display = it.display,
)
},
company = domainModel.company?.let {
CompanyDisplayInfo(
id = it.id.value,
display = it.display,
)
},
)

fun toOASModel(domainModel: com.threedays.domain.user.entity.UserProfile) = UserProfile(
gender = Gender.valueOf(domainModel.gender.name),
birthYear = domainModel.birthYear.value,
jobOccupation = JobOccupation.valueOf(domainModel.jobOccupation.name),
locationIds = domainModel.locations.map { it.id.value },
companyId = domainModel.company?.id?.value,
)

fun toOASModel(domainModel: com.threedays.domain.user.entity.ProfileWidget) = ProfileWidget(
type = ProfileWidgetType.valueOf(domainModel.type.name),
content = domainModel.content,
)

fun toDomainModel(oasModel: ProfileWidget) = com.threedays.domain.user.entity.ProfileWidget(
type = com.threedays.domain.user.entity.ProfileWidget.Type.valueOf(oasModel.type.name),
content = oasModel.content,
)

fun toOASModel(domainModel: com.threedays.domain.user.entity.UserDesiredPartner) = UserDesiredPartner(
jobOccupations = domainModel.jobOccupations.map {
JobOccupation.valueOf(it.name)
},
birthYearRange = domainModel.birthYearRange.let {
BirthYearRange(
start = it.start?.value,
end = it.end?.value,
)
},
preferDistance = PreferDistance.valueOf(domainModel.preferDistance.name),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ import com.threedays.domain.user.vo.BirthYearRange
import com.threedays.domain.user.vo.Gender
import com.threedays.domain.user.vo.JobOccupation
import com.threedays.oas.api.UsersApi
import com.threedays.oas.model.CompanyDisplayInfo
import com.threedays.oas.model.CompleteProfileImageUploadRequest
import com.threedays.oas.model.GetMyUserInfoResponse
import com.threedays.oas.model.GetProfileImageUploadUrlResponse
import com.threedays.oas.model.JobOccupationDisplayInfo
import com.threedays.oas.model.LocationDisplayInfo
import com.threedays.oas.model.PreferDistance
import com.threedays.oas.model.ProfileImage
import com.threedays.oas.model.ProfileImageExtension
import com.threedays.oas.model.ProfileWidget
import com.threedays.oas.model.ProfileWidgetType
Expand All @@ -36,8 +31,6 @@ import com.threedays.oas.model.UpdateMyUserInfoRequest
import com.threedays.oas.model.UpdateMyUserInfoResponse
import com.threedays.oas.model.UpdateUserDesiredPartnerRequest
import com.threedays.oas.model.UpdateUserDesiredPartnerResponse
import com.threedays.oas.model.UserProfile
import com.threedays.oas.model.UserProfileDisplayInfo
import com.threedays.support.common.base.domain.UUIDTypeId
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
Expand All @@ -60,7 +53,7 @@ class UserController(

override fun registerUser(
xRegisterToken: String,
registerUserRequest: RegisterUserRequest
registerUserRequest: RegisterUserRequest,
): ResponseEntity<TokenResponse> {
val result: RegisterUser.Result = RegisterUser.Command(
name = User.Name(registerUserRequest.name),
Expand Down Expand Up @@ -105,65 +98,19 @@ class UserController(
GetMyUserInfoResponse(
id = user.id.value,
name = user.name.value,
profileImages = user.profileImages.map {
ProfileImage(
id = it.id.value,
url = it.url.toURI(),
extension = ProfileImageExtension.valueOf(it.extension.name)
)
},
profileImages = user.profileImages.map(OASModelAdapter::toOASModel),
phoneNumber = user.phoneNumber.value,
profile = UserProfileDisplayInfo(
gender = com.threedays.oas.model.Gender.valueOf(user.profile.gender.name),
birthYear = user.profile.birthYear.value,
jobOccupation = JobOccupationDisplayInfo(
code = com.threedays.oas.model.JobOccupation.valueOf(user.profile.jobOccupation.name),
display = user.profile.jobOccupation.koreanName
),
locations = user.profile.locations.map {
LocationDisplayInfo(
id = it.id.value,
display = it.display,
)
},
company = user.profile.company?.let {
CompanyDisplayInfo(
id = it.id.value,
display = it.display,
)
},
),
desiredPartner = com.threedays.oas.model.UserDesiredPartner(
jobOccupations = user.desiredPartner.jobOccupations.map {
com.threedays.oas.model.JobOccupation.valueOf(
it.name
)
},
birthYearRange = user.desiredPartner.birthYearRange.let {
com.threedays.oas.model.BirthYearRange(
it.start?.value,
it.end?.value,
)
},
preferDistance = PreferDistance.valueOf(user.desiredPartner.preferDistance.name),
),
profileWidgets = user.profile.profileWidgets.map {
ProfileWidget(
type = ProfileWidgetType.valueOf(it.type.name),
content = it.content,
)
}
profile = OASModelAdapter.toUserProfileDisplayInfo(user.profile),
desiredPartner = OASModelAdapter.toOASModel(user.desiredPartner),
profileWidgets = user.profile.profileWidgets.map(OASModelAdapter::toOASModel),
).let { ResponseEntity.ok(it) }
}

override fun putProfileWidget(body: ProfileWidget): ResponseEntity<ProfileWidget> =
withUserAuthentication { userAuthentication: UserAuthentication ->
val command = PutProfileWidget.Command(
userId = userAuthentication.userId,
profileWidget = com.threedays.domain.user.entity.ProfileWidget(
type = com.threedays.domain.user.entity.ProfileWidget.Type.valueOf(body.type.name),
content = body.content
)
profileWidget = OASModelAdapter.toDomainModel(body)
)

putProfileWidget
Expand All @@ -189,9 +136,7 @@ class UserController(
userId = authentication.userId,
name = updateMyUserInfoRequest.name.let { User.Name(it) },
jobOccupation = updateMyUserInfoRequest.jobOccupation.let {
JobOccupation.valueOf(
it.name
)
JobOccupation.valueOf(it.name)
},
locationIds = updateMyUserInfoRequest.locationIds.map(UUIDTypeId::from),
companyId = updateMyUserInfoRequest.companyId?.let { UUIDTypeId.from(it) },
Expand All @@ -204,27 +149,8 @@ class UserController(
id = user.id.value,
name = user.name.value,
phoneNumber = user.phoneNumber.value,
profile = UserProfile(
gender = com.threedays.oas.model.Gender.valueOf(user.profile.gender.name),
birthYear = user.profile.birthYear.value,
jobOccupation = com.threedays.oas.model.JobOccupation.valueOf(user.profile.jobOccupation.name),
locationIds = user.profile.locations.map { it.id.value },
companyId = user.profile.company?.id?.value,
),
desiredPartner = com.threedays.oas.model.UserDesiredPartner(
jobOccupations = user.desiredPartner.jobOccupations.map {
com.threedays.oas.model.JobOccupation.valueOf(
it.name
)
},
birthYearRange = user.desiredPartner.birthYearRange.let {
com.threedays.oas.model.BirthYearRange(
it.start?.value,
it.end?.value,
)
},
preferDistance = PreferDistance.valueOf(user.desiredPartner.preferDistance.name),
)
profile = OASModelAdapter.toOASModel(user.profile),
desiredPartner = OASModelAdapter.toOASModel(user.desiredPartner)
).let { ResponseEntity.ok(it) }
}

Expand All @@ -247,20 +173,8 @@ class UserController(
val user: User = updateDesiredPartner.invoke(command)

UpdateUserDesiredPartnerResponse(
desiredPartner = com.threedays.oas.model.UserDesiredPartner(
birthYearRange = user.desiredPartner.birthYearRange.let {
com.threedays.oas.model.BirthYearRange(
it.start?.value,
it.end?.value,
)
},
jobOccupations = user.desiredPartner.jobOccupations.map {
com.threedays.oas.model.JobOccupation.valueOf(it.name)
},
preferDistance = PreferDistance.valueOf(user.desiredPartner.preferDistance.name),
)
desiredPartner = OASModelAdapter.toOASModel(user.desiredPartner)
).let { ResponseEntity.ok(it) }

}

override fun completeProfileImageUpload(completeProfileImageUploadRequest: CompleteProfileImageUploadRequest): ResponseEntity<Unit> =
Expand Down

0 comments on commit d2afb97

Please sign in to comment.