Skip to content

Commit

Permalink
feat(User) : 유저 커넥션 활성상태 수정 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW committed Jan 4, 2025
1 parent 022b430 commit 411d121
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -200,11 +206,13 @@ class UserController(

override fun getProfileImageUploadUrl(extension: ProfileImageExtension): ResponseEntity<GetProfileImageUploadUrlResponse> =
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,
Expand All @@ -215,4 +223,20 @@ class UserController(
ResponseEntity.ok(it)
}
}

override fun updateConnectionStatus(
updateConnectionStatusRequest: UpdateConnectionStatusRequest
): ResponseEntity<UpdateConnectionStatusResponse> =
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) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data class User(
val profileImages: List<UserProfileImage> = emptyList(),
val profile: UserProfile,
val desiredPartner: UserDesiredPartner,
val connectionStatus: ConnectionStatus = ConnectionStatus.INACTIVE,
) : AggregateRoot<User, User.Id>() {

data class Id(override val value: UUID) : UUIDTypeId(value)
Expand All @@ -37,6 +38,8 @@ data class User(
}
}

enum class ConnectionStatus { ACTIVE, INACTIVE }

init {
if (profile.company == null) {
require(desiredPartner.allowSameCompany == null) {
Expand Down Expand Up @@ -170,4 +173,8 @@ data class User(
return copy(profileImages = updatedProfileImages)
}

fun updateConnectionStatus(connectionStatus: ConnectionStatus): User {
return copy(connectionStatus = connectionStatus)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +29,7 @@ class UserJpaEntity(
profileImages: List<UserProfileImageJpaEntity>,
profile: UserProfileJpaEntity,
desiredPartner: UserDesiredPartnerJpaEntity,
connectionStatus: ConnectionStatus
) {

@Id
Expand Down Expand Up @@ -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 {
Expand All @@ -74,6 +83,7 @@ class UserJpaEntity(
profileImages = profileImages.map { it.toJpaEntity() },
profile = profile.toJpaEntity(),
desiredPartner = desiredPartner.toJpaEntity(),
connectionStatus = connectionStatus,
)
return entity
}
Expand All @@ -87,6 +97,7 @@ class UserJpaEntity(
phoneNumber = PhoneNumber(phoneNumber),
profile = profile.toDomainEntity(),
desiredPartner = desiredPartner.toDomainEntity(),
connectionStatus = connectionStatus,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
2 changes: 1 addition & 1 deletion openapi
Submodule openapi updated 1 files
+50 −0 openapi.yaml

0 comments on commit 411d121

Please sign in to comment.