packages feed

dixi-0.1.0.0: Dixi/API.hs

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ConstraintKinds #-}
module Dixi.API where

import Data.Text (Text)
import Data.Patch
import Data.Proxy
import Servant.API
import Servant.HTML.Blaze

import Dixi.Common
import Dixi.Page
import Dixi.PatchUtils

type a :| b = a :<|> b
infixr 8 :|
infixr 8 |:

(|:) :: a -> b -> a :| b
(|:) = (:<|>)

data PrettyPage = PP Key Version (Page Text)
data RawPage    = RP Key Version (Page Text)
data DiffPage   = DP Key Version Version (Page (Hunks Char))
data History    = H Key [Page PatchSummary]

data NewBody = NB Text (Maybe Text)
data RevReq = DR Version Version (Maybe Text)

type HistoryAPI  = Get '[HTML] History
                :| Capture "version" Version :> VersionAPI
                :| "diff" :> QueryParam "from" Version :> QueryParam "to" Version :> Get '[HTML] DiffPage
                :| "revert" :> ReqBody '[FormUrlEncoded] RevReq :> Post '[HTML] PrettyPage
type VersionAPI  = PageViewAPI
                :| ReqBody '[FormUrlEncoded] NewBody :> Post '[HTML] PrettyPage
type PageAPI     = PageViewAPI
                :| "history" :> HistoryAPI
type PageViewAPI = Get '[HTML] PrettyPage
                :| "raw" :> Get '[HTML] RawPage
type Dixi        = Capture "page" Key :> PageAPI
                :| PageAPI

dixi :: Proxy Dixi
dixi = Proxy