Skip to content

Instantly share code, notes, and snippets.

@GHGHGHKO
GHGHGHKO / UserControllerTest.kt
Created February 23, 2023 12:01
UserControllerTest const val and token var
companion object {
private const val ID = "User"
private const val ADMIN = "[email protected]"
private const val EMAIL = "@real.com"
private const val PASSWORD = "existPassword!@#s2"
private const val NICKNAME = "patric"
private const val X_AUTH_TOKEN = "X-AUTH-TOKEN"
}
lateinit var token: String
@GHGHGHKO
GHGHGHKO / UserControllerTest.kt
Created February 23, 2023 11:53
UserControllerTest success get all users
package com.example.pepega.common.controller
import com.example.pepega.common.domain.UserMaster
import com.example.pepega.common.dto.sign.request.SignInRequestDto
import com.example.pepega.common.dto.sign.request.SignUpRequestDto
import com.example.pepega.common.repository.UserMasterRepository
import com.example.pepega.common.service.sign.SignService
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
@GHGHGHKO
GHGHGHKO / UserController.kt
Created February 22, 2023 13:19
UserController getAllUsers
package com.example.pepega.common.controller
import com.example.pepega.common.dto.user.UsersResponseDto
import com.example.pepega.common.model.response.MutableListResult
import com.example.pepega.common.service.response.ResponseService
import com.example.pepega.common.service.user.UserService
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@GHGHGHKO
GHGHGHKO / ResponseService.kt
Created February 22, 2023 12:57
ResponseService mutableListResult
fun <T> mutableListResult(results: MutableList<T>): MutableListResult<T> {
val common = successResult()
return MutableListResult(
common.success,
common.code,
common.message,
results
)
}
@GHGHGHKO
GHGHGHKO / UserService.kt
Created February 22, 2023 12:53
UserService getUsers
package com.example.pepega.common.service.user
import com.example.pepega.common.dto.user.UsersResponseDto
import com.example.pepega.common.repository.UserMasterRepository
import org.springframework.stereotype.Service
@Service
class UserService(
private val userMasterRepository: UserMasterRepository
) {
@GHGHGHKO
GHGHGHKO / UsersResponseDto.kt
Created February 22, 2023 12:53
UsersResponseDto
package com.example.pepega.common.dto.user
data class UsersResponseDto(
val email: String,
val nickName: String,
val roles: MutableList<String>
)
@GHGHGHKO
GHGHGHKO / MutableListResult.kt
Created February 22, 2023 12:33
MutableListResult
package com.example.pepega.common.model.response
class MutableListResult<T> (
success: Boolean,
code: Int,
message:String,
var results: MutableList<T>
): CommonResult(success, code, message)
@GHGHGHKO
GHGHGHKO / exception_en.properties
Created February 22, 2023 11:17
exception_en.properties entryPointException
entryPointException.code = -1002
entryPointException.message = You do not have permission to access this resource.
@GHGHGHKO
GHGHGHKO / exception.properties
Created February 22, 2023 11:16
KR exception.properties entryPointException
entryPointException.code = -1002
entryPointException.message = 해당 리소스에 접근하기 위한 권한이 없습니다.
@GHGHGHKO
GHGHGHKO / ExceptionAdvice.kt
Created February 22, 2023 11:15
ExceptionAdvice authenticationEntryPointExceptionException
@ExceptionHandler(value = [AuthenticationException::class])
fun authenticationEntryPointException(): ResponseEntity<CommonResult> {
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.body(responseService.failResult(
getMessage("entryPointException.code").toInt(),
getMessage("entryPointException.message")))
}