All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jove.notebook.services.Config.scala Maven / Gradle / Ivy

The newest version!
package jove.notebook
package services

import org.http4s.dsl._
import org.http4s.argonaut._
import argonaut._, Argonaut._, Shapeless._

object Config {
  def apply(config: components.Config): Plan = {
    case GET -> Root / "api" / "config" / section =>
      Ok(config.configItem(section).fold(Json.obj())(jObject))

    case req @ (PUT -> Root / "api" / "config" / section) =>
      req.decode[Json] { reqJson =>
        reqJson.obj match {
          case Some(o) =>
            config.setConfigItem(section, o)
            NoContent()
          case None =>
            BadRequest()
        }
      }

    case req @ (PATCH -> Root / "api" / "config" / section) =>
      req.decode[Json] { reqJson =>
        reqJson.obj match {
          case Some(o) =>
            Ok(jObject(config.withConfigItem(section) { currentOpt =>

              (currentOpt.getOrElse(Json.obj().obj.get) /: o.toList) {
                case (acc, (k, v)) =>
                  acc + (k, v)
              }
            }))
          case None =>
            BadRequest()
        }
      }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy