diff --git a/application/src/main/kotlin/com/threedays/application/user/port/inbound/UpdateUserInfo.kt b/application/src/main/kotlin/com/threedays/application/user/port/inbound/UpdateUserInfo.kt index 47e6eb1..95119af 100644 --- a/application/src/main/kotlin/com/threedays/application/user/port/inbound/UpdateUserInfo.kt +++ b/application/src/main/kotlin/com/threedays/application/user/port/inbound/UpdateUserInfo.kt @@ -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 @@ -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? = null, + val name: User.Name, + val jobOccupation: JobOccupation, + val locationIds: List, + val companyId: Company.Id? = null, + val allowSameCompany: Boolean? = null, ) } diff --git a/application/src/main/kotlin/com/threedays/application/user/service/UserService.kt b/application/src/main/kotlin/com/threedays/application/user/service/UserService.kt index 1449753..dffd3c6 100644 --- a/application/src/main/kotlin/com/threedays/application/user/service/UserService.kt +++ b/application/src/main/kotlin/com/threedays/application/user/service/UserService.kt @@ -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) } } diff --git a/bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/UserController.kt b/bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/UserController.kt index 469cf1f..7e311cc 100644 --- a/bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/UserController.kt +++ b/bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/UserController.kt @@ -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) @@ -202,7 +204,6 @@ class UserController( preferDistance = com.threedays.oas.model.PreferDistance.valueOf(user.desiredPartner.preferDistance.name), ) ).let { ResponseEntity.ok(it) } - - } + } diff --git a/domain/src/main/kotlin/com/threedays/domain/user/entity/User.kt b/domain/src/main/kotlin/com/threedays/domain/user/entity/User.kt index e2a4a75..50d1607 100644 --- a/domain/src/main/kotlin/com/threedays/domain/user/entity/User.kt +++ b/domain/src/main/kotlin/com/threedays/domain/user/entity/User.kt @@ -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 @@ -97,17 +98,25 @@ data class User( fun updateUserInfo( name: Name?, - jobOccupation: JobOccupation?, - locationIds: List?, - locationQueryRepository: LocationQueryRepository + jobOccupation: JobOccupation, + locationIds: List, + locationQueryRepository: LocationQueryRepository, + companyId: Company.Id?, + companyQueryRepository: CompanyQueryRepository, + allowSameCompany: Boolean?, ): User { - val locations: List = locationIds?.map { locationQueryRepository.get(it) } ?: emptyList() + val locations: List = 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, ) ) } diff --git a/domain/src/test/kotlin/com/threedays/domain/user/entity/UserTest.kt b/domain/src/test/kotlin/com/threedays/domain/user/entity/UserTest.kt index ff0e2c1..488ad6b 100644 --- a/domain/src/test/kotlin/com/threedays/domain/user/entity/UserTest.kt +++ b/domain/src/test/kotlin/com/threedays/domain/user/entity/UserTest.kt @@ -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 @@ -22,6 +25,13 @@ class UserTest : DescribeSpec({ .objectIntrospector(PrimaryConstructorArbitraryIntrospector.INSTANCE) .build() + val locationQueryRepository = LocationQueryRepositorySpy() + val companyQueryRepository = CompanyQueryRepositorySpy() + + afterTest { + locationQueryRepository.clear() + companyQueryRepository.clear() + } describe("유저 생성") { it("새로운 유저를 생성한다") { @@ -227,4 +237,47 @@ class UserTest : DescribeSpec({ } } + describe("updateUserInfo - 유저 정보 수정") { + it("유저 정보를 수정한다") { + // arrange + val userDesiredPartner: UserDesiredPartner = fixtureMonkey + .giveMeBuilder() + .set(UserDesiredPartner::allowSameCompany, null) + .sample() + + val user: User = fixtureMonkey + .giveMeBuilder() + .set(User::name, User.Name("홍길동")) + .set(User::phoneNumber, PhoneNumber("01012345678")) + .set(User::desiredPartner, userDesiredPartner) + .sample() + + val name: User.Name = fixtureMonkey.giveMeBuilder().sample() + val jobOccupation: JobOccupation = fixtureMonkey.giveMeBuilder().sample() + val locations = fixtureMonkey.giveMeBuilder().sampleList(3) + val company = fixtureMonkey.giveMeBuilder().sample() + val allowSameCompany: Boolean = fixtureMonkey.giveMeBuilder().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 + } + } + }) diff --git a/domain/src/test/kotlin/com/threedays/domain/user/reposiotry/CompanyQueryRepositorySpy.kt b/domain/src/test/kotlin/com/threedays/domain/user/reposiotry/CompanyQueryRepositorySpy.kt new file mode 100644 index 0000000..8b40d89 --- /dev/null +++ b/domain/src/test/kotlin/com/threedays/domain/user/reposiotry/CompanyQueryRepositorySpy.kt @@ -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() + + fun save(company: Company) { + companies.add(company) + } + + fun clear() { + companies.clear() + } + + override fun searchCompanies( + name: String, + next: Company.Id?, + limit: Int + ): Pair, 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 } + } + +} diff --git a/domain/src/test/kotlin/com/threedays/domain/user/reposiotry/LocationQueryRepositorySpy.kt b/domain/src/test/kotlin/com/threedays/domain/user/reposiotry/LocationQueryRepositorySpy.kt new file mode 100644 index 0000000..ed60afb --- /dev/null +++ b/domain/src/test/kotlin/com/threedays/domain/user/reposiotry/LocationQueryRepositorySpy.kt @@ -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() + + fun save(location: Location) { + locations.add(location) + } + + fun clear() { + locations.clear() + } + + override fun getLocationRegions(): List { + return locations.map { it.region.value }.distinct() + } + + override fun getLocationsByRegion(regionName: String): List { + return locations.filter { it.region.value == regionName } + } + + override fun find(id: Location.Id): Location? { + return locations.find { it.id == id } + } +} diff --git a/openapi b/openapi index 490eae1..fc5b0be 160000 --- a/openapi +++ b/openapi @@ -1 +1 @@ -Subproject commit 490eae16de196650c4443320613f7b2c0b67f66f +Subproject commit fc5b0be00620e28dfb13946e709dec968b4e9553