summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Module/Sentiment.hs
blob: 6b998735e8df929913c3c9e61342e250d77b4cb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Fig.Web.Module.Sentiment
  ( public
  ) where

import Fig.Prelude

import Fig.Web.Utils
import Fig.Web.Types
import qualified Fig.Web.DB as DB

public :: PublicModule
public a = do
  onGet "/api/sentiment" do
    s <- DB.get a.db "sentiment" >>= \case
      Nothing -> pure "0"
      Just x -> pure x
    respondText $ decodeUtf8 s
  onPost "/api/sentiment/green" do
    DB.incr a.db "sentiment"
  onPost "/api/sentiment/red" do
    DB.decr a.db "sentiment"