diff --git a/src/main/kotlin/io/csbroker/apiserver/auth/AuthToken.kt b/src/main/kotlin/io/csbroker/apiserver/auth/AuthToken.kt index 205db063..d48ba7ac 100644 --- a/src/main/kotlin/io/csbroker/apiserver/auth/AuthToken.kt +++ b/src/main/kotlin/io/csbroker/apiserver/auth/AuthToken.kt @@ -18,21 +18,17 @@ class AuthToken( private val key: Key, ) { constructor(email: String, expiry: Date, key: Key, role: String? = null) : this("", key) { - if (role != null) { - token = createAuthToken(email, expiry, role) + token = if (role != null) { + createAuthToken(email, expiry, role) } else { - token = createAuthToken(email, expiry) + createAuthToken(email, expiry) } } val tokenClaims: Claims? get() { try { - return Jwts.parserBuilder() - .setSigningKey(key) - .build() - .parseClaimsJws(token) - .body + return parseJwt() } catch (e: SecurityException) { log.error("Invalid JWT signature.") } catch (e: MalformedJwtException) { @@ -52,11 +48,7 @@ class AuthToken( val expiredTokenClaims: Claims? get() { try { - Jwts.parserBuilder() - .setSigningKey(key) - .build() - .parseClaimsJws(token) - .body + parseJwt() } catch (e: ExpiredJwtException) { log.info("Expired JWT token.") return e.claims @@ -77,6 +69,12 @@ class AuthToken( val isValid: Boolean get() = tokenClaims != null + private fun parseJwt(): Claims? = Jwts.parserBuilder() + .setSigningKey(key) + .build() + .parseClaimsJws(token) + .body + private fun createAuthToken(email: String, expiry: Date): String { return Jwts.builder() .setSubject(email) diff --git a/src/main/kotlin/io/csbroker/apiserver/auth/AuthTokenProvider.kt b/src/main/kotlin/io/csbroker/apiserver/auth/AuthTokenProvider.kt index a609f583..14bde6c9 100644 --- a/src/main/kotlin/io/csbroker/apiserver/auth/AuthTokenProvider.kt +++ b/src/main/kotlin/io/csbroker/apiserver/auth/AuthTokenProvider.kt @@ -30,8 +30,8 @@ class AuthTokenProvider( .map(::SimpleGrantedAuthority) .toList() return UsernamePasswordAuthenticationToken(User(claims.subject, "", authorities), authToken, authorities) - } else { - throw UnAuthorizedException(ErrorCode.TOKEN_INVALID, "올바르지 않은 Token입니다.") } + + throw UnAuthorizedException(ErrorCode.TOKEN_INVALID, "올바르지 않은 Token입니다.") } } diff --git a/src/main/kotlin/io/csbroker/apiserver/auth/GithubOAuth2UserInfo.kt b/src/main/kotlin/io/csbroker/apiserver/auth/GithubOAuth2UserInfo.kt index 26bbb51a..79b8c3ec 100644 --- a/src/main/kotlin/io/csbroker/apiserver/auth/GithubOAuth2UserInfo.kt +++ b/src/main/kotlin/io/csbroker/apiserver/auth/GithubOAuth2UserInfo.kt @@ -2,21 +2,9 @@ package io.csbroker.apiserver.auth class GithubOAuth2UserInfo( attributes: MutableMap, -) : OAuth2UserInfo(attributes) { - - override fun getId(): String { - return (attributes["id"] as Int).toString() - } - - override fun getName(): String { - return attributes["login"] as String - } - - override fun getEmail(): String { - return attributes["email"] as String - } - - override fun getImageUrl(): String { - return attributes["avatar_url"] as String - } -} +) : OAuth2UserInfo( + id = (attributes["id"] as Int).toString(), + name = attributes["login"] as String, + email = attributes["email"] as String, + imageUrl = attributes["avatar_url"] as String, +) diff --git a/src/main/kotlin/io/csbroker/apiserver/auth/GoogleOAuth2UserInfo.kt b/src/main/kotlin/io/csbroker/apiserver/auth/GoogleOAuth2UserInfo.kt index 4f3d46b1..4f02f5f0 100644 --- a/src/main/kotlin/io/csbroker/apiserver/auth/GoogleOAuth2UserInfo.kt +++ b/src/main/kotlin/io/csbroker/apiserver/auth/GoogleOAuth2UserInfo.kt @@ -2,21 +2,9 @@ package io.csbroker.apiserver.auth class GoogleOAuth2UserInfo( attributes: MutableMap, -) : OAuth2UserInfo(attributes) { - - override fun getId(): String { - return attributes["sub"] as String - } - - override fun getName(): String { - return attributes["name"] as String - } - - override fun getEmail(): String { - return attributes["email"] as String - } - - override fun getImageUrl(): String { - return attributes["picture"] as String - } -} +) : OAuth2UserInfo( + id = attributes["sub"] as String, + name = attributes["name"] as String, + email = attributes["email"] as String, + imageUrl = attributes["picture"] as String, +) diff --git a/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfo.kt b/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfo.kt index 711c8434..0fb52f70 100644 --- a/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfo.kt +++ b/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfo.kt @@ -1,13 +1,8 @@ package io.csbroker.apiserver.auth abstract class OAuth2UserInfo( - val attributes: MutableMap, -) { - abstract fun getId(): String - - abstract fun getName(): String - - abstract fun getEmail(): String - - abstract fun getImageUrl(): String -} + val id: String, + val name: String, + val email: String, + val imageUrl: String, +) diff --git a/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfoFactory.kt b/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfoFactory.kt index 828dc0fe..5fae279c 100644 --- a/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfoFactory.kt +++ b/src/main/kotlin/io/csbroker/apiserver/auth/OAuth2UserInfoFactory.kt @@ -8,9 +8,7 @@ class OAuth2UserInfoFactory { return when (providerType) { ProviderType.GOOGLE -> GoogleOAuth2UserInfo(attributes) ProviderType.GITHUB -> GithubOAuth2UserInfo(attributes) - else -> throw OAuthProviderMissMatchException( - "프로바이더 타입이 일치하지 않습니다. ${providerType.name}", - ) + else -> throw OAuthProviderMissMatchException("프로바이더 타입이 일치하지 않습니다. ${providerType.name}") } } } diff --git a/src/main/kotlin/io/csbroker/apiserver/common/filter/TokenAuthenticationFilter.kt b/src/main/kotlin/io/csbroker/apiserver/common/filter/TokenAuthenticationFilter.kt index 93f43135..a5a3a285 100644 --- a/src/main/kotlin/io/csbroker/apiserver/common/filter/TokenAuthenticationFilter.kt +++ b/src/main/kotlin/io/csbroker/apiserver/common/filter/TokenAuthenticationFilter.kt @@ -17,7 +17,7 @@ class TokenAuthenticationFilter( response: HttpServletResponse, filterChain: FilterChain, ) { - val tokenStr = getAccessToken(request) + val tokenStr = request.getAccessToken() tokenStr ?: run { filterChain.doFilter(request, response) diff --git a/src/main/kotlin/io/csbroker/apiserver/common/handler/OAuth2AuthenticationSuccessHandler.kt b/src/main/kotlin/io/csbroker/apiserver/common/handler/OAuth2AuthenticationSuccessHandler.kt index 2899871f..31b1aee6 100644 --- a/src/main/kotlin/io/csbroker/apiserver/common/handler/OAuth2AuthenticationSuccessHandler.kt +++ b/src/main/kotlin/io/csbroker/apiserver/common/handler/OAuth2AuthenticationSuccessHandler.kt @@ -88,9 +88,9 @@ class OAuth2AuthenticationSuccessHandler( val user = authentication.principal as OidcUser val userInfo = OAuth2UserInfoFactory.getOauth2UserInfo(providerType, user.attributes) - return userRepository.findByEmailOrProviderId(userInfo.getEmail(), userInfo.getId()) + return userRepository.findByEmailOrProviderId(userInfo.email, userInfo.id) ?: throw EntityNotFoundException( - "유저를 찾을 수 없습니다. email = [${userInfo.getEmail()}], providerId = [${userInfo.getId()}] )", + "유저를 찾을 수 없습니다. email = [${userInfo.email}], providerId = [${userInfo.id}] )", ) } diff --git a/src/main/kotlin/io/csbroker/apiserver/common/util/CookieUtil.kt b/src/main/kotlin/io/csbroker/apiserver/common/util/CookieUtil.kt index cbe6688b..12bf824d 100644 --- a/src/main/kotlin/io/csbroker/apiserver/common/util/CookieUtil.kt +++ b/src/main/kotlin/io/csbroker/apiserver/common/util/CookieUtil.kt @@ -1,5 +1,6 @@ package io.csbroker.apiserver.common.util +import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest import org.springframework.util.SerializationUtils import java.util.Base64 import javax.servlet.http.Cookie @@ -21,19 +22,17 @@ fun addCookie(response: HttpServletResponse, name: String, value: String, maxAge } fun deleteCookie(request: HttpServletRequest, response: HttpServletResponse, name: String) { - request.cookies?.let { - it.find { cookie -> cookie.name == name }?.let { cookie -> - cookie.value = "" - cookie.path = "/" - cookie.maxAge = 0 - response.addCookie(cookie) - } + request.cookies?.find { cookie -> cookie.name == name }?.let { cookie -> + cookie.value = "" + cookie.path = "/" + cookie.maxAge = 0 + response.addCookie(cookie) } } -fun serialize(obj: Any): String { +fun OAuth2AuthorizationRequest.serialize(): String { return Base64.getUrlEncoder() - .encodeToString(SerializationUtils.serialize(obj)) + .encodeToString(SerializationUtils.serialize(this)) } fun deserialize(cookie: Cookie, cls: Class): T { diff --git a/src/main/kotlin/io/csbroker/apiserver/common/util/HeaderUtil.kt b/src/main/kotlin/io/csbroker/apiserver/common/util/HeaderUtil.kt index e284dcdc..1a5852f2 100644 --- a/src/main/kotlin/io/csbroker/apiserver/common/util/HeaderUtil.kt +++ b/src/main/kotlin/io/csbroker/apiserver/common/util/HeaderUtil.kt @@ -5,7 +5,7 @@ import javax.servlet.http.HttpServletRequest const val HEADER_AUTHORIZATION = "Authorization" const val TOKEN_PREFIX = "Bearer " -fun getAccessToken(request: HttpServletRequest): String? { - val headerValue = request.getHeader(HEADER_AUTHORIZATION) +fun HttpServletRequest.getAccessToken(): String? { + val headerValue = this.getHeader(HEADER_AUTHORIZATION) return if (headerValue?.startsWith(TOKEN_PREFIX) == true) headerValue.substring(TOKEN_PREFIX.length) else null } diff --git a/src/main/kotlin/io/csbroker/apiserver/common/util/UuidUtil.kt b/src/main/kotlin/io/csbroker/apiserver/common/util/UuidUtil.kt index c8bf7f68..ddf294e9 100644 --- a/src/main/kotlin/io/csbroker/apiserver/common/util/UuidUtil.kt +++ b/src/main/kotlin/io/csbroker/apiserver/common/util/UuidUtil.kt @@ -3,11 +3,9 @@ package io.csbroker.apiserver.common.util import java.nio.ByteBuffer import java.util.UUID -fun uuidAsByte(uuid: UUID?): ByteArray? { - uuid ?: return null - +fun UUID.asByte(): ByteArray? { val byteBufferWrapper = ByteBuffer.wrap(ByteArray(16)) - byteBufferWrapper.putLong(uuid.mostSignificantBits) - byteBufferWrapper.putLong(uuid.leastSignificantBits) + byteBufferWrapper.putLong(this.mostSignificantBits) + byteBufferWrapper.putLong(this.leastSignificantBits) return byteBufferWrapper.array() } diff --git a/src/main/kotlin/io/csbroker/apiserver/controller/v1/post/response/PostResponseDto.kt b/src/main/kotlin/io/csbroker/apiserver/controller/v1/post/response/PostResponseDto.kt index ae82fd6b..4cd7eb39 100644 --- a/src/main/kotlin/io/csbroker/apiserver/controller/v1/post/response/PostResponseDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/controller/v1/post/response/PostResponseDto.kt @@ -13,7 +13,7 @@ data class PostResponseDto( val comments: List, ) { constructor(post: Post, likeCount: Long, isLiked: Boolean, comments: List) : this( - id = post.id!!, + id = post.id, content = post.content, username = post.user.username, likeCount = likeCount, @@ -29,7 +29,7 @@ data class CommentResponseDto( val createdAt: LocalDateTime, ) { constructor(comment: Comment) : this( - id = comment.id!!, + id = comment.id, content = comment.content, username = comment.user.username, createdAt = comment.createdAt!!, diff --git a/src/main/kotlin/io/csbroker/apiserver/controller/v1/problem/ProblemController.kt b/src/main/kotlin/io/csbroker/apiserver/controller/v1/problem/ProblemController.kt index ae2b2c8b..da1f2cc4 100644 --- a/src/main/kotlin/io/csbroker/apiserver/controller/v1/problem/ProblemController.kt +++ b/src/main/kotlin/io/csbroker/apiserver/controller/v1/problem/ProblemController.kt @@ -35,13 +35,10 @@ class ProblemController( @RequestParam("page") page: Int, @RequestParam("size") size: Int, ): ApiResponse { - var solvedBy: String? = null - - if (isSolved != null) { - solvedBy = getEmailFromSecurityContextHolder() + val solvedBy = isSolved?.let { + getEmailFromSecurityContextHolder() ?: throw UnAuthorizedException(ErrorCode.FORBIDDEN, "사용자 권한이 없습니다.") } - val searchDto = ProblemSearchDto(tags, solvedBy, isSolved, query, type, isGradable, page, size) val foundProblems = commonProblemService.findProblems(searchDto) diff --git a/src/main/kotlin/io/csbroker/apiserver/controller/v2/problem/response/ShortProblemDetailResponseV2Dto.kt b/src/main/kotlin/io/csbroker/apiserver/controller/v2/problem/response/ShortProblemDetailResponseV2Dto.kt index b793cec6..d873d540 100644 --- a/src/main/kotlin/io/csbroker/apiserver/controller/v2/problem/response/ShortProblemDetailResponseV2Dto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/controller/v2/problem/response/ShortProblemDetailResponseV2Dto.kt @@ -1,6 +1,6 @@ package io.csbroker.apiserver.controller.v2.problem.response -class ShortProblemDetailResponseV2Dto( +data class ShortProblemDetailResponseV2Dto( val id: Long, val title: String, val tags: List, diff --git a/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/KeywordGradingRequestDto.kt b/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/KeywordGradingRequestDto.kt index e5e9c321..b46dd36f 100644 --- a/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/KeywordGradingRequestDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/KeywordGradingRequestDto.kt @@ -20,13 +20,13 @@ data class KeywordGradingRequestDto( companion object { fun createKeywordGradingRequestDto(problem: LongProblem, answer: String): KeywordGradingRequestDto { return KeywordGradingRequestDto( - problem.id!!, + problem.id, answer, problem.gradingStandards.filter { it.type == GradingStandardType.KEYWORD }.map { GradingKeyword( - it.id!!, + it.id, it.content, ) }, diff --git a/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/LongProblemGradingRequestToAiServerDto.kt b/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/LongProblemGradingRequestToAiServerDto.kt index 4e3e1399..dffb026f 100644 --- a/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/LongProblemGradingRequestToAiServerDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/dto/problem/grade/LongProblemGradingRequestToAiServerDto.kt @@ -27,13 +27,13 @@ data class LongProblemGradingRequestToAiServerDto( companion object { fun createGradingRequestDto(problem: LongProblem, answer: String): LongProblemGradingRequestToAiServerDto { return LongProblemGradingRequestToAiServerDto( - problem.id!!, + problem.id, answer, problem.gradingStandards.filter { it.type == GradingStandardType.KEYWORD }.map { GradingKeyword( - it.id!!, + it.id, it.content, ) }, @@ -41,7 +41,7 @@ data class LongProblemGradingRequestToAiServerDto( it.type == GradingStandardType.CONTENT }.map { GradingContent( - it.id!!, + it.id, it.content, ) }, diff --git a/src/main/kotlin/io/csbroker/apiserver/dto/problem/longproblem/LongProblemGradingHistoryDto.kt b/src/main/kotlin/io/csbroker/apiserver/dto/problem/longproblem/LongProblemGradingHistoryDto.kt index 116f85bc..23209554 100644 --- a/src/main/kotlin/io/csbroker/apiserver/dto/problem/longproblem/LongProblemGradingHistoryDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/dto/problem/longproblem/LongProblemGradingHistoryDto.kt @@ -41,7 +41,7 @@ data class LongProblemGradingHistoryDto( return LongProblemGradingHistoryDto( gradingHistoryId, - problem.id!!, + problem.id, problem.title, tags, problem.description, diff --git a/src/main/kotlin/io/csbroker/apiserver/dto/problem/multiplechoiceproblem/MultipleChoiceProblemGradingHistoryDto.kt b/src/main/kotlin/io/csbroker/apiserver/dto/problem/multiplechoiceproblem/MultipleChoiceProblemGradingHistoryDto.kt index 5dd630d2..8f2866be 100644 --- a/src/main/kotlin/io/csbroker/apiserver/dto/problem/multiplechoiceproblem/MultipleChoiceProblemGradingHistoryDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/dto/problem/multiplechoiceproblem/MultipleChoiceProblemGradingHistoryDto.kt @@ -30,14 +30,14 @@ data class MultipleChoiceProblemGradingHistoryDto( val choices = problem.choicesList.map { ChoiceResponseDto( - it.id!!, + it.id, it.content, ) } return MultipleChoiceProblemGradingHistoryDto( gradingHistoryId, - problem.id!!, + problem.id, problem.title, commonDetail.tags, problem.description, diff --git a/src/main/kotlin/io/csbroker/apiserver/dto/problem/shortproblem/ShortProblemGradingHistoryDto.kt b/src/main/kotlin/io/csbroker/apiserver/dto/problem/shortproblem/ShortProblemGradingHistoryDto.kt index b26a0b87..5d42a47b 100644 --- a/src/main/kotlin/io/csbroker/apiserver/dto/problem/shortproblem/ShortProblemGradingHistoryDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/dto/problem/shortproblem/ShortProblemGradingHistoryDto.kt @@ -31,7 +31,7 @@ data class ShortProblemGradingHistoryDto( return ShortProblemGradingHistoryDto( gradingHistoryId, - problem.id!!, + problem.id, problem.title, commonDetail.tags, problem.description, diff --git a/src/main/kotlin/io/csbroker/apiserver/dto/user/GradingStandardResponseDto.kt b/src/main/kotlin/io/csbroker/apiserver/dto/user/GradingStandardResponseDto.kt index f1ff4e38..7b44a264 100644 --- a/src/main/kotlin/io/csbroker/apiserver/dto/user/GradingStandardResponseDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/dto/user/GradingStandardResponseDto.kt @@ -12,7 +12,7 @@ data class GradingStandardResponseDto( companion object { fun fromGradingStandard(gradingStandard: GradingStandard): GradingStandardResponseDto { return GradingStandardResponseDto( - id = gradingStandard.id!!, + id = gradingStandard.id, content = gradingStandard.content, score = gradingStandard.score, type = gradingStandard.type, diff --git a/src/main/kotlin/io/csbroker/apiserver/dto/useranswer/UserAnswerResponseDto.kt b/src/main/kotlin/io/csbroker/apiserver/dto/useranswer/UserAnswerResponseDto.kt index 1998ebf4..f591093b 100644 --- a/src/main/kotlin/io/csbroker/apiserver/dto/useranswer/UserAnswerResponseDto.kt +++ b/src/main/kotlin/io/csbroker/apiserver/dto/useranswer/UserAnswerResponseDto.kt @@ -27,12 +27,12 @@ data class UserAnswerResponseDto( .map { GradingStandardResponseDto.fromGradingStandard(it) } val selectedGradingStandards = userAnswer.userAnswerGradingStandards.map { - it.gradingStandard.id!! + it.gradingStandard.id } return UserAnswerResponseDto( - userAnswer.id!!, - userAnswer.problem.id!!, + userAnswer.id, + userAnswer.problem.id, userAnswer.problem.title, userAnswer.problem.description, userAnswer.answer, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Challenge.kt b/src/main/kotlin/io/csbroker/apiserver/model/Challenge.kt index c165f56f..c233e13e 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Challenge.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Challenge.kt @@ -16,7 +16,7 @@ class Challenge( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "challenge_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "problem_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/ChatResult.kt b/src/main/kotlin/io/csbroker/apiserver/model/ChatResult.kt index 53fa888c..6fcee1b7 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/ChatResult.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/ChatResult.kt @@ -13,7 +13,7 @@ class ChatResult( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "chat_result_id") - val id: Long? = null, + val id: Long = 0, // 연관관계로 엮을 수 있으나, 단순 데이터 저장용이기 때문에.. 굳이 엮지 않겠음. @Column(name = "email") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Choice.kt b/src/main/kotlin/io/csbroker/apiserver/model/Choice.kt index 08d620b6..e78f930f 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Choice.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Choice.kt @@ -17,7 +17,7 @@ class Choice( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "choice_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "content") var content: String, @@ -31,7 +31,7 @@ class Choice( ) { fun toChoiceResponseDto(): ChoiceResponseDto { return ChoiceResponseDto( - id!!, + id, content, ) } diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Comment.kt b/src/main/kotlin/io/csbroker/apiserver/model/Comment.kt index a8b3bce9..e86330b8 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Comment.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Comment.kt @@ -16,7 +16,7 @@ class Comment( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "comment_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "post_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/GradingHistory.kt b/src/main/kotlin/io/csbroker/apiserver/model/GradingHistory.kt index 7daf1630..413ffe03 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/GradingHistory.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/GradingHistory.kt @@ -17,7 +17,7 @@ class GradingHistory( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "grading_history_id") - val gradingHistoryId: Long? = null, + val gradingHistoryId: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "problem_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/GradingResultAssessment.kt b/src/main/kotlin/io/csbroker/apiserver/model/GradingResultAssessment.kt index dd5ba0e8..7a985624 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/GradingResultAssessment.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/GradingResultAssessment.kt @@ -18,7 +18,7 @@ class GradingResultAssessment( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "grading_result_assessment_id") - val id: Long? = null, + val id: Long = 0, @OneToOne(mappedBy = "gradingResultAssessment", fetch = FetchType.LAZY) val gradingHistory: GradingHistory, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/GradingStandard.kt b/src/main/kotlin/io/csbroker/apiserver/model/GradingStandard.kt index 39418fc2..5ddc5962 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/GradingStandard.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/GradingStandard.kt @@ -21,7 +21,7 @@ class GradingStandard( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "grading_standard_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "content") var content: String, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/LongProblem.kt b/src/main/kotlin/io/csbroker/apiserver/model/LongProblem.kt index e28f54ed..3180d6fb 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/LongProblem.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/LongProblem.kt @@ -49,7 +49,7 @@ class LongProblem( fun toLongProblemResponseDto(): LongProblemResponseDto { return LongProblemResponseDto( - id!!, + id, title, description, standardAnswers.map { it.content }, @@ -70,7 +70,7 @@ class LongProblem( } return LongProblemDataDto( - id!!, + id, title, creator.username, if (keywordScores.isEmpty()) null else keywordScores.average(), @@ -94,7 +94,7 @@ class LongProblem( val isSolved = gradingHistory.any { it.user.email == email } return LongProblemDetailResponseDto( - id!!, + id, title, tags, description, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Major.kt b/src/main/kotlin/io/csbroker/apiserver/model/Major.kt index f114cfc3..b4c380e7 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Major.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Major.kt @@ -13,7 +13,7 @@ class Major( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "major_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "major_name", columnDefinition = "VARCHAR(100)") val name: String, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/MultipleChoiceProblem.kt b/src/main/kotlin/io/csbroker/apiserver/model/MultipleChoiceProblem.kt index 400db0aa..197acbb9 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/MultipleChoiceProblem.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/MultipleChoiceProblem.kt @@ -49,7 +49,7 @@ class MultipleChoiceProblem( fun toMultipleChoiceProblemResponseDto(): MultipleChoiceProblemResponseDto { return MultipleChoiceProblemResponseDto( - id!!, + id, title, description, problemTags.map { @@ -75,7 +75,7 @@ class MultipleChoiceProblem( } return MultipleChoiceProblemSearchResponseDto.MultipleChoiceProblemDataDto( - id!!, + id, title, creator.username, if (answerCnt == 0) null else correctAnswerCnt / answerCnt.toDouble(), @@ -88,7 +88,7 @@ class MultipleChoiceProblem( val commonDetail = ProblemCommonDetailResponse.getCommonDetail(this) return MultipleChoiceProblemDetailResponseDto( - id!!, + id, title, commonDetail.tags, description, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Notification.kt b/src/main/kotlin/io/csbroker/apiserver/model/Notification.kt index f84b2060..29bf296b 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Notification.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Notification.kt @@ -22,7 +22,7 @@ class Notification( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "notification_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "content", columnDefinition = "VARCHAR(100)") val content: String, @@ -48,7 +48,7 @@ class Notification( fun toNotificationResponseDto(): NotificationResponseDto { return NotificationResponseDto( - id!!, + id, content, link, isRead, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Post.kt b/src/main/kotlin/io/csbroker/apiserver/model/Post.kt index fe046ab5..d2aabe92 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Post.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Post.kt @@ -16,7 +16,7 @@ class Post( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "post_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "problem_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/PostLike.kt b/src/main/kotlin/io/csbroker/apiserver/model/PostLike.kt index 273e77c1..370d48cd 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/PostLike.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/PostLike.kt @@ -16,7 +16,7 @@ class PostLike( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "post_like_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "post_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Problem.kt b/src/main/kotlin/io/csbroker/apiserver/model/Problem.kt index 6c40202d..1a88fa69 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Problem.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Problem.kt @@ -25,7 +25,7 @@ abstract class Problem( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "problem_id") - var id: Long? = null, + var id: Long = 0, @Column(name = "problem_title", columnDefinition = "VARCHAR(50)") var title: String, @@ -72,7 +72,7 @@ abstract class Problem( } return ProblemResponseDto( - id!!, + id, title, tags, gradingHistoryStats?.avgScore, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/ProblemBookmark.kt b/src/main/kotlin/io/csbroker/apiserver/model/ProblemBookmark.kt index 9aba31a0..1d442a75 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/ProblemBookmark.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/ProblemBookmark.kt @@ -16,7 +16,7 @@ class ProblemBookmark( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "problem_bookmark_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "problem_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/ProblemLike.kt b/src/main/kotlin/io/csbroker/apiserver/model/ProblemLike.kt index 80799b03..642b8b8b 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/ProblemLike.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/ProblemLike.kt @@ -16,7 +16,7 @@ class ProblemLike( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "problem_like_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "problem_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/ProblemSet.kt b/src/main/kotlin/io/csbroker/apiserver/model/ProblemSet.kt index ba5fcb05..a5d7d70e 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/ProblemSet.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/ProblemSet.kt @@ -17,7 +17,7 @@ class ProblemSet( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "problem_set_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "problem_set_name") var name: String, @@ -30,7 +30,7 @@ class ProblemSet( ) { fun toProblemSetResponseDto(): ProblemSetResponseDto { return ProblemSetResponseDto( - id!!, + id, problemSetMapping.size, name, description, @@ -39,7 +39,7 @@ class ProblemSet( fun toProblemSetDetailResponseDto(): ProblemSetDetailResponseDto { return ProblemSetDetailResponseDto( - id!!, + id, problemSetMapping.map { it.problem.toProblemResponseDto(GradingHistoryStats.toGradingHistoryStats(it.problem.gradingHistory)) }, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/ProblemSetMapping.kt b/src/main/kotlin/io/csbroker/apiserver/model/ProblemSetMapping.kt index 4a7c3b44..f1bc9653 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/ProblemSetMapping.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/ProblemSetMapping.kt @@ -16,7 +16,7 @@ class ProblemSetMapping( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "problem_set_mapping_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "problem_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/ProblemTag.kt b/src/main/kotlin/io/csbroker/apiserver/model/ProblemTag.kt index d3e1cd3a..ba2c86c0 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/ProblemTag.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/ProblemTag.kt @@ -16,7 +16,7 @@ class ProblemTag( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "problem_tag_id") - val id: Long? = null, + val id: Long = 0, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "problem_id") diff --git a/src/main/kotlin/io/csbroker/apiserver/model/ShortProblem.kt b/src/main/kotlin/io/csbroker/apiserver/model/ShortProblem.kt index 09e95df5..a49859d7 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/ShortProblem.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/ShortProblem.kt @@ -37,7 +37,7 @@ class ShortProblem( fun toShortProblemResponseDto(): ShortProblemResponseDto { return ShortProblemResponseDto( - id!!, + id, title, description, problemTags.map { it.tag.name }, @@ -55,7 +55,7 @@ class ShortProblem( } return ShortProblemSearchResponseDto.ShortProblemDataDto( - id!!, + id, title, creator.username, if (answerCnt == 0) null else correctAnswerCnt / answerCnt.toDouble(), @@ -68,7 +68,7 @@ class ShortProblem( val commonDetail = ProblemCommonDetailResponse.getCommonDetail(this) return ShortProblemDetailResponseDto( - id!!, + id, title, commonDetail.tags, description, @@ -90,7 +90,7 @@ class ShortProblem( val commonDetail = ProblemCommonDetailResponse.getCommonDetail(this) return ShortProblemDetailResponseV2Dto( - id!!, + id, title, commonDetail.tags, description, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/StandardAnswer.kt b/src/main/kotlin/io/csbroker/apiserver/model/StandardAnswer.kt index 136232e6..d7d6d0c4 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/StandardAnswer.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/StandardAnswer.kt @@ -16,7 +16,7 @@ class StandardAnswer( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "standard_answer_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "content", columnDefinition = "LONGTEXT") var content: String, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Tag.kt b/src/main/kotlin/io/csbroker/apiserver/model/Tag.kt index a5ca99e1..ae32a839 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Tag.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Tag.kt @@ -14,7 +14,7 @@ class Tag( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "tag_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "tag_name", columnDefinition = "VARCHAR(30)") val name: String, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/Tech.kt b/src/main/kotlin/io/csbroker/apiserver/model/Tech.kt index 1257498d..66158881 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/Tech.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/Tech.kt @@ -13,7 +13,7 @@ class Tech( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "tech_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "tech_name", columnDefinition = "VARCHAR(100)") val name: String, diff --git a/src/main/kotlin/io/csbroker/apiserver/model/UserAnswer.kt b/src/main/kotlin/io/csbroker/apiserver/model/UserAnswer.kt index d82792f0..78ff6df3 100644 --- a/src/main/kotlin/io/csbroker/apiserver/model/UserAnswer.kt +++ b/src/main/kotlin/io/csbroker/apiserver/model/UserAnswer.kt @@ -20,7 +20,7 @@ class UserAnswer( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_answer_id") - val id: Long? = null, + val id: Long = 0, @Column(name = "answer", columnDefinition = "VARCHAR(300)") val answer: String, @@ -68,7 +68,7 @@ class UserAnswer( fun toUserAnswerDataDto(): UserAnswerDataDto { return UserAnswerDataDto( - id!!, + id, problem.title, assignedUser?.username, validatingUser?.username, diff --git a/src/main/kotlin/io/csbroker/apiserver/repository/common/OAuth2AuthorizationRequestBasedOnCookieRepository.kt b/src/main/kotlin/io/csbroker/apiserver/repository/common/OAuth2AuthorizationRequestBasedOnCookieRepository.kt index 04dc1139..60dab9d9 100644 --- a/src/main/kotlin/io/csbroker/apiserver/repository/common/OAuth2AuthorizationRequestBasedOnCookieRepository.kt +++ b/src/main/kotlin/io/csbroker/apiserver/repository/common/OAuth2AuthorizationRequestBasedOnCookieRepository.kt @@ -37,7 +37,7 @@ class OAuth2AuthorizationRequestBasedOnCookieRepository : AuthorizationRequestRe addCookie( response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME, - serialize(authorizationRequest), + authorizationRequest.serialize(), COOKIE_EXPIRE_SECONDS, ) diff --git a/src/main/kotlin/io/csbroker/apiserver/repository/problem/ProblemRepositoryCustomImpl.kt b/src/main/kotlin/io/csbroker/apiserver/repository/problem/ProblemRepositoryCustomImpl.kt index 315a2dad..0e10cfd2 100644 --- a/src/main/kotlin/io/csbroker/apiserver/repository/problem/ProblemRepositoryCustomImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/repository/problem/ProblemRepositoryCustomImpl.kt @@ -73,7 +73,7 @@ class ProblemRepositoryCustomImpl( override fun getProblemIdToStatMap(problems: List): Map = getGradingHistoriesRelatedProblems(problems) .groupBy { - it.problem.id!! + it.problem.id }.map { it.key to GradingHistoryStats.toGradingHistoryStats(it.value) }.toMap() diff --git a/src/main/kotlin/io/csbroker/apiserver/repository/problem/UserAnswerRepositoryCustomImpl.kt b/src/main/kotlin/io/csbroker/apiserver/repository/problem/UserAnswerRepositoryCustomImpl.kt index 2c2dc87e..3403d441 100644 --- a/src/main/kotlin/io/csbroker/apiserver/repository/problem/UserAnswerRepositoryCustomImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/repository/problem/UserAnswerRepositoryCustomImpl.kt @@ -2,7 +2,7 @@ package io.csbroker.apiserver.repository.problem import com.querydsl.core.types.dsl.BooleanExpression import com.querydsl.jpa.impl.JPAQueryFactory -import io.csbroker.apiserver.common.util.uuidAsByte +import io.csbroker.apiserver.common.util.asByte import io.csbroker.apiserver.dto.useranswer.UserAnswerUpsertDto import io.csbroker.apiserver.model.QLongProblem.longProblem import io.csbroker.apiserver.model.QUser.user @@ -37,9 +37,9 @@ class UserAnswerRepositoryCustomImpl( ps.setString(1, userAnswer.answer) ps.setBoolean(2, false) ps.setBoolean(3, false) - ps.setBytes(4, uuidAsByte(userAnswer.assignedUserId)) + ps.setBytes(4, userAnswer.assignedUserId?.asByte()) ps.setLong(5, userAnswer.problemId) - ps.setBytes(6, uuidAsByte(userAnswer.validatingUserId)) + ps.setBytes(6, userAnswer.assignedUserId?.asByte()) ps.setTimestamp(7, Timestamp.valueOf(LocalDateTime.now())) ps.setTimestamp(8, Timestamp.valueOf(LocalDateTime.now())) } diff --git a/src/main/kotlin/io/csbroker/apiserver/service/auth/AuthServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/auth/AuthServiceImpl.kt index 420e43ac..8902af45 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/auth/AuthServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/auth/AuthServiceImpl.kt @@ -94,7 +94,7 @@ class AuthServiceImpl( } override fun refreshUserToken(request: HttpServletRequest): TokenDto { - val accessToken = getAccessToken(request) + val accessToken = request.getAccessToken() ?: throw UnAuthorizedException(ErrorCode.ACCESS_TOKEN_NOT_EXIST, "Access Token이 존재하지 않습니다.") val convertAccessToken = authTokenProvider.convertAuthToken(accessToken) diff --git a/src/main/kotlin/io/csbroker/apiserver/service/auth/CustomOAuth2UserService.kt b/src/main/kotlin/io/csbroker/apiserver/service/auth/CustomOAuth2UserService.kt index c08a4576..b1312431 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/auth/CustomOAuth2UserService.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/auth/CustomOAuth2UserService.kt @@ -64,19 +64,19 @@ class CustomOAuth2UserService( attributes: MutableMap, ): User { val userInfo = OAuth2UserInfoFactory.getOauth2UserInfo(providerType, attributes) - val savedUser = userRepository.findByEmail(userInfo.getEmail()) - ?: userRepository.findUserByProviderId(userInfo.getId()) + val savedUser = userRepository.findByEmail(userInfo.email) + ?: userRepository.findUserByProviderId(userInfo.id) return savedUser ?: createUser(userInfo, providerType) } private fun createUser(userInfo: OAuth2UserInfo, providerType: ProviderType): User { val user = User( - email = userInfo.getEmail(), - username = userInfo.getName(), + email = userInfo.email, + username = userInfo.name, providerType = providerType, - profileImageUrl = userInfo.getImageUrl(), - providerId = userInfo.getId(), + profileImageUrl = userInfo.imageUrl, + providerId = userInfo.id, ) return userRepository.saveAndFlush(user) diff --git a/src/main/kotlin/io/csbroker/apiserver/service/common/NotificationServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/common/NotificationServiceImpl.kt index 31c2fcda..b42c605a 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/common/NotificationServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/common/NotificationServiceImpl.kt @@ -23,7 +23,7 @@ class NotificationServiceImpl( val notification = Notification(notificationRequestDto, findUser) - return notificationRepository.save(notification).id!! + return notificationRepository.save(notification).id } @Transactional diff --git a/src/main/kotlin/io/csbroker/apiserver/service/post/CommentServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/post/CommentServiceImpl.kt index d9d7751a..e9f4dcb2 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/post/CommentServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/post/CommentServiceImpl.kt @@ -25,7 +25,7 @@ class CommentServiceImpl( "${postId}번 답변은 존재하지 않는 답변입니다", ) val comment = commentRepository.save(Comment(content = content, post = post, user = user)) - return comment.id!! + return comment.id } @Transactional diff --git a/src/main/kotlin/io/csbroker/apiserver/service/post/PostServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/post/PostServiceImpl.kt index d8439328..a23111f7 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/post/PostServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/post/PostServiceImpl.kt @@ -53,7 +53,7 @@ class PostServiceImpl( "${problemId}번 문제는 존재하지 않는 문제입니다", ) val post = postRepository.save(Post(content = content, problem = problem, user = user)) - return post.id!! + return post.id } @Transactional diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/CommonProblemServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/CommonProblemServiceImpl.kt index 2474f67f..09e4c746 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/CommonProblemServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/CommonProblemServiceImpl.kt @@ -87,7 +87,7 @@ class CommonProblemServiceImpl( gradingHistory.gradingResultAssessment = gradingResultAssessment - return gradingResultAssessment.id!! + return gradingResultAssessment.id } @Transactional diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/LongProblemServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/LongProblemServiceImpl.kt index 2a48e27c..4b78d771 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/LongProblemServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/LongProblemServiceImpl.kt @@ -65,7 +65,7 @@ class LongProblemServiceImpl( // get keywords val correctKeywordListDto = gradeResultDto.correctKeywordIds.map { - val keyword = findProblem.gradingStandards.find { gs -> gs.id!! == it } + val keyword = findProblem.gradingStandards.find { gs -> gs.id == it } ?: throw EntityNotFoundException("${it}번 채점 기준을 찾을 수 없습니다.") if (keyword.type != GradingStandardType.KEYWORD) { throw InternalServiceException( @@ -75,7 +75,7 @@ class LongProblemServiceImpl( } userGradedScore += keyword.score KeywordDto( - keyword.id!!, + keyword.id, keyword.content, true, gradeResultDto.predictKeywordPositions[it] @@ -86,7 +86,7 @@ class LongProblemServiceImpl( val notCorrectKeywordListDto = findProblem.gradingStandards.filter { it.type == GradingStandardType.KEYWORD && it.id !in gradeResultDto.correctKeywordIds }.map { - KeywordDto(it.id!!, it.content) + KeywordDto(it.id, it.content) }.toList() // get score from content standards @@ -100,13 +100,13 @@ class LongProblemServiceImpl( ) } userGradedScore += it.score - ContentDto(it.id!!, it.content, true) + ContentDto(it.id, it.content, true) } val notCorrectContentListDto = findProblem.gradingStandards.filter { it.type == GradingStandardType.CONTENT && it.id !in gradeResultDto.correctContentIds }.map { - ContentDto(it.id!!, it.content) + ContentDto(it.id, it.content) }.toList() if (correctContentListDto.size != gradeResultDto.correctContentIds.size) { @@ -130,7 +130,7 @@ class LongProblemServiceImpl( // create dto return LongProblemGradingHistoryDto.createDto( - gradingHistoryId = gradingHistory.gradingHistoryId!!, + gradingHistoryId = gradingHistory.gradingHistoryId, problem = findProblem, userAnswer = answer, score = userGradedScore, diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceImpl.kt index cda304a2..3692ee23 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceImpl.kt @@ -40,7 +40,7 @@ class MultipleProblemServiceImpl( val correctAnswer = findProblem.choicesList.filter { it.isAnswer }.map { - it.id!! + it.id } val isAnswer = correctAnswer.size == answerIds.size && correctAnswer.containsAll(answerIds) @@ -58,7 +58,7 @@ class MultipleProblemServiceImpl( // create dto return MultipleChoiceProblemGradingHistoryDto.createDto( - gradingHistoryId = gradingHistory.gradingHistoryId!!, + gradingHistoryId = gradingHistory.gradingHistoryId, problem = findProblem, userAnswerIds = answerIds, score = score, diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/ProblemSetServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/ProblemSetServiceImpl.kt index a2093ce3..764f96b9 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/ProblemSetServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/ProblemSetServiceImpl.kt @@ -31,16 +31,16 @@ class ProblemSetServiceImpl( override fun createProblemSet(problemSetUpsertRequestDto: ProblemSetUpsertRequestDto): Long { val problemSet = problemSetRepository.save(problemSetUpsertRequestDto.toProblemSet()) createProblemSetMapping(problemSetUpsertRequestDto.problemIds, problemSet) - return problemSet.id!! + return problemSet.id } @Transactional override fun updateProblemSet(id: Long, problemSetUpsertRequestDto: ProblemSetUpsertRequestDto): Long { val problemSet = findById(id) problemSet.updateContents(problemSetUpsertRequestDto.name, problemSetUpsertRequestDto.description) - problemSetMappingRepository.deleteAllByProblemSetId(problemSet.id!!) + problemSetMappingRepository.deleteAllByProblemSetId(problemSet.id) createProblemSetMapping(problemSetUpsertRequestDto.problemIds, problemSet) - return problemSet.id!! + return problemSet.id } private fun createProblemSetMapping( diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceImpl.kt index 01214b7c..6d8cd66c 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceImpl.kt @@ -51,7 +51,7 @@ class ShortProblemServiceImpl( // create dto return ShortProblemGradingHistoryDto.createDto( - gradingHistoryId = gradingHistory.gradingHistoryId!!, + gradingHistoryId = gradingHistory.gradingHistoryId, problem = findProblem, userAnswer = answer, score = score, diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceImpl.kt index c584d5ff..e21cccd3 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceImpl.kt @@ -56,7 +56,7 @@ class UserAnswerServiceImpl( validatingUser = validatingUser, ) - return userAnswerRepository.save(createUserAnswer).id!! + return userAnswerRepository.save(createUserAnswer).id } override fun findUserAnswerById(id: Long): UserAnswerResponseDto { diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminLongProblemServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminLongProblemServiceImpl.kt index b9247711..205b7e8b 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminLongProblemServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminLongProblemServiceImpl.kt @@ -63,7 +63,7 @@ class AdminLongProblemServiceImpl( }, ) - return savedProblem.id!! + return savedProblem.id } @Transactional diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminMultipleProblemServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminMultipleProblemServiceImpl.kt index 2c081697..f5864464 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminMultipleProblemServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminMultipleProblemServiceImpl.kt @@ -58,7 +58,7 @@ class AdminMultipleProblemServiceImpl( multipleChoiceProblem.addChoices(choiceDataList) - return problemRepository.save(multipleChoiceProblem).id!! + return problemRepository.save(multipleChoiceProblem).id } @Transactional diff --git a/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminShortProblemServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminShortProblemServiceImpl.kt index 67078fbf..1a7811eb 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminShortProblemServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/problem/admin/AdminShortProblemServiceImpl.kt @@ -46,7 +46,7 @@ class AdminShortProblemServiceImpl( tagUpserter.setTags(shortProblem, createRequestDto.tags) - return problemRepository.save(shortProblem).id!! + return problemRepository.save(shortProblem).id } @Transactional diff --git a/src/main/kotlin/io/csbroker/apiserver/service/user/UserServiceImpl.kt b/src/main/kotlin/io/csbroker/apiserver/service/user/UserServiceImpl.kt index 4b1ec13f..5ae0f178 100644 --- a/src/main/kotlin/io/csbroker/apiserver/service/user/UserServiceImpl.kt +++ b/src/main/kotlin/io/csbroker/apiserver/service/user/UserServiceImpl.kt @@ -77,7 +77,7 @@ class UserServiceImpl( val gradingHistories = gradingHistoryRepository.findGradingHistoriesByUserId(findUser.id!!) val resultMap = gradingHistories.groupBy { - it.problem.id!! + it.problem.id }.mapValues { v -> v.value.maxByOrNull { it.score } ?: v.value.first() } @@ -148,7 +148,7 @@ class UserServiceImpl( override fun calculateRank() { val userScoreMap = userRepository.findAll().associate { val scoreMap = it.gradingHistories.groupBy { gradingHistory -> - gradingHistory.problem.id!! + gradingHistory.problem.id }.mapValues { map -> map.value.maxOfOrNull { gradingHistory -> gradingHistory.score } ?: 0.0 } diff --git a/src/test/kotlin/io/csbroker/apiserver/controller/IntegrationTest.kt b/src/test/kotlin/io/csbroker/apiserver/controller/IntegrationTest.kt index b61f0d2d..08cfad10 100644 --- a/src/test/kotlin/io/csbroker/apiserver/controller/IntegrationTest.kt +++ b/src/test/kotlin/io/csbroker/apiserver/controller/IntegrationTest.kt @@ -65,6 +65,7 @@ class IntegrationTest { entity } + @Suppress("UNCHECKED_CAST") fun findOne( @Language("JPAQL") qlString: String, params: Map = emptyMap(), @@ -74,6 +75,7 @@ class IntegrationTest { query.singleResult as T } + @Suppress("UNCHECKED_CAST") fun findAll( @Language("JPAQL") qlString: String, params: Map = emptyMap(), diff --git a/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemControllerIntegrationTest.kt b/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemControllerIntegrationTest.kt index f3e859b3..ac84403b 100644 --- a/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemControllerIntegrationTest.kt +++ b/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemControllerIntegrationTest.kt @@ -41,7 +41,7 @@ class AdminProblemControllerIntegrationTest : IntegrationTest() { // then response.andExpect(status().isOk) .andExpect { - val problems = findAll("SELECT p FROM Problem p where p.id = :id", mapOf("id" to problem.id!!)) + val problems = findAll("SELECT p FROM Problem p where p.id = :id", mapOf("id" to problem.id)) problems.size shouldBe 0 } } @@ -78,7 +78,7 @@ class AdminProblemControllerIntegrationTest : IntegrationTest() { url = "/api/admin/problems", isAdmin = true, body = ProblemDeleteRequestDto( - ids = listOf(problem1.id!!, problem2.id!!), + ids = listOf(problem1.id, problem2.id), ), ) @@ -87,7 +87,7 @@ class AdminProblemControllerIntegrationTest : IntegrationTest() { .andExpect { val problems = findAll( "SELECT p FROM Problem p where p.id in :ids", - mapOf("ids" to listOf(problem1.id!!, problem2.id!!)), + mapOf("ids" to listOf(problem1.id, problem2.id)), ) problems.size shouldBe 0 } diff --git a/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemSetControllerIntegrationTest.kt b/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemSetControllerIntegrationTest.kt index c1eec980..d05280ed 100644 --- a/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemSetControllerIntegrationTest.kt +++ b/src/test/kotlin/io/csbroker/apiserver/controller/v1/admin/problem/AdminProblemSetControllerIntegrationTest.kt @@ -49,7 +49,7 @@ class AdminProblemSetControllerIntegrationTest : IntegrationTest() { val response = request( method = HttpMethod.POST, url = "/api/admin/problem-sets", - body = ProblemSetUpsertRequestDto(listOf(longProblem.id!!, shortProblem.id!!), "name", "description"), + body = ProblemSetUpsertRequestDto(listOf(longProblem.id, shortProblem.id), "name", "description"), isAdmin = true, ) @@ -125,7 +125,7 @@ class AdminProblemSetControllerIntegrationTest : IntegrationTest() { val response = request( method = HttpMethod.PUT, url = "/api/admin/problem-sets/${problemSet.id}", - body = ProblemSetUpsertRequestDto(listOf(multipleChoiceProblem.id!!), "name", "description"), + body = ProblemSetUpsertRequestDto(listOf(multipleChoiceProblem.id), "name", "description"), isAdmin = true, ) diff --git a/src/test/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceTest.kt b/src/test/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceTest.kt index 3cd74802..d56ac4ae 100644 --- a/src/test/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceTest.kt +++ b/src/test/kotlin/io/csbroker/apiserver/service/problem/MultipleProblemServiceTest.kt @@ -101,8 +101,8 @@ class MultipleProblemServiceTest { // given val email = user.email val problem = createProblem() - val problemId = problem.id!! - val answerId = problem.choicesList.find { it.isAnswer }?.id!! + val problemId = problem.id + val answerId = problem.choicesList.first { it.isAnswer }.id val answerIds = listOf(answerId) val gradingRequest = MultipleProblemGradingRequestDto(email, problemId, answerIds) val gradingHistory = GradingHistory( @@ -126,8 +126,8 @@ class MultipleProblemServiceTest { // given val email = user.email val problem = createProblem() - val problemId = problem.id!! - val answerId = problem.choicesList.find { !it.isAnswer }?.id!! + val problemId = problem.id + val answerId = problem.choicesList.first { !it.isAnswer }.id val answerIds = listOf(answerId) val gradingRequest = MultipleProblemGradingRequestDto(email, problemId, answerIds) val gradingHistory = GradingHistory( diff --git a/src/test/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceTest.kt b/src/test/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceTest.kt index c1bbfde9..88cb9d68 100644 --- a/src/test/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceTest.kt +++ b/src/test/kotlin/io/csbroker/apiserver/service/problem/ShortProblemServiceTest.kt @@ -96,7 +96,7 @@ class ShortProblemServiceTest { val problem = createProblem() val gradingRequest = ShortProblemGradingRequestDto( user.email, - problem.id!!, + problem.id, problem.answer, ) val gradingHistory = GradingHistory( @@ -107,7 +107,7 @@ class ShortProblemServiceTest { score = problem.score, ) every { userRepository.findByEmail(user.email) } returns user - every { shortProblemRepository.findByIdOrNull(problem.id!!) } returns problem + every { shortProblemRepository.findByIdOrNull(problem.id) } returns problem every { gradingHistoryRepository.save(any()) } returns gradingHistory // when @@ -116,7 +116,7 @@ class ShortProblemServiceTest { // then assertEquals(problem.score, result.score) verify { userRepository.findByEmail(user.email) } - verify { shortProblemRepository.findByIdOrNull(problem.id!!) } + verify { shortProblemRepository.findByIdOrNull(problem.id) } verify { gradingHistoryRepository.save(any()) } } @@ -127,7 +127,7 @@ class ShortProblemServiceTest { val wrongAnswer = "wrongAnswer" val gradingRequest = ShortProblemGradingRequestDto( user.email, - problem.id!!, + problem.id, wrongAnswer, ) val gradingHistory = GradingHistory( @@ -138,7 +138,7 @@ class ShortProblemServiceTest { score = 10.0, ) every { userRepository.findByEmail(user.email) } returns user - every { shortProblemRepository.findByIdOrNull(problem.id!!) } returns problem + every { shortProblemRepository.findByIdOrNull(problem.id) } returns problem every { gradingHistoryRepository.save(any()) } returns gradingHistory // when val result = service.gradingProblem(gradingRequest) @@ -146,7 +146,7 @@ class ShortProblemServiceTest { // then assertEquals(0.0, result.score) verify { userRepository.findByEmail(user.email) } - verify { shortProblemRepository.findByIdOrNull(problem.id!!) } + verify { shortProblemRepository.findByIdOrNull(problem.id) } verify { gradingHistoryRepository.save(any()) } } diff --git a/src/test/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceTest.kt b/src/test/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceTest.kt index 969deeb6..04e0d8b7 100644 --- a/src/test/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceTest.kt +++ b/src/test/kotlin/io/csbroker/apiserver/service/problem/UserAnswerServiceTest.kt @@ -86,7 +86,7 @@ class UserAnswerServiceTest { @Test fun `createUserAnswer - 존재하지 않는 유저가 담당자로 등록되면 예외가 발생합니다 `() { // given - val problemId = problem.id!! + val problemId = problem.id val notExistUserId = UUID.randomUUID() val requestDto = UserAnswerUpsertDto( assignedUserId = notExistUserId, @@ -106,7 +106,7 @@ class UserAnswerServiceTest { @Test fun `createUserAnswer - 존재하지 않는 유저가 검수자로 등록되면 예외가 발생합니다 `() { // given - val problemId = problem.id!! + val problemId = problem.id val notExistUserId = UUID.randomUUID() val requestDto = UserAnswerUpsertDto( assignedUserId = assignee.id!!, @@ -128,7 +128,7 @@ class UserAnswerServiceTest { @Test fun `createUserAnswer - success`() { // given - val problemId = problem.id!! + val problemId = problem.id val answer = "answer" val requestDto = UserAnswerUpsertDto( assignedUserId = assignee.id!!, @@ -187,7 +187,7 @@ class UserAnswerServiceTest { fun `labelUserAnswer - 담당자가 존재하지 않는 답안은 라벨링을 할 수 없습니다`() { // given val anotherUserEmail = "another@email.com" - val userAnswerId = userAnswer.id!! + val userAnswerId = userAnswer.id userAnswer.assignedUser = null val selectedGradingStandardIds = listOf(1L, 2L, 3L) every { userAnswerRepository.findByIdOrNull(userAnswerId) } returns userAnswer @@ -203,7 +203,7 @@ class UserAnswerServiceTest { fun `labelUserAnswer - 담당자가 아닌 유저가 라벨링을 진행할 시 예외가 발생합니다`() { // given val anotherUserEmail = "another@email.com" - val userAnswerId = userAnswer.id!! + val userAnswerId = userAnswer.id val selectedGradingStandardIds = listOf(1L, 2L, 3L) every { userAnswerRepository.findByIdOrNull(userAnswerId) } returns userAnswer @@ -217,7 +217,7 @@ class UserAnswerServiceTest { @Test fun `labelUserAnswer - 존재하지 않는 채점기준이 존재하면 예외가 발생합니다`() { // given - val userAnswerId = userAnswer.id!! + val userAnswerId = userAnswer.id val selectedGradingStandardIds = listOf(1L, 2L, 3L) every { userAnswerRepository.findByIdOrNull(userAnswerId) } returns userAnswer @@ -234,7 +234,7 @@ class UserAnswerServiceTest { @Test fun `labelUserAnswer - 라벨링이 완료되면 완료 표식을 남깁니다`() { // given - val userAnswerId = userAnswer.id!! + val userAnswerId = userAnswer.id val selectedGradingStandardIds = listOf(1L, 2L, 3L) every { userAnswerRepository.findByIdOrNull(userAnswerId) } returns userAnswer