-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] 회원가입 API 생성 #14
Changes from all commits
b30f50e
3c5d857
51d2449
37ca89b
1fdeb59
071a3af
8fecba1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
package com.psr.psr.global | ||
|
||
class Constant { | ||
companion object JWT{ | ||
const val AUTHORIZATION_HEADER = "Authorization" | ||
const val BEARER_PREFIX: String = "Bearer " | ||
class JWT{ | ||
companion object JWT{ | ||
const val AUTHORIZATION_HEADER = "Authorization" | ||
const val BEARER_PREFIX: String = "Bearer " | ||
} | ||
} | ||
|
||
class User{ | ||
companion object User{ | ||
// 비밀번호 (숫자, 문자, 특수문자 포함 8~15자리 이내) | ||
const val PASSWORD_VALIDATION = "^.*(?=^.{8,15}\$)(?=.*\\d)(?=.*[a-zA-Z])(?=.*[!@#\$%^&+=]).*\$" | ||
const val EMAIL_VALIDATION = "^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}\$" | ||
const val PHONE_VALIDATION = "^01([0|1|6|7|8|9])-?([0-9]{3,4})-?([0-9]{4})\$" | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ package com.psr.psr.global.exception | |
import org.springframework.http.HttpStatus | ||
|
||
data class BaseRes( | ||
val status: HttpStatus, | ||
val status: Int, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 부분도 에러 발생하면 400 에러가 나야하는데 BAD_REQUEST 라고 return 되길래, |
||
val message: String? | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package com.psr.psr.global.jwt.dto | ||
|
||
data class TokenRes(val accessToken: String, val refreshToken: String) | ||
import com.psr.psr.user.entity.Type | ||
|
||
data class TokenRes(val accessToken: String, val refreshToken: String, val type: String) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
package com.psr.psr.user.controller | ||
|
||
import com.psr.psr.global.dto.BaseResponse | ||
import com.psr.psr.global.exception.BaseResponseCode | ||
import com.psr.psr.global.jwt.dto.TokenRes | ||
import com.psr.psr.user.dto.SignUpReq | ||
import com.psr.psr.user.service.UserService | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@RestController | ||
@RequestMapping("/users") | ||
class UserController( | ||
private val userService: UserService | ||
) { | ||
/** | ||
* 회원가입 | ||
*/ | ||
@PostMapping("/signup") | ||
@ResponseBody | ||
fun signUp (@RequestBody signUpReq: SignUpReq) : BaseResponse<TokenRes>{ | ||
chaerlo127 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return BaseResponse(userService.signUp(signUpReq)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.psr.psr.user.dto | ||
|
||
import com.psr.psr.user.entity.* | ||
import java.util.stream.Collector | ||
import java.util.stream.Collectors | ||
|
||
|
||
|
||
|
||
data class SignUpReq ( | ||
val email: String, | ||
var password: String, | ||
val type: String, | ||
val phone: String, | ||
val imgKey: String, | ||
val nickname: String, | ||
val marketing: Boolean, | ||
val notification: Boolean, | ||
val interestList: List<UserInterestReq> | ||
) { | ||
fun toEntity(): User { | ||
return User(email = email, | ||
password = password, | ||
type = Type.getTypeByName(type), | ||
phone = phone, | ||
imgKey = imgKey, | ||
provider = Provider.LOCAL, | ||
marketing = marketing, | ||
notification = notification, | ||
nickname = nickname) | ||
} | ||
|
||
fun toInterestEntity(user: User): List<UserInterest> { | ||
return interestList.stream() | ||
.map { i -> | ||
UserInterest(category = Category.getCategoryByName(i.category), | ||
user = user) | ||
}.collect(Collectors.toList()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.psr.psr.user.dto | ||
|
||
import com.psr.psr.user.entity.Category | ||
|
||
data class UserInterestReq ( | ||
val category: String | ||
){ | ||
fun checkInterestCategory() : Category{ | ||
return Category.getCategoryByName(category) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package com.psr.psr.user.entity | ||
|
||
import com.psr.psr.global.exception.BaseException | ||
import com.psr.psr.global.exception.BaseResponseCode | ||
|
||
enum class Category(val value: String) { | ||
BROADCAST_PRODUCT("방송가능 상품소싱"), | ||
SHOW_HOST_ADVERTISE("쇼호스트 구인"), | ||
|
@@ -9,5 +12,12 @@ enum class Category(val value: String) { | |
VIDEO_EDITING("영상편집"), | ||
INSTRUCTOR_MATCHING("강사매칭"), | ||
SNS_MARKETING("SNS 마케팅"), | ||
PROMOTION_DESIGN("홍보물 디자인") | ||
PROMOTION_DESIGN("홍보물 디자인"); | ||
|
||
companion object { | ||
fun getCategoryByName(name: String): Category { | ||
return enumValues<Category>().find { it.value == name } | ||
?: throw BaseException(BaseResponseCode.INVALID_USER_CATEGORY) | ||
} | ||
} | ||
Comment on lines
+17
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사.❤️🔥 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
package com.psr.psr.user.entity | ||
|
||
import com.psr.psr.global.exception.BaseException | ||
import com.psr.psr.global.exception.BaseResponseCode | ||
|
||
|
||
enum class Type(val value: String) { | ||
GENERAL("일반"), | ||
ENTREPRENEUR("사업자"), | ||
SHOW_HOST("쇼호스트"), | ||
MANAGER("관리자") | ||
MANAGER("관리자"); | ||
|
||
companion object { | ||
fun getTypeByName(name: String): Type { | ||
return enumValues<Type>().find { it.value == name } | ||
?: throw BaseException(BaseResponseCode.INVALID_USER_TYPE_NAME) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ import jakarta.persistence.* | |
import org.jetbrains.annotations.NotNull | ||
|
||
@Entity | ||
data class User( | ||
class User( | ||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
var id: Long, | ||
var id: Long? = null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 찾아보니까 kotlin은 따로 builder가 없대요 ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 팁줍줍 |
||
|
||
@NotNull | ||
@Column(length = 100) | ||
|
@@ -29,7 +29,7 @@ data class User( | |
@Column(length = 15) | ||
var phone:String, | ||
|
||
var imgKey: String, | ||
var imgKey: String? = null, | ||
|
||
@NotNull | ||
@Enumerated(EnumType.STRING) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분 변경 됐어요 !
result 가 constructor에 반영이 안돼서 !