Skip to content

Commit

Permalink
[IDLE-62] 센터 관리자 회원가입 API
Browse files Browse the repository at this point in the history
  • Loading branch information
wonjunYou committed Jul 6, 2024
1 parent 8596561 commit c9a8de3
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.swm.idle.api.auth.carer.spec

import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.RequestMapping

@Tag(name = "Auth-Carer", description = "Carer Auth API")
@RequestMapping("/api/v1/auth/carer", produces = ["application/json"])
interface CarerAuthApi {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.swm.idle.api.auth.center.controller

import com.swm.idle.api.auth.center.dto.JoinRequest
import com.swm.idle.api.auth.center.facade.CenterAuthFacadeService
import com.swm.idle.api.auth.center.spec.CenterAuthApi
import com.swm.idle.domain.center.vo.BusinessRegistrationNumber
import com.swm.idle.domain.sms.vo.PhoneNumber
import org.springframework.web.bind.annotation.RestController

@RestController
class CenterAuthController(
private val centerAuthFacadeService: CenterAuthFacadeService,
) : CenterAuthApi {

override fun join(request: JoinRequest) {
centerAuthFacadeService.join(
identifier = request.identifier,
password = request.password,
phoneNumber = PhoneNumber(request.phoneNumber),
managerName = request.managerName,
centerBusinessRegistrationNumber = BusinessRegistrationNumber(request.centerBusinessRegistrationNumber),
)
}

// override fun login(request: LoginRequest): LoginResponse {
// TODO("Not yet implemented")
// }
//
// override fun logout() {
// TODO("Not yet implemented")
// }
//
// override fun refreshLoginToken(request: RefreshTokenRequest): RefreshLoginTokenResponse {
// TODO("Not yet implemented")
// }
//
// override fun withDraw() {
// TODO("Not yet implemented")
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.swm.idle.api.auth.center.dto

import io.swagger.v3.oas.annotations.media.Schema

@Schema(
name = "Center Manager Join Request",
description = "센터 관리자 회원 가입 요청"
)
data class JoinRequest(
@Schema(description = "아이디(ID)")
val identifier: String,
@Schema(description = "비밀번호")
val password: String,
@Schema(description = "관리자 휴대폰 번호", example = "010-0000-0000")
val phoneNumber: String,
@Schema(description = "관리자 성명")
val managerName: String,
@Schema(description = "센터 사업자 등록 번호", example = "000-00-00000")
val centerBusinessRegistrationNumber: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.swm.idle.api.auth.center.facade

import com.swm.idle.domain.center.service.CenterManagerService
import com.swm.idle.domain.center.vo.BusinessRegistrationNumber
import com.swm.idle.domain.sms.vo.PhoneNumber
import org.springframework.stereotype.Service

@Service
class CenterAuthFacadeService(
private val centerManagerService: CenterManagerService,
) {
fun join(
identifier: String,
password: String,
phoneNumber: PhoneNumber,
managerName: String,
centerBusinessRegistrationNumber: BusinessRegistrationNumber,
) {
centerManagerService.save(
identifier = identifier,
password = password,
phoneNumber = phoneNumber,
managerName = managerName,
centerBusinessRegistrationNumber = centerBusinessRegistrationNumber,
)
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.swm.idle.api.auth.center.spec

import com.swm.idle.api.auth.center.dto.LoginRequest
import com.swm.idle.api.auth.center.dto.LoginResponse
import com.swm.idle.api.auth.center.dto.RefreshLoginTokenResponse
import com.swm.idle.api.auth.center.dto.RefreshTokenRequest
import com.swm.idle.api.auth.center.dto.JoinRequest
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.HttpStatus
Expand All @@ -16,27 +13,34 @@ import org.springframework.web.bind.annotation.ResponseStatus
@RequestMapping("/api/v1/auth/center", produces = ["application/json"])
interface CenterAuthApi {

@Operation(summary = "센터 로그인 API")
@PostMapping("/login")
fun login(
@RequestBody request: LoginRequest,
): LoginResponse
@Operation(summary = "센터 관리자 회원가입 API")
@PostMapping("/join")
@ResponseStatus(HttpStatus.CREATED)
fun join(
@RequestBody request: JoinRequest,
)

@Operation(summary = "센터 로그아웃 API")
@PostMapping("/logout")
@ResponseStatus(HttpStatus.OK)
fun logout()

@Operation(summary = "Refresh Login Token API")
@PostMapping("/refresh")
@ResponseStatus(HttpStatus.OK)
fun refreshLoginToken(
@RequestBody request: RefreshTokenRequest,
): RefreshLoginTokenResponse

@Operation(summary = "센터 회원 탈퇴 API")
@PostMapping("/withdraw")
@ResponseStatus(HttpStatus.OK)
fun withDraw()
// @Operation(summary = "센터 로그인 API")
// @PostMapping("/login")
// fun login(
// @RequestBody request: LoginRequest,
// ): LoginResponse
//
// @Operation(summary = "센터 로그아웃 API")
// @PostMapping("/logout")
// @ResponseStatus(HttpStatus.OK)
// fun logout()
//
// @Operation(summary = "Refresh Login Token API")
// @PostMapping("/refresh")
// @ResponseStatus(HttpStatus.OK)
// fun refreshLoginToken(
// @RequestBody request: RefreshTokenRequest,
// ): RefreshLoginTokenResponse
//
// @Operation(summary = "센터 회원 탈퇴 API")
// @PostMapping("/withdraw")
// @ResponseStatus(HttpStatus.OK)
// fun withDraw()

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController

@RestController
class AuthController(
val authFacadeService: AuthFacadeService,
private val authFacadeService: AuthFacadeService,
) : AuthApi {

override fun sendVerificationMessage(request: SendSmsVerificationRequest) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.swm.idle.domain.center.entity

import com.swm.idle.domain.center.enums.CenterAccountStatus
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.util.*

@Entity
@Table(name = "center_manager")
class CenterManager(
id: UUID,
identifier: String,
password: String,
managerName: String,
phoneNumber: String,
status: CenterAccountStatus,
centerBusinessRegistrationNumber: String,
) {

@Id
@Column(nullable = false)
var id: UUID = id
private set

@Column(nullable = false, columnDefinition = "varchar(255)")
var identifier: String = identifier
private set

@Column(nullable = false, columnDefinition = "varchar(255)")
var password: String = password
private set

@Column(nullable = false, columnDefinition = "varchar(255)")
var managerName: String = managerName
private set

@Column(nullable = false, columnDefinition = "varchar(255)")
var phoneNumber: String = phoneNumber
private set

@Enumerated(EnumType.STRING)
@Column(nullable = false, columnDefinition = "varchar(255)")
var status: CenterAccountStatus = status
private set

@Column(nullable = false, columnDefinition = "varchar(255)")
var centerBusinessRegistrationNumber: String = centerBusinessRegistrationNumber
private set

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.swm.idle.domain.center.enums

enum class CenterAccountStatus {
ACTIVE,
PENDING,
INACTIVE,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.swm.idle.domain.center.repository

import com.swm.idle.domain.center.entity.CenterManager
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import java.util.*

@Repository
interface CenterManagerJpaRepository : JpaRepository<CenterManager, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.swm.idle.domain.center.service

import com.swm.idle.domain.center.entity.CenterManager
import com.swm.idle.domain.center.enums.CenterAccountStatus
import com.swm.idle.domain.center.repository.CenterManagerJpaRepository
import com.swm.idle.domain.center.vo.BusinessRegistrationNumber
import com.swm.idle.domain.sms.vo.PhoneNumber
import com.swm.idle.support.common.uuid.UuidCreator
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class CenterManagerService(
private val centerManagerJpaRepository: CenterManagerJpaRepository,
) {

@Transactional
fun save(
identifier: String,
password: String,
phoneNumber: PhoneNumber,
managerName: String,
centerBusinessRegistrationNumber: BusinessRegistrationNumber,
) {
CenterManager(
id = UuidCreator.create(),
identifier = identifier,
password = password,
phoneNumber = phoneNumber.value,
managerName = managerName,
status = CenterAccountStatus.PENDING,
centerBusinessRegistrationNumber = centerBusinessRegistrationNumber.value,
).also {
centerManagerJpaRepository.save(it)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.swm.idle.domain.center.vo

@JvmInline
value class BusinessRegistrationNumber(val value: String) {

init {
require(value.matches(Regex(VALIDATION_REGEX)))
}

companion object {
const val VALIDATION_REGEX = "^\\d{3}-\\d{2}-\\d{5}$"
}
}

0 comments on commit c9a8de3

Please sign in to comment.