diff --git a/application/src/main/kotlin/com/threedays/application/user/port/inbound/UpdateConnectionStatus.kt b/application/src/main/kotlin/com/threedays/application/user/port/inbound/UpdateConnectionStatus.kt new file mode 100644 index 0000000..405539b --- /dev/null +++ b/application/src/main/kotlin/com/threedays/application/user/port/inbound/UpdateConnectionStatus.kt @@ -0,0 +1,14 @@ +package com.threedays.application.user.port.inbound + +import com.threedays.domain.user.entity.User + +fun interface UpdateConnectionStatus { + + operator fun invoke(command: Command): User + + data class Command( + val userId: User.Id, + val status: User.ConnectionStatus, + ) + +} 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 1fb488e..bd348a1 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 @@ -3,6 +3,7 @@ package com.threedays.application.user.service import com.threedays.application.auth.config.AuthProperties import com.threedays.application.auth.port.inbound.IssueLoginTokens import com.threedays.application.user.port.inbound.RegisterUser +import com.threedays.application.user.port.inbound.UpdateConnectionStatus import com.threedays.domain.user.entity.Company import com.threedays.domain.user.entity.Location import com.threedays.domain.user.entity.User @@ -19,7 +20,7 @@ class UserService( private val companyQueryRepository: CompanyQueryRepository, private val issueLoginTokens: IssueLoginTokens, private val authProperties: AuthProperties, -) : RegisterUser { +) : RegisterUser, UpdateConnectionStatus { @Transactional override fun invoke(command: RegisterUser.Command): RegisterUser.Result { @@ -52,4 +53,11 @@ class UserService( expiresIn = authProperties.accessTokenExpirationSeconds, ) } + + override fun invoke(command: UpdateConnectionStatus.Command): User { + val user: User = userRepository.get(command.userId) + return user + .updateConnectionStatus(command.status) + .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 c5f1f73..953cc73 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 @@ -6,6 +6,7 @@ import com.threedays.application.user.port.inbound.DeleteUserProfileImage import com.threedays.application.user.port.inbound.GetUserProfileImageUploadUrl import com.threedays.application.user.port.inbound.PutProfileWidget import com.threedays.application.user.port.inbound.RegisterUser +import com.threedays.application.user.port.inbound.UpdateConnectionStatus import com.threedays.application.user.port.inbound.UpdateDesiredPartner import com.threedays.application.user.port.inbound.UpdateUserInfo import com.threedays.bootstrap.api.support.security.UserAuthentication @@ -27,6 +28,8 @@ import com.threedays.oas.model.ProfileWidget import com.threedays.oas.model.ProfileWidgetType import com.threedays.oas.model.RegisterUserRequest import com.threedays.oas.model.TokenResponse +import com.threedays.oas.model.UpdateConnectionStatusRequest +import com.threedays.oas.model.UpdateConnectionStatusResponse import com.threedays.oas.model.UpdateMyUserInfoRequest import com.threedays.oas.model.UpdateMyUserInfoResponse import com.threedays.oas.model.UpdateUserDesiredPartnerRequest @@ -36,7 +39,7 @@ import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.RestController import java.time.Year -import java.util.UUID +import java.util.* @RestController class UserController( @@ -49,6 +52,7 @@ class UserController( private val getUserProfileImageUploadUrl: GetUserProfileImageUploadUrl, private val completeUserProfileImageUpload: CompleteUserProfileImageUpload, private val deleteUserProfileImage: DeleteUserProfileImage, + private val updateConnectionStatus: UpdateConnectionStatus, ) : UsersApi { override fun registerUser( @@ -167,7 +171,9 @@ class UserController( end = it.end?.let { Year.of(it) } ) }, - preferDistance = UserDesiredPartner.PreferDistance.valueOf(updateUserDesiredPartnerRequest.preferDistance.name), + preferDistance = UserDesiredPartner.PreferDistance.valueOf( + updateUserDesiredPartnerRequest.preferDistance.name + ), ) val user: User = updateDesiredPartner.invoke(command) @@ -200,11 +206,13 @@ class UserController( override fun getProfileImageUploadUrl(extension: ProfileImageExtension): ResponseEntity = withUserAuthentication { _ -> - val command: GetUserProfileImageUploadUrl.Command = GetUserProfileImageUploadUrl.Command( - extension = UserProfileImage.Extension.valueOf(extension.name) - ) + val command: GetUserProfileImageUploadUrl.Command = + GetUserProfileImageUploadUrl.Command( + extension = UserProfileImage.Extension.valueOf(extension.name) + ) - val result: GetUserProfileImageUploadUrl.Result = getUserProfileImageUploadUrl.invoke(command) + val result: GetUserProfileImageUploadUrl.Result = + getUserProfileImageUploadUrl.invoke(command) GetProfileImageUploadUrlResponse( imageId = result.imageId, @@ -215,4 +223,20 @@ class UserController( ResponseEntity.ok(it) } } + + override fun updateConnectionStatus( + updateConnectionStatusRequest: UpdateConnectionStatusRequest + ): ResponseEntity = + withUserAuthentication { authentication -> + val command = UpdateConnectionStatus.Command( + userId = authentication.userId, + status = User.ConnectionStatus.valueOf(updateConnectionStatusRequest.status.name) + ) + + val result: User = updateConnectionStatus(command) + + UpdateConnectionStatusResponse( + status = UpdateConnectionStatusResponse.Status.valueOf(result.connectionStatus.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 a07f578..ed78160 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 @@ -25,6 +25,7 @@ data class User( val profileImages: List = emptyList(), val profile: UserProfile, val desiredPartner: UserDesiredPartner, + val connectionStatus: ConnectionStatus = ConnectionStatus.INACTIVE, ) : AggregateRoot() { data class Id(override val value: UUID) : UUIDTypeId(value) @@ -37,6 +38,8 @@ data class User( } } + enum class ConnectionStatus { ACTIVE, INACTIVE } + init { if (profile.company == null) { require(desiredPartner.allowSameCompany == null) { @@ -170,4 +173,8 @@ data class User( return copy(profileImages = updatedProfileImages) } + fun updateConnectionStatus(connectionStatus: ConnectionStatus): User { + return copy(connectionStatus = connectionStatus) + } + } diff --git a/infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/entity/UserJpaEntity.kt b/infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/entity/UserJpaEntity.kt index 8eeb63f..65ad000 100644 --- a/infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/entity/UserJpaEntity.kt +++ b/infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/entity/UserJpaEntity.kt @@ -2,12 +2,15 @@ package com.threedays.persistence.user.entity import com.threedays.domain.auth.vo.PhoneNumber import com.threedays.domain.user.entity.User +import com.threedays.domain.user.entity.User.ConnectionStatus import com.threedays.persistence.user.entity.UserDesiredPartnerJpaEntity.Companion.toJpaEntity import com.threedays.persistence.user.entity.UserProfileImageJpaEntity.Companion.toJpaEntity import com.threedays.persistence.user.entity.UserProfileJpaEntity.Companion.toJpaEntity import jakarta.persistence.CascadeType import jakarta.persistence.Column import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated import jakarta.persistence.FetchType import jakarta.persistence.Id import jakarta.persistence.JoinColumn @@ -26,6 +29,7 @@ class UserJpaEntity( profileImages: List, profile: UserProfileJpaEntity, desiredPartner: UserDesiredPartnerJpaEntity, + connectionStatus: ConnectionStatus ) { @Id @@ -64,6 +68,11 @@ class UserJpaEntity( var desiredPartner: UserDesiredPartnerJpaEntity = desiredPartner private set + @Column(name = "connection_status", nullable = false) + @Enumerated(EnumType.STRING) + var connectionStatus: ConnectionStatus = connectionStatus + private set + companion object { fun User.toJpaEntity(): UserJpaEntity { @@ -74,6 +83,7 @@ class UserJpaEntity( profileImages = profileImages.map { it.toJpaEntity() }, profile = profile.toJpaEntity(), desiredPartner = desiredPartner.toJpaEntity(), + connectionStatus = connectionStatus, ) return entity } @@ -87,6 +97,7 @@ class UserJpaEntity( phoneNumber = PhoneNumber(phoneNumber), profile = profile.toDomainEntity(), desiredPartner = desiredPartner.toDomainEntity(), + connectionStatus = connectionStatus, ) } diff --git a/infrastructure/persistence/src/main/resources/db/migration/V1__init_user.sql b/infrastructure/persistence/src/main/resources/db/migration/V1__init_user.sql index 19b0a4d..2f457a2 100644 --- a/infrastructure/persistence/src/main/resources/db/migration/V1__init_user.sql +++ b/infrastructure/persistence/src/main/resources/db/migration/V1__init_user.sql @@ -51,11 +51,12 @@ CREATE TABLE user_profiles CREATE TABLE users ( - id BINARY(16) NOT NULL, - name VARCHAR(255) NOT NULL, - phone_number VARCHAR(255) NOT NULL, - profile_id BINARY(16) NULL, - desired_partner_id BINARY(16) NULL, + id BINARY(16) NOT NULL, + name VARCHAR(255) NOT NULL, + phone_number VARCHAR(255) NOT NULL, + profile_id BINARY(16) NULL, + desired_partner_id BINARY(16) NULL, + connection_status VARCHAR(255) NOT NULL, CONSTRAINT pk_users PRIMARY KEY (id), CONSTRAINT uq_users_phone_number UNIQUE (phone_number) ); diff --git a/openapi b/openapi index b4118d6..4a5e747 160000 --- a/openapi +++ b/openapi @@ -1 +1 @@ -Subproject commit b4118d6a2e2cf6d57430fe47d6c4a45b9f9817e8 +Subproject commit 4a5e747dcdbb6bc061765e3ffffc44b90133dd2f