Skip to content

Commit 4c2d85d

Browse files
authored
[PLT-9] 키, 팔길이 등 프로필 세부 사항 추가 및 유저 정보 수정 API 추가 (#173)
1 parent e88c723 commit 4c2d85d

7 files changed

Lines changed: 110 additions & 3 deletions

File tree

clog-api/src/main/kotlin/org/depromeet/clog/server/api/user/application/GetMe.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class GetMe(
1818
return UserResponse(
1919
id = user.id!!,
2020
name = user.name,
21+
height = user.height,
22+
armSpan = user.armSpan,
23+
instagramUrl = user.instagramUrl,
2124
)
2225
}
2326
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.depromeet.clog.server.api.user.application
2+
3+
import io.swagger.v3.oas.annotations.media.Schema
4+
import jakarta.validation.constraints.Max
5+
import jakarta.validation.constraints.Min
6+
import jakarta.validation.constraints.NotBlank
7+
import jakarta.validation.constraints.Pattern
8+
import org.depromeet.clog.server.domain.user.domain.UserRepository
9+
import org.depromeet.clog.server.domain.user.domain.exception.UserNotFoundException
10+
import org.hibernate.validator.constraints.Length
11+
import org.springframework.stereotype.Service
12+
13+
@Service
14+
class UpdateUser(
15+
private val userRepository: UserRepository,
16+
) {
17+
18+
operator fun invoke(
19+
userId: Long,
20+
command: Command,
21+
): Result {
22+
val user = userRepository.findByIdAndIsDeletedFalse(userId)
23+
?: throw UserNotFoundException()
24+
25+
user.copy(
26+
name = command.name ?: user.name,
27+
height = command.height ?: user.height,
28+
armSpan = command.armSpan ?: user.armSpan,
29+
instagramUrl = command.instagramUrl ?: user.instagramUrl,
30+
).let { updatedUser ->
31+
userRepository.save(updatedUser)
32+
}
33+
34+
return Result(userId = user.id!!)
35+
}
36+
37+
data class Command(
38+
@field:NotBlank
39+
@Length(min = 1, max = 10)
40+
@Schema(title = "이름")
41+
val name: String? = null,
42+
43+
@field:Min(1)
44+
@field:Max(999)
45+
@Schema(title = "", description = "1 ~ 999 사이의 값")
46+
val height: Int? = null,
47+
48+
@field:Min(1)
49+
@field:Max(999)
50+
@Schema(title = "팔 길이", description = "1 ~ 999 사이의 값")
51+
val armSpan: Int? = null,
52+
53+
@field:Pattern(
54+
regexp = "^https://(www\\.)?instagram\\.com/[A-Za-z0-9._]{1,30}/?$",
55+
message = "유효한 인스타그램 프로필 URL을 입력하세요.",
56+
)
57+
val instagramUrl: String? = null,
58+
)
59+
60+
data class Result(
61+
val userId: Long,
62+
)
63+
}

clog-api/src/main/kotlin/org/depromeet/clog/server/api/user/presentation/UserController.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package org.depromeet.clog.server.api.user.presentation
22

33
import io.swagger.v3.oas.annotations.Operation
44
import io.swagger.v3.oas.annotations.tags.Tag
5+
import jakarta.validation.Valid
56
import org.depromeet.clog.server.api.auth.application.LogoutService
67
import org.depromeet.clog.server.api.configuration.ApiConstants.API_BASE_PATH_V1
78
import org.depromeet.clog.server.api.configuration.annotation.ApiErrorCodes
89
import org.depromeet.clog.server.api.user.UserContext
10+
import org.depromeet.clog.server.api.user.application.UpdateUser
911
import org.depromeet.clog.server.api.user.application.UserService
1012
import org.depromeet.clog.server.api.user.presentation.dto.WithdrawalRequest
1113
import org.depromeet.clog.server.domain.common.ClogApiResponse
@@ -18,7 +20,8 @@ import org.springframework.web.bind.annotation.*
1820
@RequestMapping("$API_BASE_PATH_V1/users")
1921
class UserController(
2022
private val userService: UserService,
21-
private val logoutService: LogoutService
23+
private val logoutService: LogoutService,
24+
private val updateUser: UpdateUser,
2225
) {
2326

2427
@Operation(summary = "로그아웃")
@@ -50,4 +53,15 @@ class UserController(
5053
userService.updateName(userContext.userId, request)
5154
return ClogApiResponse.from(null)
5255
}
56+
57+
@Operation(summary = "유저 정보 변경")
58+
@PatchMapping
59+
@ApiErrorCodes([ErrorCode.USER_NOT_FOUND])
60+
fun update(
61+
userContext: UserContext,
62+
@RequestBody @Valid request: UpdateUser.Command
63+
): ClogApiResponse<UpdateUser.Result> {
64+
val result = updateUser(userContext.userId, request)
65+
return ClogApiResponse.from(result)
66+
}
5367
}

clog-api/src/main/kotlin/org/depromeet/clog/server/api/user/presentation/UserResponse.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ data class UserResponse(
99

1010
@Schema(description = "유저 이름", example = "권기준")
1111
val name: String? = null,
12+
13+
@Schema(description = "유저 키", example = "180")
14+
val height: Int? = null,
15+
16+
@Schema(description = "유저 팔 길이", example = "180")
17+
val armSpan: Int? = null,
18+
19+
@Schema(description = "유저 인스타그램 URL", example = "https://www.instagram.com/kkjsw17")
20+
val instagramUrl: String? = null,
1221
)

clog-domain/src/main/kotlin/org/depromeet/clog/server/domain/user/domain/User.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ data class User(
55
val loginId: String,
66
var name: String? = null,
77
val provider: Provider,
8-
var isDeleted: Boolean = false
8+
var isDeleted: Boolean = false,
9+
val height: Int? = null,
10+
val armSpan: Int? = null,
11+
val instagramUrl: String? = null,
912
)

clog-infrastructure/src/main/kotlin/org/depromeet/clog/server/infrastructure/mappers/UserMapper.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class UserMapper : DomainEntityMapper<User, User, UserEntity> {
1414
name = entity.name,
1515
provider = entity.provider,
1616
isDeleted = entity.isDeleted,
17+
height = entity.height,
18+
armSpan = entity.armSpan,
19+
instagramUrl = entity.instagramUrl,
1720
)
1821
}
1922

@@ -24,6 +27,9 @@ class UserMapper : DomainEntityMapper<User, User, UserEntity> {
2427
name = domain.name,
2528
provider = domain.provider,
2629
isDeleted = domain.isDeleted,
30+
height = domain.height,
31+
armSpan = domain.armSpan,
32+
instagramUrl = domain.instagramUrl,
2733
)
2834
}
2935
}

clog-infrastructure/src/main/kotlin/org/depromeet/clog/server/infrastructure/user/UserEntity.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ class UserEntity(
2121
val provider: Provider,
2222

2323
@Column(nullable = false)
24-
var isDeleted: Boolean = false
24+
var isDeleted: Boolean = false,
25+
26+
@Column
27+
val height: Int? = null,
28+
29+
@Column
30+
val armSpan: Int? = null,
31+
32+
@Column
33+
val instagramUrl: String? = null,
2534
) : BaseEntity()

0 commit comments

Comments
 (0)