-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: add querydsl and extension function
- Loading branch information
1 parent
39addf5
commit 5ad5fb4
Showing
7 changed files
with
152 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
src/main/kotlin/com/hero/alignlab/domain/user/model/response/UserInfoResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
package com.hero.alignlab.domain.user.model.response | ||
|
||
import com.hero.alignlab.domain.user.domain.UserInfo | ||
|
||
data class UserInfoResponse( | ||
val uid: Long, | ||
val nickname: String, | ||
) | ||
) { | ||
companion object { | ||
fun from(user: UserInfo): UserInfoResponse { | ||
return UserInfoResponse( | ||
uid = user.id, | ||
nickname = user.nickname | ||
) | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/kotlin/com/hero/alignlab/extension/QuerydslExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.hero.alignlab.extension | ||
|
||
import com.hero.alignlab.exception.AlignlabException | ||
import com.hero.alignlab.exception.ErrorCode | ||
import com.querydsl.core.types.dsl.* | ||
import com.querydsl.jpa.impl.JPAQuery | ||
import org.springframework.data.domain.* | ||
import org.springframework.data.jpa.repository.support.Querydsl | ||
import java.time.LocalDateTime | ||
|
||
fun <T> Querydsl?.execute(query: JPAQuery<T>, pageable: Pageable): Page<T> { | ||
return this.takeUnless { querydsl -> querydsl == null } | ||
?.let { queryDsl -> | ||
queryDsl.applyPagination(pageable, query).run { | ||
PageImpl(this.fetch(), pageable, this.fetchCount()) | ||
} | ||
} ?: throw AlignlabException(ErrorCode.QUERY_DSL_NOT_EXISTS_ERROR) | ||
} | ||
|
||
fun <T> Querydsl?.executeSlice(query: JPAQuery<T>, pageable: Pageable): Slice<T> { | ||
return this.takeUnless { querydsl -> querydsl == null } | ||
?.let { queryDsl -> | ||
queryDsl.applyPagination(pageable, query).run { | ||
this.limit(pageable.pageSize + 1L) | ||
.fetch() | ||
}.run { | ||
var hasNext = false | ||
if (this.size > pageable.pageSize) { | ||
hasNext = true | ||
this.removeAt(pageable.pageSize) | ||
} | ||
SliceImpl(this, pageable, hasNext) | ||
} | ||
} ?: throw AlignlabException(ErrorCode.QUERY_DSL_NOT_EXISTS_ERROR) | ||
} | ||
|
||
fun StringPath.isEquals(parameter: String?): BooleanExpression? { | ||
return parameter?.let { param -> this.eq(param) } | ||
} | ||
|
||
fun NumberPath<Long>.isEquals(parameter: Long?): BooleanExpression? { | ||
return parameter?.let { param -> this.eq(param) } | ||
} | ||
|
||
fun StringPath.isContains(parameter: String?): BooleanExpression? { | ||
return parameter?.let { param -> this.contains(param) } | ||
} | ||
|
||
fun NumberPath<Long>.isIn(parameters: Set<Long>?): BooleanExpression? { | ||
return parameters.takeUnless { params -> params.isNullOrEmpty() }?.let { params -> this.`in`(params) } | ||
} | ||
|
||
fun <T : Enum<T>> EnumPath<T>.isIn(parameters: Set<T>?): BooleanExpression? { | ||
return parameters?.takeIf { params -> params.isNotEmpty() }?.let { params -> this.`in`(params) } | ||
} | ||
|
||
fun NumberPath<Long>.isGoe(parameter: Long?): BooleanExpression? { | ||
return parameter?.let { param -> this.goe(param) } | ||
} | ||
|
||
fun NumberExpression<Long>.isGoe(parameter: Long?): BooleanExpression? { | ||
return parameter?.let { param -> this.goe(param) } | ||
} | ||
|
||
fun NumberExpression<Long>.isLoe(parameter: Long?): BooleanExpression? { | ||
return parameter?.let { param -> this.loe(param) } | ||
} | ||
|
||
fun NumberPath<Long>.isLoe(parameter: Long?): BooleanExpression? { | ||
return parameter?.let { param -> this.loe(param) } | ||
} | ||
|
||
fun NumberPath<Long>.isNotIn(parameters: Set<Long>?): BooleanExpression? { | ||
return parameters.takeUnless { params -> params.isNullOrEmpty() }?.let { params -> this.notIn(params) } | ||
} | ||
|
||
fun DateTimePath<LocalDateTime>.isGoe(parameter: LocalDateTime?): BooleanExpression? { | ||
return parameter?.let { param -> this.goe(param) } | ||
} | ||
|
||
fun DateTimePath<LocalDateTime>.isLoe(parameter: LocalDateTime?): BooleanExpression? { | ||
return parameter?.let { param -> this.loe(param) } | ||
} |