summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Module/Sentiment.hs
blob: 2bf1edbb440d0fb4f303a9b074737bceb7254b61 (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.Utils.DB as DB

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