-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move findByUsersId to UserService
- Loading branch information
Showing
10 changed files
with
83 additions
and
46 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../maa/backend/common/utils/KtExtensions.kt → ...backend/common/extensions/KtExtensions.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
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/plus/maa/backend/common/extensions/MongoExtensions.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,34 @@ | ||
package plus.maa.backend.common.extensions | ||
|
||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.mongodb.core.MongoOperations | ||
import org.springframework.data.mongodb.core.count | ||
import org.springframework.data.mongodb.core.find | ||
import org.springframework.data.mongodb.core.query.Criteria | ||
import org.springframework.data.mongodb.core.query.Query | ||
import org.springframework.data.support.PageableExecutionUtils | ||
|
||
inline fun <reified T : Any> MongoOperations.findPage( | ||
pageable: Pageable, | ||
query: Query = Query(), | ||
customizer: Query.() -> Unit = {}, | ||
): Page<T> { | ||
val q = query.apply(customizer) | ||
check(q.skip == 0L && !q.isLimited) { "query should not be paged" } | ||
val content = find<T>(q.with(pageable)) | ||
val total = count<T>(q.skip(0).limit(0)) | ||
return PageableExecutionUtils.getPage(content, pageable) { total } | ||
} | ||
|
||
fun Query.addAndCriteria(vararg criteria: Criteria) { | ||
addCriteria(Criteria().andOperator(*criteria)) | ||
} | ||
|
||
fun Query.addOrCriteria(vararg criteria: Criteria) { | ||
addCriteria(Criteria().orOperator(*criteria)) | ||
} | ||
|
||
fun Query.addNorCriteria(vararg criteria: Criteria) { | ||
addCriteria(Criteria().norOperator(*criteria)) | ||
} |
2 changes: 1 addition & 1 deletion
2
...ckend/common/utils/WebClientExtentions.kt → .../common/extensions/WebClientExtensions.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
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
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