Skip to content

Commit

Permalink
API 이름 수정, BaseEntity 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Jan 13, 2025
1 parent 118838f commit d6411c7
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 37 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/com/ohayo/moyamoya/api/user/UserApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class UserApi(
@GetMapping("exists")
fun exists(@RequestParam phone: String) = userService.exists(phone)

@PostMapping("authorization-code")
fun sendAuthorizationCode(@RequestParam phone: String) = userService.sendAuthorizationCode(phone)
@PostMapping("send-code")
fun sendCode(@RequestParam phone: String) = userService.sendCode(phone)

@PostMapping("authorize-code")
fun authorizeCode(@RequestParam phone: String, @RequestParam code: String) = userService.authorizeCode(phone, code)
@PostMapping("verify-code")
fun verifyCode(@RequestParam phone: String, @RequestParam code: String) = userService.verifyCode(phone, code)

@PostMapping("sign-up")
fun signUp(@RequestBody @Valid req: SignUpReq) = userService.signUp(req)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/ohayo/moyamoya/api/user/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UserService(
isExists = userRepository.existsByPhone(phone)
)

fun sendAuthorizationCode(phone: String): VoidRes {
fun sendCode(phone: String): VoidRes {
val code = smsClient.sendAuthorizationCode(phone)
phoneCodeRepository.save(
PhoneCodeEntity(
Expand All @@ -41,7 +41,7 @@ class UserService(
return VoidRes()
}

fun authorizeCode(phone: String, code: String): VoidRes {
fun verifyCode(phone: String, code: String): VoidRes {
val codes = phoneCodeRepository.findByStatusAndPhoneAndCode(
status = PhoneCodeEntity.Status.UNUSED,
phone = phone,
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/ohayo/moyamoya/core/BaseEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ohayo.moyamoya.core

import jakarta.persistence.*
import java.time.LocalDateTime

@MappedSuperclass
abstract class BaseEntity(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int = 0,

@Column(nullable = false, updatable = false, columnDefinition = "DATETIME(6)")
val createdAt: LocalDateTime = LocalDateTime.now(),
)
5 changes: 1 addition & 4 deletions src/main/kotlin/com/ohayo/moyamoya/core/FcmTokenEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import jakarta.persistence.*
@Entity
@Table(name = "tbl_fcm_token")
class FcmTokenEntity(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int = 0,

@Column(nullable = false)
val fcmToken: String,

@JoinColumn(nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
val user: UserEntity,
)
): BaseEntity()
12 changes: 4 additions & 8 deletions src/main/kotlin/com/ohayo/moyamoya/core/PhoneCodeEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import jakarta.persistence.*
@Entity
@Table(name = "tbl_phone_code")
class PhoneCodeEntity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int = 0,

@Column(nullable = false)
val phone: String,

Expand All @@ -18,11 +14,11 @@ class PhoneCodeEntity(
@Column(nullable = false)
@Enumerated(EnumType.STRING)
var status: Status = Status.UNUSED
) {
): BaseEntity() {
enum class Status(val nextStep: Status?) {
SIGNED_UP(null),
AUTHORIZED(SIGNED_UP),
UNUSED(AUTHORIZED),
SIGNED_UP(nextStep = null), // 회원가입이 된 상태
AUTHORIZED(nextStep = SIGNED_UP), // 인증 코드로 인증 된 상태
UNUSED(nextStep = AUTHORIZED), // 초기 상태
}

fun updateStatus() {
Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/com/ohayo/moyamoya/core/SchoolEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import java.time.LocalDate
@Entity
@Table(name = "tbl_school")
class SchoolEntity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int = 0,

@Column(nullable = false)
val name: String,

Expand All @@ -25,11 +21,11 @@ class SchoolEntity(

@Column(nullable = false)
val phone: String,

val website: String?,

@Column(nullable = false)
val createdAt: LocalDate,
val foundedAt: LocalDate,

@Column(nullable = false)
val anniversary: LocalDate,
Expand All @@ -39,4 +35,4 @@ class SchoolEntity(

@Column(nullable = false)
val officeCode: String,
)
): BaseEntity()
5 changes: 1 addition & 4 deletions src/main/kotlin/com/ohayo/moyamoya/core/UserEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import jakarta.persistence.*
@Entity
@Table(name = "tbl_user")
class UserEntity(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int = 0,

@Column(unique = true, nullable = false)
val phone: String,

Expand All @@ -33,4 +30,4 @@ class UserEntity(

@Column(nullable = false)
val userRole: UserRole = UserRole.NORMAL
)
): BaseEntity()
4 changes: 2 additions & 2 deletions src/main/kotlin/com/ohayo/moyamoya/global/SecurityConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class SecurityConfig(
"/users/refresh",
"/users/sign-up",
"/users/exists",
"/users/authorize-code",
"/users/authorization-code",
"/users/verify-code",
"/users/send-code",

"/schools",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.ohayo.moyamoya.core.SchoolType
import com.ohayo.moyamoya.global.CustomException
import mu.KLogger
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.CommandLineRunner
import org.springframework.http.HttpStatus
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
Expand Down Expand Up @@ -68,7 +67,7 @@ class NeisSchoolClient(
addressDetail = it.orgRdnda,
phone = it.orgTelno,
website = it.hmpgAdres,
createdAt = LocalDate.parse(it.fondYmd, DateTimeFormatter.ofPattern("yyyyMMdd")),
foundedAt = LocalDate.parse(it.fondYmd, DateTimeFormatter.ofPattern("yyyyMMdd")),
anniversary = LocalDate.parse(it.foasMemrd, DateTimeFormatter.ofPattern("yyyyMMdd")),
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/com/ohayo/moyamoya/api/UserApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ class UserApiTest {

@Test
fun `인증 코드 발송`() {
mvc.post("/users/authorization-code") {
mvc.post("/users/send-code") {
param("phone", testPhone2)
}.andExpect { status { isOk() } }
}

@Test
fun `인증 코드 발송 후 검증`() {
`인증 코드 발송`()
mvc.post("/users/authorize-code") {
mvc.post("/users/verify-code") {
param("phone", testPhone2)
param("code", TestSmsClient.FAKE_AUTHORIZATION_CODE)
}.andExpect { status { isOk() } }
Expand All @@ -69,7 +69,7 @@ class UserApiTest {
@Test
fun `인증 코드 발송 후 검증 - 이상한 코드`() {
this.`인증 코드 발송`()
mvc.post("/users/authorize-code") {
mvc.post("/users/verify-code") {
param("phone", testPhone2)
param("code", "노영재")
}.andExpect { status { isBadRequest() } }
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/ohayo/moyamoya/api/dummyValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ val dummySchool = SchoolEntity(
addressDetail = "testAddressDetail",
phone = "testPhone",
website = "test.com",
createdAt = LocalDate.now(),
foundedAt = LocalDate.now(),
anniversary = LocalDate.now(),
schoolCode = "testSchoolCode",
officeCode = "testOfficeCode",
Expand Down

0 comments on commit d6411c7

Please sign in to comment.