From ad66224ebced23fd90da4be914ef45fbbb2b93ff Mon Sep 17 00:00:00 2001 From: dragove Date: Fri, 12 Apr 2024 02:09:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=83=BD=E5=A4=9F?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=88=B0=E7=A7=81=E6=9C=89=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E9=9B=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maa/backend/service/CopilotSetService.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/plus/maa/backend/service/CopilotSetService.kt b/src/main/kotlin/plus/maa/backend/service/CopilotSetService.kt index bf7d6e95..b644929e 100644 --- a/src/main/kotlin/plus/maa/backend/service/CopilotSetService.kt +++ b/src/main/kotlin/plus/maa/backend/service/CopilotSetService.kt @@ -113,29 +113,31 @@ class CopilotSetService( fun query(req: CopilotSetQuery, userId: String?): CopilotSetPageRes { val pageRequest = PageRequest.of(req.page - 1, req.limit, defaultSort) - val criteria = Criteria.where("status").`is`(CopilotSetStatus.PUBLIC) - val query = Query.query( - if (userId.isNullOrBlank()) { - criteria - } else { - Criteria().orOperator(criteria, Criteria.where("creatorId").`is`(userId)) - }.and("delete").`is`(false) - ).with(pageRequest) + val andList = ArrayList() + val publicCriteria = Criteria.where("status").`is`(CopilotSetStatus.PUBLIC) + val permissionCriterion = if (userId.isNullOrBlank()) { + publicCriteria + } else { + Criteria().orOperator(publicCriteria, Criteria.where("creatorId").`is`(userId)) + } + andList.add(permissionCriterion) + andList.add(Criteria.where("delete").`is`(false)) if (!req.copilotIds.isNullOrEmpty()) { - query.addCriteria(Criteria.where("copilotIds").all(req.copilotIds)).with(pageRequest) + andList.add(Criteria.where("copilotIds").all(req.copilotIds)) } if (!req.creatorId.isNullOrBlank()) { - query.addCriteria(Criteria.where("creatorId").`is`(req.creatorId)) + andList.add(Criteria.where("creatorId").`is`(req.creatorId)) } if (!req.keyword.isNullOrBlank()) { val pattern = Pattern.compile(req.keyword, Pattern.CASE_INSENSITIVE) - query.addCriteria( + andList.add( Criteria().orOperator( Criteria.where("name").regex(pattern), Criteria.where("description").regex(pattern) ) ) } + val query = Query.query(Criteria().andOperator(andList)).with(pageRequest) val copilotSets = PageableExecutionUtils.getPage(mongoTemplate.find(query, CopilotSet::class.java), pageRequest) { mongoTemplate.count(