Skip to content

Commit

Permalink
[KAN-29] 유저 api url, dto 설계 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok authored Apr 29, 2024
1 parent 4df52c3 commit 56c2225
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class SecurityConfig(
.antMatchers(
"/v1/users/email/sign-up",
"/v1/users/email/sign-in",
"/v1/users/email/send",
"/v1/users/email/validate",
"/v1/users/password",

"/hello",
"/profile",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.restaurant.be.user.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.user.presentation.dto.GetUserResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.responses.ApiResponse
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Api(tags = ["01. User Info"], description = "유저 서비스")
@RestController
@RequestMapping("/api/v1/users")
class GetUserController {

@GetMapping("/{userId}")
@PreAuthorize("hasRole('USER')")
@ApiOperation(value = "유저 정보 조회 API")
@ApiResponse(
responseCode = "200",
description = "성공",
content = [Content(schema = Schema(implementation = GetUserResponse::class))]
)
fun getUser(@PathVariable userId: String): CommonResponse<GetUserResponse> {
return CommonResponse.success()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.restaurant.be.user.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.user.presentation.dto.UpdatePasswordRequest
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import org.springframework.web.bind.annotation.PatchMapping
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

@Api(tags = ["01. User Info"], description = "유저 서비스")
@RestController
@RequestMapping("/api/v1/users/password")
class UpdatePasswordController {

@PatchMapping
@ApiOperation(value = "비밀번호 변경 API")
@ApiResponse(
responseCode = "200",
description = "성공"
)
fun passwordUpdate(
@Valid @RequestBody
request: UpdatePasswordRequest
): CommonResponse<Unit> {
return CommonResponse.success()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.restaurant.be.user.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.user.presentation.dto.UpdateUserRequest
import com.restaurant.be.user.presentation.dto.UpdateUserResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.responses.ApiResponse
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.security.Principal
import javax.validation.Valid

@Api(tags = ["01. User Info"], description = "유저 서비스")
@RestController
@RequestMapping("/api/v1/users")
class UpdateUserController {

@PatchMapping
@PreAuthorize("hasRole('USER')")
@ApiOperation(value = "유저 수정 API")
@ApiResponse(
responseCode = "200",
description = "성공",
content = [Content(schema = Schema(implementation = UpdateUserResponse::class))]
)
fun updateUser(
principal: Principal,
@Valid @RequestBody
request: UpdateUserRequest
): CommonResponse<UpdateUserResponse> {
return CommonResponse.success()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.restaurant.be.user.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.user.presentation.dto.SendEmailRequest
import com.restaurant.be.user.presentation.dto.ValidateEmailRequest
import com.restaurant.be.user.presentation.dto.ValidateEmailResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.responses.ApiResponse
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

@Api(tags = ["01. User Info"], description = "유저 서비스")
@RestController
@RequestMapping("/v1/users/email")
class ValidateEmailController {
@PostMapping("/send")
@ApiOperation(value = "이메일 전송 API")
@ApiResponse(
responseCode = "200",
description = "성공"
)
fun sendEmail(
@Valid @RequestBody
request: SendEmailRequest
): CommonResponse<Unit> {
return CommonResponse.success()
}

@PostMapping("/validate")
@ApiOperation(value = "이메일 인증 API")
@ApiResponse(
responseCode = "200",
description = "성공",
content = [Content(schema = Schema(implementation = ValidateEmailResponse::class))]
)
fun validateEmail(
@Valid @RequestBody
request: ValidateEmailRequest
): CommonResponse<ValidateEmailResponse> {
return CommonResponse.success(ValidateEmailResponse("test"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@file:Suppress("ktlint", "MatchingDeclarationName")

package com.restaurant.be.user.presentation.dto

import com.restaurant.be.user.presentation.dto.common.UserDto
import io.swagger.v3.oas.annotations.media.Schema

data class GetUserResponse(
@Schema(description = "유저 정보")
val userDto: UserDto
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:Suppress("ktlint", "MatchingDeclarationName")

package com.restaurant.be.user.presentation.dto

import com.restaurant.be.user.presentation.dto.common.EmailSendType
import io.swagger.annotations.ApiModelProperty
import javax.validation.constraints.Email
import javax.validation.constraints.NotEmpty

data class SendEmailRequest(
@field:NotEmpty(message = "이메일은 필수 값 입니다.")
@field:Email(message = "유효하지 않는 이메일 입니다.")
@ApiModelProperty(value = "이메일", example = "[email protected]", required = true)
val email: String,

@ApiModelProperty(
value = "이메일 전송 타입",
example = "EMAIL_VALIDATION",
required = true,
allowableValues = "EMAIL_VALIDATION, UPDATE_PASSWORD"
)
val sendType: EmailSendType
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ data class SignUpUserRequest(

@field:NotBlank(message = "닉네임을 입력해 주세요.")
@ApiModelProperty(value = "닉네임", example = "닉네임", required = true)
val nickname: String = ""
val nickname: String = "",

@ApiModelProperty(
value = "프로필 이미지 URL",
example = "https://test.com/test.jpg",
required = true
)
val profileImageUrl: String = ""
) {

fun toEntity() = User(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:Suppress("ktlint", "MatchingDeclarationName")

package com.restaurant.be.user.presentation.dto

import io.swagger.annotations.ApiModelProperty
import javax.validation.constraints.NotEmpty
import javax.validation.constraints.Pattern

data class UpdatePasswordRequest(
@field:NotEmpty(message = "비밀번호는 필수 값 입니다.")
@field:Pattern(
regexp = "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[\\W_])[A-Za-z\\d\\W_]{8,16}\$",
message = "영소문자, 영대문자, 숫자, 특수문자가 포함된 8~16자 비밀번호"
)
@ApiModelProperty(value = "비밀번호", example = "Test1234!", required = true)
val password: String,
@field:NotEmpty(message = "변경 토큰은 필수 값 입니다.")
@ApiModelProperty(
value = "변경 토큰",
example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVIjoxNjIzNTEyNzAwfQ.7J1"
)
val token: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.restaurant.be.user.presentation.dto

import com.restaurant.be.user.presentation.dto.common.UserDto
import io.swagger.annotations.ApiModelProperty
import io.swagger.v3.oas.annotations.media.Schema
import javax.validation.constraints.NotBlank

data class UpdateUserRequest(
@field:NotBlank(message = "닉네임을 입력해 주세요.")
@ApiModelProperty(value = "닉네임", example = "닉네임", required = true)
val nickname: String = "",

@ApiModelProperty(
value = "프로필 이미지 URL",
example = "https://test.com/test.jpg",
required = true
)
val profileImageUrl: String = ""
)

data class UpdateUserResponse(
@Schema(description = "유저 정보")
val userDto: UserDto
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.restaurant.be.user.presentation.dto

import com.restaurant.be.user.presentation.dto.common.EmailSendType
import io.swagger.annotations.ApiModelProperty
import javax.validation.constraints.Email
import javax.validation.constraints.NotEmpty

data class ValidateEmailRequest(
@field:NotEmpty(message = "이메일은 필수 값 입니다.")
@field:Email(message = "유효하지 않는 이메일 입니다.")
@ApiModelProperty(value = "이메일", example = "[email protected]", required = true)
val email: String,
@ApiModelProperty(value = "인증번호", required = true)
val code: String,
@ApiModelProperty(
value = "이메일 전송 타입",
example = "EMAIL_VALIDATION",
required = true,
allowableValues = "EMAIL_VALIDATION, UPDATE_PASSWORD"
)
val sendType: EmailSendType
)

data class ValidateEmailResponse(
val token: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.restaurant.be.user.presentation.dto.common

enum class EmailSendType {
EMAIL_VALIDATION,
UPDATE_PASSWORD
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ package com.restaurant.be.user.presentation.dto.common
import io.swagger.annotations.ApiModelProperty

data class UserDto(
@ApiModelProperty(value = "유저 아이디", example = "1", required = true)
val id: Long = 0,

@ApiModelProperty(value = "이메일 아이디", example = "[email protected]", required = true)
val email: String = "",

@ApiModelProperty(value = "비밀번호", example = "test12!@", required = true)
val password: String = "",

@ApiModelProperty(value = "닉네임", example = "닉네임", required = true)
val nickname: String = ""
val nickname: String = "",

@ApiModelProperty(
value = "프로필 이미지 URL",
example = "https://test.com/test.jpg",
required = true
)
val profileImageUrl: String = ""
)

0 comments on commit 56c2225

Please sign in to comment.