-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat : Swagger 설 * feat : User nickname 필드 추가 * feat : User 등록 메소드 구현 * feat : 회원가입 로직 구 * feat : application 모듈 회원가입 dto * feat : 회원가입 API * feat : in-web 모듈 회원가입 dto * feat : 로그인 API 명세 * refactor : 오타 수정 * fix : 스웨거 오류 해결 * fix : develop 브랜치 conflict 해결 * feat : Controller 인자 PrincipalUser로 변경 * feat : 요청 dto validation 추가
- Loading branch information
1 parent
06b690f
commit 2295172
Showing
21 changed files
with
316 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
adapters/in-web/src/main/kotlin/com/pokit/auth/config/ErrorOperation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.pokit.auth.config | ||
|
||
import com.pokit.common.exception.ErrorCode | ||
import kotlin.reflect.KClass | ||
|
||
@Target(AnnotationTarget.FUNCTION) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
annotation class ErrorOperation(val value: KClass<out ErrorCode>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
adapters/in-web/src/main/kotlin/com/pokit/auth/config/SwaggerConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.pokit.auth.config | ||
|
||
import io.swagger.v3.oas.models.Components | ||
import io.swagger.v3.oas.models.OpenAPI | ||
import io.swagger.v3.oas.models.info.Info | ||
import io.swagger.v3.oas.models.media.Schema | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class SwaggerConfig { | ||
@Bean | ||
fun openAPI(): OpenAPI { | ||
return OpenAPI() | ||
.components( | ||
Components() | ||
.addSchemas( | ||
"ErrorResponse", Schema<Any>() | ||
.addProperty("message", Schema<Any>().type("string")) | ||
.addProperty("code", Schema<Any>().type("string")) | ||
) | ||
) | ||
.info(configurationInfo()) | ||
} | ||
|
||
private fun configurationInfo(): Info { | ||
return Info() | ||
.title("POKIT API") | ||
.description("포킷 api 명세서") | ||
.version("1.0") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
adapters/in-web/src/main/kotlin/com/pokit/common/exception/ApiErrorOperationCustomizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.pokit.common.exception | ||
|
||
import com.pokit.auth.config.ErrorOperation | ||
import io.swagger.v3.oas.models.Operation | ||
import io.swagger.v3.oas.models.examples.Example | ||
import io.swagger.v3.oas.models.media.Content | ||
import io.swagger.v3.oas.models.media.MediaType | ||
import io.swagger.v3.oas.models.media.Schema | ||
import io.swagger.v3.oas.models.responses.ApiResponse | ||
import io.swagger.v3.oas.models.responses.ApiResponses | ||
import org.springdoc.core.customizers.OperationCustomizer | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.method.HandlerMethod | ||
|
||
@Component | ||
class ApiErrorOperationCustomizer : OperationCustomizer { | ||
override fun customize(operation: Operation, handlerMethod: HandlerMethod): Operation { | ||
val annotation = handlerMethod.method.getAnnotation(ErrorOperation::class.java) | ||
if (annotation != null) { | ||
val errorCodeClass = annotation.value.java | ||
val errorCodes = errorCodeClass.enumConstants | ||
val apiResponses = operation.responses ?: ApiResponses() | ||
|
||
for (errorCode in errorCodes) { | ||
val exampleContent = ErrorResponse(errorCode.message, errorCode.code) | ||
|
||
val example = Example().apply { | ||
value = exampleContent | ||
} | ||
|
||
val mediaType = MediaType().apply { | ||
addExamples("example", example) | ||
schema = Schema<ErrorResponse>() | ||
} | ||
|
||
val content = Content().apply { | ||
addMediaType(org.springframework.http.MediaType.APPLICATION_JSON_VALUE, mediaType) | ||
} | ||
|
||
val response = ApiResponse() | ||
.description("${errorCode.code}: ${errorCode.message}") | ||
.content(content) | ||
apiResponses.addApiResponse(errorCode.code, response) | ||
} | ||
|
||
operation.responses(apiResponses) | ||
} | ||
return operation | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
adapters/in-web/src/main/kotlin/com/pokit/user/UserController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.pokit.user | ||
|
||
import com.pokit.auth.config.ErrorOperation | ||
import com.pokit.auth.model.PrincipalUser | ||
import com.pokit.auth.model.toDomain | ||
import com.pokit.user.dto.ApiSignUpRequest | ||
import com.pokit.user.dto.response.SignUpResponse | ||
import com.pokit.user.exception.UserErrorCode | ||
import com.pokit.user.model.User | ||
import com.pokit.user.port.`in`.UserUseCase | ||
import io.swagger.v3.oas.annotations.Operation | ||
import jakarta.validation.Valid | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/user") | ||
class UserController( | ||
private val userUseCase: UserUseCase | ||
) { | ||
@PostMapping("/signup") | ||
@Operation(summary = "회원 등록 API") | ||
@ErrorOperation(UserErrorCode::class) | ||
fun signUp( | ||
@AuthenticationPrincipal principalUser: PrincipalUser, | ||
@Valid @RequestBody request: ApiSignUpRequest | ||
): ResponseEntity<SignUpResponse> { | ||
val user = principalUser.toDomain() | ||
val signUpRequest = request.toSignUpRequest() | ||
val response = userUseCase.signUp(user, signUpRequest) | ||
return ResponseEntity.ok(response) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
adapters/in-web/src/main/kotlin/com/pokit/user/dto/ApiSignUpRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.pokit.user.dto | ||
|
||
import com.pokit.user.dto.request.SignUpRequest | ||
import com.pokit.user.model.InterestType | ||
import jakarta.validation.constraints.NotBlank | ||
import jakarta.validation.constraints.Size | ||
|
||
data class ApiSignUpRequest( | ||
@NotBlank(message = "닉네임은 필수값입니다.") | ||
@Size(max = 10, message = "닉네임은 10자 이하만 가능합니다.") | ||
val nickName: String, | ||
@Size(min = 1, max = 3, message = "최소 하나 이상, 세개 이하만 가능합니다.") | ||
val interests: List<String> | ||
) { | ||
fun toSignUpRequest(): SignUpRequest { | ||
val interestTypes = interests.map { | ||
InterestType.of(it) | ||
} | ||
|
||
return SignUpRequest( | ||
nickName = nickName, | ||
interests = interestTypes | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.pokit.user | ||
|
||
import com.pokit.user.dto.UserInfo | ||
import com.pokit.user.dto.request.SignUpRequest | ||
import com.pokit.user.model.InterestType | ||
import com.pokit.user.model.Role | ||
import com.pokit.user.model.User | ||
|
||
|
@@ -9,5 +11,9 @@ class UserFixture { | |
fun getUser() = User(1L, "[email protected]", Role.USER) | ||
|
||
fun getUserInfo() = UserInfo("[email protected]") | ||
|
||
fun getInvalidUser() = User(2L, "[email protected]", Role.USER) | ||
|
||
fun getSignUpRequest() = SignUpRequest("인주니", listOf(InterestType.SPORTS)) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
application/src/main/kotlin/com/pokit/user/port/in/UserUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.pokit.user.port.`in` | ||
|
||
import com.pokit.user.dto.request.SignUpRequest | ||
import com.pokit.user.dto.response.SignUpResponse | ||
import com.pokit.user.model.User | ||
|
||
interface UserUseCase { | ||
fun signUp(user: User, request: SignUpRequest): SignUpResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
application/src/main/kotlin/com/pokit/user/port/service/UserService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.pokit.user.port.service | ||
|
||
import com.pokit.common.exception.NotFoundCustomException | ||
import com.pokit.user.dto.request.SignUpRequest | ||
import com.pokit.user.dto.response.SignUpResponse | ||
import com.pokit.user.exception.UserErrorCode | ||
import com.pokit.user.model.User | ||
import com.pokit.user.port.`in`.UserUseCase | ||
import com.pokit.user.port.out.UserPort | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class UserService( | ||
private val userPort: UserPort | ||
) : UserUseCase { | ||
@Transactional | ||
override fun signUp(user: User, request: SignUpRequest): SignUpResponse { | ||
user.modifyUser( | ||
request.nickName, | ||
) | ||
|
||
val savedUser = userPort.register(user) | ||
?: throw NotFoundCustomException(UserErrorCode.NOT_FOUND_USER) | ||
|
||
return SignUpResponse(savedUser.id) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.pokit.user.port.service | ||
|
||
import com.pokit.common.exception.NotFoundCustomException | ||
import com.pokit.user.UserFixture | ||
import com.pokit.user.model.User | ||
import com.pokit.user.port.out.UserPort | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
|
||
class UserServiceTest : BehaviorSpec({ | ||
val userPort = mockk<UserPort>() | ||
val userService = UserService(userPort) | ||
Given("회원을 등록할 때") { | ||
val user = UserFixture.getUser() | ||
val invalidUser = UserFixture.getInvalidUser() | ||
val request = UserFixture.getSignUpRequest() | ||
val modifieUser = User(user.id, user.email, user.role, request.nickName) | ||
|
||
every { userPort.register(user) } returns modifieUser | ||
every { userPort.register(invalidUser) } returns null | ||
|
||
When("수정하려는 정보를 받으면") { | ||
val response = userService.signUp(user, request) | ||
Then("회원 정보가 수정되고 수정된 회원의 id가 반환된다.") { | ||
response.userId shouldBe modifieUser.id | ||
user.nickName shouldBe modifieUser.nickName | ||
} | ||
} | ||
|
||
When("수정하려는 회원을 찾을 수 없으면") { | ||
Then("예외가 발생한다.") { | ||
shouldThrow<NotFoundCustomException> { | ||
userService.signUp(invalidUser, request) | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
}) |
9 changes: 9 additions & 0 deletions
9
domain/src/main/kotlin/com/pokit/user/dto/request/SignUpRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.pokit.user.dto.request | ||
|
||
import com.pokit.user.model.InterestType | ||
|
||
data class SignUpRequest( | ||
val nickName: String, | ||
val interests: List<InterestType> | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
domain/src/main/kotlin/com/pokit/user/dto/response/SignUpResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.pokit.user.dto.response | ||
|
||
class SignUpResponse( | ||
val userId: Long | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.