Skip to content

Commit

Permalink
✨ 프로필 수정 API 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW committed Nov 24, 2024
1 parent 456d0bc commit 8ee7228
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.threedays.application.user.port.inbound

import com.threedays.domain.user.entity.Company
import com.threedays.domain.user.entity.Location
import com.threedays.domain.user.entity.User
import com.threedays.domain.user.vo.JobOccupation
Expand All @@ -10,8 +11,10 @@ interface UpdateUserInfo {

data class Command(
val userId: User.Id,
val name: User.Name? = null,
val jobOccupation: JobOccupation? = null,
val locationIds: List<Location.Id>? = null,
val name: User.Name,
val jobOccupation: JobOccupation,
val locationIds: List<Location.Id>,
val companyId: Company.Id? = null,
val allowSameCompany: Boolean? = null,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class UserService(
name = command.name,
jobOccupation = command.jobOccupation,
locationIds = command.locationIds,
locationQueryRepository = locationQueryRepository
locationQueryRepository = locationQueryRepository,
companyId = command.companyId,
companyQueryRepository = companyQueryRepository,
allowSameCompany = command.allowSameCompany,
)
.also { userRepository.save(it) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ class UserController(
withUserAuthentication { authentication ->
val command = UpdateUserInfo.Command(
userId = authentication.userId,
name = updateMyUserInfoRequest.name?.let { User.Name(it) },
jobOccupation = updateMyUserInfoRequest.jobOccupation?.let {
name = updateMyUserInfoRequest.name.let { User.Name(it) },
jobOccupation = updateMyUserInfoRequest.jobOccupation.let {
JobOccupation.valueOf(
it.name
)
},
locationIds = updateMyUserInfoRequest.locationIds?.map(UUIDTypeId::from),
locationIds = updateMyUserInfoRequest.locationIds.map(UUIDTypeId::from),
companyId = updateMyUserInfoRequest.companyId?.let { UUIDTypeId.from(it) },
allowSameCompany = updateMyUserInfoRequest.allowSameCompany,
)

val user: User = updateUserInfo.invoke(command)
Expand Down Expand Up @@ -202,7 +204,6 @@ class UserController(
preferDistance = com.threedays.oas.model.PreferDistance.valueOf(user.desiredPartner.preferDistance.name),
)
).let { ResponseEntity.ok(it) }


}

}
21 changes: 15 additions & 6 deletions domain/src/main/kotlin/com/threedays/domain/user/entity/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.threedays.domain.user.entity

import com.threedays.domain.auth.vo.PhoneNumber
import com.threedays.domain.user.entity.UserDesiredPartner.PreferDistance
import com.threedays.domain.user.repository.CompanyQueryRepository
import com.threedays.domain.user.repository.LocationQueryRepository
import com.threedays.domain.user.vo.BirthYearRange
import com.threedays.domain.user.vo.Gender
Expand Down Expand Up @@ -97,17 +98,25 @@ data class User(

fun updateUserInfo(
name: Name?,
jobOccupation: JobOccupation?,
locationIds: List<Location.Id>?,
locationQueryRepository: LocationQueryRepository
jobOccupation: JobOccupation,
locationIds: List<Location.Id>,
locationQueryRepository: LocationQueryRepository,
companyId: Company.Id?,
companyQueryRepository: CompanyQueryRepository,
allowSameCompany: Boolean?,
): User {
val locations: List<Location> = locationIds?.map { locationQueryRepository.get(it) } ?: emptyList()
val locations: List<Location> = locationIds.map { locationQueryRepository.get(it) }
val company: Company? = companyId?.let { companyQueryRepository.get(it) }

return copy(
name = name ?: this.name,
profile = profile.copy(
jobOccupation = jobOccupation ?: profile.jobOccupation,
locations = locations.ifEmpty { profile.locations }
jobOccupation = jobOccupation,
locations = locations,
company = company,
),
desiredPartner = desiredPartner.copy(
allowSameCompany = allowSameCompany ?: desiredPartner.allowSameCompany,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.navercorp.fixturemonkey.kotlin.giveMeBuilder
import com.navercorp.fixturemonkey.kotlin.introspector.PrimaryConstructorArbitraryIntrospector
import com.navercorp.fixturemonkey.kotlin.set
import com.threedays.domain.auth.vo.PhoneNumber
import com.threedays.domain.user.reposiotry.CompanyQueryRepositorySpy
import com.threedays.domain.user.reposiotry.LocationQueryRepositorySpy
import com.threedays.domain.user.repository.LocationQueryRepository
import com.threedays.domain.user.vo.BirthYearRange
import com.threedays.domain.user.vo.Gender
import com.threedays.domain.user.vo.JobOccupation
Expand All @@ -22,6 +25,13 @@ class UserTest : DescribeSpec({
.objectIntrospector(PrimaryConstructorArbitraryIntrospector.INSTANCE)
.build()

val locationQueryRepository = LocationQueryRepositorySpy()
val companyQueryRepository = CompanyQueryRepositorySpy()

afterTest {
locationQueryRepository.clear()
companyQueryRepository.clear()
}

describe("유저 생성") {
it("새로운 유저를 생성한다") {
Expand Down Expand Up @@ -227,4 +237,47 @@ class UserTest : DescribeSpec({
}
}

describe("updateUserInfo - 유저 정보 수정") {
it("유저 정보를 수정한다") {
// arrange
val userDesiredPartner: UserDesiredPartner = fixtureMonkey
.giveMeBuilder<UserDesiredPartner>()
.set(UserDesiredPartner::allowSameCompany, null)
.sample()

val user: User = fixtureMonkey
.giveMeBuilder<User>()
.set(User::name, User.Name("홍길동"))
.set(User::phoneNumber, PhoneNumber("01012345678"))
.set(User::desiredPartner, userDesiredPartner)
.sample()

val name: User.Name = fixtureMonkey.giveMeBuilder<User.Name>().sample()
val jobOccupation: JobOccupation = fixtureMonkey.giveMeBuilder<JobOccupation>().sample()
val locations = fixtureMonkey.giveMeBuilder<Location>().sampleList(3)
val company = fixtureMonkey.giveMeBuilder<Company>().sample()
val allowSameCompany: Boolean = fixtureMonkey.giveMeBuilder<Boolean>().sample()

companyQueryRepository.save(company)
locations.forEach { locationQueryRepository.save(it) }

// act
val result: User = user.updateUserInfo(
name = name,
jobOccupation = jobOccupation,
locationIds = locations.map { it.id },
locationQueryRepository = locationQueryRepository,
companyId = company.id,
companyQueryRepository = companyQueryRepository,
allowSameCompany = allowSameCompany,
)

// assert
result.name shouldBe name
result.profile.jobOccupation shouldBe jobOccupation
result.profile.locations shouldBe locations
result.profile.company shouldBe company
}
}

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.threedays.domain.user.reposiotry

import com.threedays.domain.user.entity.Company
import com.threedays.domain.user.repository.CompanyQueryRepository

class CompanyQueryRepositorySpy: CompanyQueryRepository {

private val companies = mutableListOf<Company>()

fun save(company: Company) {
companies.add(company)
}

fun clear() {
companies.clear()
}

override fun searchCompanies(
name: String,
next: Company.Id?,
limit: Int
): Pair<List<Company>, Company.Id?> {
return companies
.filter { it.name.contains(name) }
.let { it.subList(0, limit.coerceAtMost(it.size)) }
.let { it to it.lastOrNull()?.id }
}

override fun find(id: Company.Id): Company? {
return companies.find { it.id == id }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.threedays.domain.user.reposiotry

import com.threedays.domain.user.entity.Location
import com.threedays.domain.user.repository.LocationQueryRepository

class LocationQueryRepositorySpy: LocationQueryRepository {

private val locations = mutableListOf<Location>()

fun save(location: Location) {
locations.add(location)
}

fun clear() {
locations.clear()
}

override fun getLocationRegions(): List<String> {
return locations.map { it.region.value }.distinct()
}

override fun getLocationsByRegion(regionName: String): List<Location> {
return locations.filter { it.region.value == regionName }
}

override fun find(id: Location.Id): Location? {
return locations.find { it.id == id }
}
}
2 changes: 1 addition & 1 deletion openapi
Submodule openapi updated 1 files
+10 −1 openapi.yaml

0 comments on commit 8ee7228

Please sign in to comment.