mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Allow managing clientsettings per collective
This commit is contained in:
@ -19,6 +19,7 @@ import org.http4s.HttpRoutes
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
import org.http4s.circe.CirceEntityEncoder._
|
||||
import org.http4s.dsl.Http4sDsl
|
||||
import cats.kernel.Semigroup
|
||||
|
||||
object ClientSettingsRoutes {
|
||||
|
||||
@ -27,14 +28,27 @@ object ClientSettingsRoutes {
|
||||
import dsl._
|
||||
|
||||
HttpRoutes.of {
|
||||
case req @ PUT -> Root / Ident(clientId) =>
|
||||
case GET -> Root / Ident(clientId) =>
|
||||
for {
|
||||
collData <- backend.clientSettings.loadCollective(clientId, user.account)
|
||||
userData <- backend.clientSettings.loadUser(clientId, user.account)
|
||||
|
||||
mergedData = collData.map(_.settingsData) |+| userData.map(_.settingsData)
|
||||
|
||||
res <- mergedData match {
|
||||
case Some(j) => Ok(j)
|
||||
case None => NotFound()
|
||||
}
|
||||
} yield res
|
||||
|
||||
case req @ PUT -> Root / "user" / Ident(clientId) =>
|
||||
for {
|
||||
data <- req.as[Json]
|
||||
_ <- backend.clientSettings.saveUser(clientId, user.account, data)
|
||||
res <- Ok(BasicResult(true, "Settings stored"))
|
||||
} yield res
|
||||
|
||||
case GET -> Root / Ident(clientId) =>
|
||||
case GET -> Root / "user" / Ident(clientId) =>
|
||||
for {
|
||||
data <- backend.clientSettings.loadUser(clientId, user.account)
|
||||
res <- data match {
|
||||
@ -43,7 +57,7 @@ object ClientSettingsRoutes {
|
||||
}
|
||||
} yield res
|
||||
|
||||
case DELETE -> Root / Ident(clientId) =>
|
||||
case DELETE -> Root / "user" / Ident(clientId) =>
|
||||
for {
|
||||
flag <- backend.clientSettings.deleteUser(clientId, user.account)
|
||||
res <- Ok(
|
||||
@ -53,6 +67,36 @@ object ClientSettingsRoutes {
|
||||
)
|
||||
)
|
||||
} yield res
|
||||
|
||||
case req @ PUT -> Root / "collective" / Ident(clientId) =>
|
||||
for {
|
||||
data <- req.as[Json]
|
||||
_ <- backend.clientSettings.saveCollective(clientId, user.account, data)
|
||||
res <- Ok(BasicResult(true, "Settings stored"))
|
||||
} yield res
|
||||
|
||||
case GET -> Root / "collective" / Ident(clientId) =>
|
||||
for {
|
||||
data <- backend.clientSettings.loadCollective(clientId, user.account)
|
||||
res <- data match {
|
||||
case Some(d) => Ok(d.settingsData)
|
||||
case None => NotFound()
|
||||
}
|
||||
} yield res
|
||||
|
||||
case DELETE -> Root / "collective" / Ident(clientId) =>
|
||||
for {
|
||||
flag <- backend.clientSettings.deleteCollective(clientId, user.account)
|
||||
res <- Ok(
|
||||
BasicResult(
|
||||
flag,
|
||||
if (flag) "Settings deleted" else "Deleting settings failed"
|
||||
)
|
||||
)
|
||||
} yield res
|
||||
}
|
||||
}
|
||||
|
||||
implicit def jsonSemigroup: Semigroup[Json] =
|
||||
Semigroup.instance((a1, a2) => a1.deepMerge(a2))
|
||||
}
|
||||
|
Reference in New Issue
Block a user