Commit 53c9063e authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

finished /api/tags coach.

parent 89a2798c
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Document</title>
</head>
<body>
<h1>Hello, Bro!</h1>
</body>
</html>
\ No newline at end of file
......@@ -23,6 +23,8 @@ library
, API.Articles
, API.Profile
, API.Tags
, Que.Tags
, Coach.Tags
, RealWorld
, DevelMain
other-modules: Lib.Prelude
......
......@@ -12,13 +12,15 @@ import Protolude
import Servant
import Types
import Conf
import Types
import Coach.Tags
type TagsAPI = "tags" :> Get '[ JSON] ResponseTags
tagsApi :: MonadIO m => ServerT TagsAPI (CoachT m)
tagsApi = panic ""
tagsApi = getTagsCoach
tagsProxy :: Proxy TagsAPI
tagsProxy = Proxy
......
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Coach.Tags where
import Protolude
import Database.Esqueleto
import Conf
import Model
import Types
import Que.Tags
getTagsCoach :: MonadIO m => CoachT m ResponseTags
getTagsCoach = do
tags <- runDb selectTags
return (resptags tags)
where
resptags xs = ResponseTags $ map (tagName . entityVal) xs
......@@ -19,6 +19,8 @@ import Database.Persist.Sql
import Database.Persist.TH
import Servant.Auth.Server
import Conf
share
[ mkPersist sqlSettings
, mkDeleteCascade sqlSettings
......@@ -83,3 +85,11 @@ instance FromJWT User
doMigration :: SqlPersistT IO ()
doMigration = runMigration migrateEverything
runDb ::
(MonadIO m, MonadReader Configuration m)
=> SqlPersistT IO b
-> m b
runDb q = do
pool <- asks configurationPool
liftIO $ runSqlPool q pool
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module Que.Tags where
import Lib.Prelude hiding (from, get, on, (<&>))
import Database.Esqueleto
import Model
selectTags ::
( PersistUniqueRead backend
, PersistQueryRead backend
, BackendCompatible SqlBackend backend
, MonadIO m
)
=> ReaderT backend m [Entity Tag]
selectTags =
select $
from $ \tag -> do
orderBy [asc (tag ^. TagName)]
return tag
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment