feat(user) : 회원 등록 기능 구현
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.adapter.register
|
||||||
|
|
||||||
|
import com.banjjoknim.springmultimodule.user.User
|
||||||
|
import com.banjjoknim.springmultimodule.user.UserRepository
|
||||||
|
import com.banjjoknim.springmultimodule.user.application.register.UserRegisterPersistencePort
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
class UserRegisterPersistenceAdapter(
|
||||||
|
private val userRepository: UserRepository
|
||||||
|
) : UserRegisterPersistencePort {
|
||||||
|
override fun registerUser(user: User): User {
|
||||||
|
return userRepository.save(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.adapter.register
|
||||||
|
|
||||||
|
import com.banjjoknim.springmultimodule.user.application.register.UserRegisterRequestData
|
||||||
|
import javax.validation.constraints.NotBlank
|
||||||
|
|
||||||
|
data class UserRegisterRequest(
|
||||||
|
@NotBlank
|
||||||
|
val name: String = ""
|
||||||
|
) {
|
||||||
|
fun toData(): UserRegisterRequestData {
|
||||||
|
return UserRegisterRequestData(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.adapter.register
|
||||||
|
|
||||||
|
import com.banjjoknim.springmultimodule.user.application.register.UserRegisterResponseData
|
||||||
|
|
||||||
|
data class UserRegisterResponse(
|
||||||
|
val userId: Long
|
||||||
|
) {
|
||||||
|
constructor(responseData: UserRegisterResponseData) : this(
|
||||||
|
userId = responseData.userId
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.adapter.register
|
||||||
|
|
||||||
|
import com.banjjoknim.springmultimodule.user.application.register.UserRegisterUseCase
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
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
|
||||||
|
import javax.validation.Valid
|
||||||
|
|
||||||
|
@RequestMapping("/users")
|
||||||
|
@RestController
|
||||||
|
class UserRegisterWebAdapter(
|
||||||
|
private val userRegisterUseCase: UserRegisterUseCase
|
||||||
|
) {
|
||||||
|
@PostMapping("")
|
||||||
|
fun registerUser(@RequestBody @Valid userRegisterRequest: UserRegisterRequest): ResponseEntity<UserRegisterResponse> {
|
||||||
|
val requestData = userRegisterRequest.toData()
|
||||||
|
val responseData = userRegisterUseCase.registerUser(requestData)
|
||||||
|
return ResponseEntity.ok(UserRegisterResponse(responseData))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.application.register
|
||||||
|
|
||||||
|
import com.banjjoknim.springmultimodule.user.User
|
||||||
|
|
||||||
|
interface UserRegisterPersistencePort {
|
||||||
|
fun registerUser(user: User): User
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.application.register
|
||||||
|
|
||||||
|
data class UserRegisterRequestData(val name: String)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.application.register
|
||||||
|
|
||||||
|
import com.banjjoknim.springmultimodule.user.User
|
||||||
|
|
||||||
|
data class UserRegisterResponseData(val userId: Long) {
|
||||||
|
constructor(user: User) : this(
|
||||||
|
userId = user.id
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.application.register
|
||||||
|
|
||||||
|
import com.banjjoknim.springmultimodule.user.User
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class UserRegisterService(
|
||||||
|
private val userRegisterPersistencePort: UserRegisterPersistencePort
|
||||||
|
) : UserRegisterUseCase {
|
||||||
|
@Transactional
|
||||||
|
override fun registerUser(requestData: UserRegisterRequestData): UserRegisterResponseData {
|
||||||
|
val newUser = User(name = requestData.name)
|
||||||
|
val user = userRegisterPersistencePort.registerUser(newUser)
|
||||||
|
return UserRegisterResponseData(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.banjjoknim.springmultimodule.user.application.register
|
||||||
|
|
||||||
|
interface UserRegisterUseCase {
|
||||||
|
fun registerUser(requestData: UserRegisterRequestData): UserRegisterResponseData
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user