Skip to content

Commit c52f534

Browse files
authored
Display only visible tags and categories in API List
1 parent 2129784 commit c52f534

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

daikoku/app/domain/CommonServices.scala

+40-39
Original file line numberDiff line numberDiff line change
@@ -537,59 +537,60 @@ object CommonServices {
537537
}
538538
}
539539
def getAllTags(research: String)(implicit
540-
ctx: DaikokuActionContext[_],
541-
env: Env,
542-
ec: ExecutionContext
540+
ctx: DaikokuActionContext[JsValue],
541+
env: Env,
542+
ec: ExecutionContext
543543
): Future[Seq[String]] = {
544544
for {
545-
apis <- env.dataStore.apiRepo.forTenant(ctx.tenant.id).findAllNotDeleted()
545+
visibleApis <- getVisibleApis(research = "", limit = -1, offset = 0)
546546
} yield {
547-
apis
548-
.flatMap(api =>
549-
api.tags.toSeq.filter(tag => tag.indexOf(research) != -1)
550-
)
551-
.foldLeft(Map.empty[String, Int])((map, tag) => {
552-
val nbOfMatching = map.get(tag) match {
553-
case Some(count) => count + 1
554-
case None => 1
555-
}
556-
map + (tag -> nbOfMatching)
557-
558-
})
559-
.toSeq
560-
.sortBy(_._2)
561-
.reverse
562-
.map(a => a._1)
563-
.take(5)
547+
visibleApis
548+
.map(apis => apis.apis.flatMap(api =>
549+
api.api.tags.toSeq.filter(tag => tag.indexOf(research) != -1)
550+
)
551+
.foldLeft(Map.empty[String, Int])((map, tag) => {
552+
val nbOfMatching = map.get(tag) match {
553+
case Some(count) => count + 1
554+
case None => 1
555+
}
556+
map + (tag -> nbOfMatching)
564557

558+
})
559+
.toSeq
560+
.sortBy(_._2)
561+
.reverse
562+
.map(a => a._1)
563+
.take(5))
564+
.getOrElse(Seq.empty)
565565
}
566566
}
567567

568568
def getAllCategories(research: String)(implicit
569-
ctx: DaikokuActionContext[_],
569+
ctx: DaikokuActionContext[JsValue],
570570
env: Env,
571571
ec: ExecutionContext
572572
): Future[Seq[String]] = {
573573
for {
574-
apis <- env.dataStore.apiRepo.forTenant(ctx.tenant.id).findAllNotDeleted()
574+
visibleApis <- getVisibleApis(research = "", limit = -1, offset = 0)
575575
} yield {
576-
apis
577-
.flatMap(api =>
578-
api.categories.toSeq.filter(cat => cat.indexOf(research) != -1)
579-
)
580-
.foldLeft(Map.empty[String, Int])((map, cat) => {
581-
val nbOfMatching = map.get(cat) match {
582-
case Some(count) => count + 1
583-
case None => 1
584-
}
585-
map + (cat -> nbOfMatching)
576+
visibleApis
577+
.map(apis => apis.apis.flatMap(api =>
578+
api.api.categories.toSeq.filter(tag => tag.indexOf(research) != -1)
579+
)
580+
.foldLeft(Map.empty[String, Int])((map, cat) => {
581+
val nbOfMatching = map.get(cat) match {
582+
case Some(count) => count + 1
583+
case None => 1
584+
}
585+
map + (cat -> nbOfMatching)
586586

587-
})
588-
.toSeq
589-
.sortBy(_._2)
590-
.reverse
591-
.map(a => a._1)
592-
.take(5)
587+
})
588+
.toSeq
589+
.sortBy(_._2)
590+
.reverse
591+
.map(a => a._1)
592+
.take(5))
593+
.getOrElse(Seq.empty)
593594
}
594595
}
595596

0 commit comments

Comments
 (0)