mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-31 05:15:08 +00:00
Streamline query parameters
This commit is contained in:
parent
d535130c9e
commit
c6f3920351
@ -17,6 +17,12 @@ object QueryParam {
|
|||||||
QueryParamDecoder[String].map(s => QueryString(s.trim.toLowerCase))
|
QueryParamDecoder[String].map(s => QueryString(s.trim.toLowerCase))
|
||||||
|
|
||||||
|
|
||||||
|
// implicit val booleanDecoder: QueryParamDecoder[Boolean] =
|
||||||
|
// QueryParamDecoder.fromUnsafeCast(qp => Option(qp.value).exists(_.equalsIgnoreCase("true")))(
|
||||||
|
// "Boolean"
|
||||||
|
// )
|
||||||
|
|
||||||
|
object FullOpt extends OptionalQueryParamDecoderMatcher[Boolean]("full")
|
||||||
|
|
||||||
object ContactKindOpt extends OptionalQueryParamDecoderMatcher[ContactKind]("kind")
|
object ContactKindOpt extends OptionalQueryParamDecoderMatcher[ContactKind]("kind")
|
||||||
|
|
||||||
|
@ -2,15 +2,17 @@ package docspell.restserver.routes
|
|||||||
|
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits._
|
import cats.implicits._
|
||||||
|
import org.http4s.HttpRoutes
|
||||||
|
import org.http4s.circe.CirceEntityDecoder._
|
||||||
|
import org.http4s.circe.CirceEntityEncoder._
|
||||||
|
import org.http4s.dsl.Http4sDsl
|
||||||
|
|
||||||
import docspell.backend.BackendApp
|
import docspell.backend.BackendApp
|
||||||
import docspell.backend.auth.AuthToken
|
import docspell.backend.auth.AuthToken
|
||||||
import docspell.common.Ident
|
import docspell.common.Ident
|
||||||
import docspell.restapi.model._
|
import docspell.restapi.model._
|
||||||
import docspell.restserver.conv.Conversions._
|
import docspell.restserver.conv.Conversions._
|
||||||
import org.http4s.HttpRoutes
|
import docspell.restserver.http4s.QueryParam
|
||||||
import org.http4s.circe.CirceEntityDecoder._
|
|
||||||
import org.http4s.circe.CirceEntityEncoder._
|
|
||||||
import org.http4s.dsl.Http4sDsl
|
|
||||||
|
|
||||||
object EquipmentRoutes {
|
object EquipmentRoutes {
|
||||||
|
|
||||||
@ -19,10 +21,9 @@ object EquipmentRoutes {
|
|||||||
import dsl._
|
import dsl._
|
||||||
|
|
||||||
HttpRoutes.of {
|
HttpRoutes.of {
|
||||||
case req @ GET -> Root =>
|
case GET -> Root :? QueryParam.QueryOpt(q) =>
|
||||||
val q = req.params.get("q").map(_.trim).filter(_.nonEmpty)
|
|
||||||
for {
|
for {
|
||||||
data <- backend.equipment.findAll(user.account, q)
|
data <- backend.equipment.findAll(user.account, q.map(_.q))
|
||||||
resp <- Ok(EquipmentList(data.map(mkEquipment).toList))
|
resp <- Ok(EquipmentList(data.map(mkEquipment).toList))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import docspell.restapi.model._
|
|||||||
import docspell.store.records.RUserEmail
|
import docspell.store.records.RUserEmail
|
||||||
import docspell.store.EmilUtil
|
import docspell.store.EmilUtil
|
||||||
import docspell.restserver.conv.Conversions
|
import docspell.restserver.conv.Conversions
|
||||||
|
import docspell.restserver.http4s.QueryParam
|
||||||
|
|
||||||
object MailSettingsRoutes {
|
object MailSettingsRoutes {
|
||||||
|
|
||||||
@ -25,10 +26,9 @@ object MailSettingsRoutes {
|
|||||||
import dsl._
|
import dsl._
|
||||||
|
|
||||||
HttpRoutes.of {
|
HttpRoutes.of {
|
||||||
case req @ GET -> Root =>
|
case GET -> Root :? QueryParam.QueryOpt(q) =>
|
||||||
val q = req.params.get("q").map(_.trim).filter(_.nonEmpty)
|
|
||||||
for {
|
for {
|
||||||
list <- backend.mail.getSettings(user.account, q)
|
list <- backend.mail.getSettings(user.account, q.map(_.q))
|
||||||
res = list.map(convert)
|
res = list.map(convert)
|
||||||
resp <- Ok(EmailSettingsList(res.toList))
|
resp <- Ok(EmailSettingsList(res.toList))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
@ -7,7 +7,7 @@ import docspell.backend.auth.AuthToken
|
|||||||
import docspell.common.Ident
|
import docspell.common.Ident
|
||||||
import docspell.restapi.model._
|
import docspell.restapi.model._
|
||||||
import docspell.restserver.conv.Conversions._
|
import docspell.restserver.conv.Conversions._
|
||||||
import docspell.restserver.routes.ParamDecoder._
|
import docspell.restserver.http4s.QueryParam
|
||||||
import org.http4s.HttpRoutes
|
import org.http4s.HttpRoutes
|
||||||
import org.http4s.circe.CirceEntityDecoder._
|
import org.http4s.circe.CirceEntityDecoder._
|
||||||
import org.http4s.circe.CirceEntityEncoder._
|
import org.http4s.circe.CirceEntityEncoder._
|
||||||
@ -20,16 +20,15 @@ object OrganizationRoutes {
|
|||||||
import dsl._
|
import dsl._
|
||||||
|
|
||||||
HttpRoutes.of {
|
HttpRoutes.of {
|
||||||
case req @ GET -> Root :? FullQueryParamMatcher(full) =>
|
case GET -> Root :? QueryParam.FullOpt(full) +& QueryParam.QueryOpt(q) =>
|
||||||
val q = req.params.get("q").map(_.trim).filter(_.nonEmpty)
|
|
||||||
if (full.getOrElse(false)) {
|
if (full.getOrElse(false)) {
|
||||||
for {
|
for {
|
||||||
data <- backend.organization.findAllOrg(user.account, q)
|
data <- backend.organization.findAllOrg(user.account, q.map(_.q))
|
||||||
resp <- Ok(OrganizationList(data.map(mkOrg).toList))
|
resp <- Ok(OrganizationList(data.map(mkOrg).toList))
|
||||||
} yield resp
|
} yield resp
|
||||||
} else {
|
} else {
|
||||||
for {
|
for {
|
||||||
data <- backend.organization.findAllOrgRefs(user.account, q)
|
data <- backend.organization.findAllOrgRefs(user.account, q.map(_.q))
|
||||||
resp <- Ok(ReferenceList(data.map(mkIdName).toList))
|
resp <- Ok(ReferenceList(data.map(mkIdName).toList))
|
||||||
} yield resp
|
} yield resp
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package docspell.restserver.routes
|
|
||||||
|
|
||||||
import org.http4s.QueryParamDecoder
|
|
||||||
import org.http4s.dsl.impl.OptionalQueryParamDecoderMatcher
|
|
||||||
|
|
||||||
object ParamDecoder {
|
|
||||||
|
|
||||||
implicit val booleanDecoder: QueryParamDecoder[Boolean] =
|
|
||||||
QueryParamDecoder.fromUnsafeCast(qp => Option(qp.value).exists(_.equalsIgnoreCase("true")))(
|
|
||||||
"Boolean"
|
|
||||||
)
|
|
||||||
|
|
||||||
object FullQueryParamMatcher extends OptionalQueryParamDecoderMatcher[Boolean]("full")
|
|
||||||
|
|
||||||
}
|
|
@ -8,7 +8,7 @@ import docspell.common.Ident
|
|||||||
import docspell.common.syntax.all._
|
import docspell.common.syntax.all._
|
||||||
import docspell.restapi.model._
|
import docspell.restapi.model._
|
||||||
import docspell.restserver.conv.Conversions._
|
import docspell.restserver.conv.Conversions._
|
||||||
import docspell.restserver.routes.ParamDecoder._
|
import docspell.restserver.http4s.QueryParam
|
||||||
import org.http4s.HttpRoutes
|
import org.http4s.HttpRoutes
|
||||||
import org.http4s.circe.CirceEntityDecoder._
|
import org.http4s.circe.CirceEntityDecoder._
|
||||||
import org.http4s.circe.CirceEntityEncoder._
|
import org.http4s.circe.CirceEntityEncoder._
|
||||||
@ -23,16 +23,15 @@ object PersonRoutes {
|
|||||||
import dsl._
|
import dsl._
|
||||||
|
|
||||||
HttpRoutes.of {
|
HttpRoutes.of {
|
||||||
case req @ GET -> Root :? FullQueryParamMatcher(full) =>
|
case GET -> Root :? QueryParam.FullOpt(full) +& QueryParam.QueryOpt(q) =>
|
||||||
val q = req.params.get("q").map(_.trim).filter(_.nonEmpty)
|
|
||||||
if (full.getOrElse(false)) {
|
if (full.getOrElse(false)) {
|
||||||
for {
|
for {
|
||||||
data <- backend.organization.findAllPerson(user.account, q)
|
data <- backend.organization.findAllPerson(user.account, q.map(_.q))
|
||||||
resp <- Ok(PersonList(data.map(mkPerson).toList))
|
resp <- Ok(PersonList(data.map(mkPerson).toList))
|
||||||
} yield resp
|
} yield resp
|
||||||
} else {
|
} else {
|
||||||
for {
|
for {
|
||||||
data <- backend.organization.findAllPersonRefs(user.account, q)
|
data <- backend.organization.findAllPersonRefs(user.account, q.map(_.q))
|
||||||
resp <- Ok(ReferenceList(data.map(mkIdName).toList))
|
resp <- Ok(ReferenceList(data.map(mkIdName).toList))
|
||||||
} yield resp
|
} yield resp
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import docspell.backend.auth.AuthToken
|
|||||||
import docspell.common.Ident
|
import docspell.common.Ident
|
||||||
import docspell.restapi.model._
|
import docspell.restapi.model._
|
||||||
import docspell.restserver.conv.Conversions._
|
import docspell.restserver.conv.Conversions._
|
||||||
import docspell.restserver.http4s.ResponseGenerator
|
import docspell.restserver.http4s._
|
||||||
import org.http4s.HttpRoutes
|
import org.http4s.HttpRoutes
|
||||||
import org.http4s.circe.CirceEntityDecoder._
|
import org.http4s.circe.CirceEntityDecoder._
|
||||||
import org.http4s.circe.CirceEntityEncoder._
|
import org.http4s.circe.CirceEntityEncoder._
|
||||||
@ -20,10 +20,9 @@ object TagRoutes {
|
|||||||
import dsl._
|
import dsl._
|
||||||
|
|
||||||
HttpRoutes.of {
|
HttpRoutes.of {
|
||||||
case req @ GET -> Root =>
|
case GET -> Root :? QueryParam.QueryOpt(q) =>
|
||||||
val q = req.params.get("q").map(_.trim).filter(_.nonEmpty)
|
|
||||||
for {
|
for {
|
||||||
all <- backend.tag.findAll(user.account, q)
|
all <- backend.tag.findAll(user.account, q.map(_.q))
|
||||||
resp <- Ok(TagList(all.size, all.map(mkTag).toList))
|
resp <- Ok(TagList(all.size, all.map(mkTag).toList))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user