mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Provide email proposals from address book
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package docspell.restserver.http4s
|
||||
|
||||
import org.http4s.QueryParamDecoder
|
||||
import org.http4s.ParseFailure
|
||||
import docspell.common.ContactKind
|
||||
import org.http4s.dsl.impl.OptionalQueryParamDecoderMatcher
|
||||
|
||||
object QueryParam {
|
||||
case class QueryString(q: String)
|
||||
|
||||
implicit val contactKindDecoder: QueryParamDecoder[ContactKind] =
|
||||
QueryParamDecoder[String].emap(str =>
|
||||
ContactKind.fromString(str).left.map(s => ParseFailure(str, s))
|
||||
)
|
||||
|
||||
implicit val queryStringDecoder: QueryParamDecoder[QueryString] =
|
||||
QueryParamDecoder[String].map(s => QueryString(s.trim.toLowerCase))
|
||||
|
||||
|
||||
|
||||
object ContactKindOpt extends OptionalQueryParamDecoderMatcher[ContactKind]("kind")
|
||||
|
||||
object QueryOpt extends OptionalQueryParamDecoderMatcher[QueryString]("q")
|
||||
}
|
@ -6,7 +6,7 @@ import docspell.backend.BackendApp
|
||||
import docspell.backend.auth.AuthToken
|
||||
import docspell.restapi.model._
|
||||
import docspell.restserver.conv.Conversions
|
||||
import docspell.restserver.http4s.ResponseGenerator
|
||||
import docspell.restserver.http4s._
|
||||
import org.http4s.HttpRoutes
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
import org.http4s.circe.CirceEntityEncoder._
|
||||
@ -39,6 +39,16 @@ object CollectiveRoutes {
|
||||
resp <- sett.toResponse()
|
||||
} yield resp
|
||||
|
||||
case GET -> Root / "contacts" :? QueryParam.QueryOpt(q) +& QueryParam.ContactKindOpt(kind) =>
|
||||
for {
|
||||
res <- backend.collective
|
||||
.getContacts(user.account.collective, q.map(_.q), kind)
|
||||
.take(50)
|
||||
.compile
|
||||
.toList
|
||||
resp <- Ok(ContactList(res.map(Conversions.mkContact)))
|
||||
} yield resp
|
||||
|
||||
case GET -> Root =>
|
||||
for {
|
||||
collDb <- backend.collective.find(user.account.collective)
|
||||
|
Reference in New Issue
Block a user