@@ -16,7 +16,7 @@ module Data.PostElement (
16 MkElementRow,
16 MkElementRow,
17 PostElementRow(..),
17 PostElementRow(..),
18 elementsToRows
18 elementsToRows
21import Data.Int (Int64)
21import Data.Int (Int64)
22import qualified Generics.SOP as SOP
22import qualified Generics.SOP as SOP
@@ -25,7 +25,6 @@ import Data.Text (Text)
25import Data.Aeson
25import Data.Aeson
26import Control.Applicative ((<|>))
26import Control.Applicative ((<|>))
27import Servant.Docs (ToSample, toSamples, samples)
27import Servant.Docs (ToSample, toSamples, samples)
30-- MARK: Documentation
29-- MARK: Documentation
@@ -44,14 +43,7 @@ data PostElement a = Markdown Text
44 | Quote PostQuote
43 | Quote PostQuote
45 | Attachment Text
44 | Attachment Text
47−instance {-# Overlapping #-} Sanitizable (PostElement t) where
48− sanitize f (Markdown m) = Markdown (sanitize f m)
49− sanitize f (Latex l) = Latex (sanitize f l)
50− sanitize f (Image i) = Image (sanitize f i)
51− sanitize f (Quote q) = Quote (sanitize f q)
52− sanitize f (Attachment a) = Attachment (sanitize f a)
54−instance ToJSON (PostElement t) where
46+instance ToJSON (PostElement t) where
55 toJSON (Markdown m) = object ["markdown" .= m]
47 toJSON (Markdown m) = object ["markdown" .= m]
56 toJSON (Latex l) = object ["latex" .= l]
48 toJSON (Latex l) = object ["latex" .= l]
57 toJSON (Image i) = object ["image" .= i]
49 toJSON (Image i) = object ["image" .= i]
@@ -59,7 +51,7 @@ instance ToJSON (PostElement t) where
59 toJSON (Attachment a) = object ["attachment" .= a]
51 toJSON (Attachment a) = object ["attachment" .= a]
61instance FromJSON (PostElement t) where
53instance FromJSON (PostElement t) where
62− parseJSON = withObject "post element" $ \e ->
54+ parseJSON = withObject "post element" $ \e ->
63 Markdown <$> e .: "markdown" <|>
55 Markdown <$> e .: "markdown" <|>
64 Latex <$> e .: "latex" <|>
56 Latex <$> e .: "latex" <|>
65 Image <$> e .: "image" <|>
57 Image <$> e .: "image" <|>
@@ -83,7 +75,7 @@ rowsToElement :: MkElementRow (Maybe (PostElement p))
83rowsToElement (Just m) Nothing Nothing Nothing Nothing = Just $ Markdown m
75rowsToElement (Just m) Nothing Nothing Nothing Nothing = Just $ Markdown m
84rowsToElement Nothing (Just l) Nothing Nothing Nothing = Just $ Latex l
76rowsToElement Nothing (Just l) Nothing Nothing Nothing = Just $ Latex l
85rowsToElement Nothing Nothing (Just i) Nothing Nothing = Just $ Image i
77rowsToElement Nothing Nothing (Just i) Nothing Nothing = Just $ Image i
86−-- rowsToElement Nothing Nothing Nothing (Just q) Nothing =
78+-- rowsToElement Nothing Nothing Nothing (Just q) Nothing =
87-- fmap Quote $ M.lookup q pqrs >>= rowsToQuote erqs pqrs
79-- fmap Quote $ M.lookup q pqrs >>= rowsToQuote erqs pqrs
88rowsToElement Nothing Nothing Nothing Nothing (Just a) = Just $ Attachment a
80rowsToElement Nothing Nothing Nothing Nothing (Just a) = Just $ Attachment a
89rowsToElement _ _ _ _ _ = Nothing
81rowsToElement _ _ _ _ _ = Nothing
@@ -106,7 +98,7 @@ elementsToRows :: Int64 -> [PostElement a] -> [PostElementRow a]
106elementsToRows pId els = map (\(el, f) -> elemenToRow f el) . zip els . map (PostElementRow pId) $ [0..]
98elementsToRows pId els = map (\(el, f) -> elemenToRow f el) . zip els . map (PostElementRow pId) $ [0..]
109−-- -- MARK: Quote
101+-- -- MARK: Quote
111data PostQuote = PostQuote {
103data PostQuote = PostQuote {
112 quoteId :: Int64,
104 quoteId :: Int64,
@@ -114,16 +106,13 @@ data PostQuote = PostQuote {
114 quotePostId :: Int64
106 quotePostId :: Int64
117−instance Sanitizable PostQuote where
118− sanitize f (PostQuote qId qB qPId) = PostQuote qId (sanitize f qB) qPId
120instance ToJSON PostQuote where
109instance ToJSON PostQuote where
121 toJSON (PostQuote qId pb pId) = object [
110 toJSON (PostQuote qId pb pId) = object [
122− "id" .= qId,
111+ "id" .= qId,
123 "postId" .= pId,
112 "postId" .= pId,
124 "quoteBody" .= pb ]
113 "quoteBody" .= pb ]
127-- -- MARK: PostQuoteRow
116-- -- MARK: PostQuoteRow
129-- data PostQuoteRow = PostQuoteRow {
118-- data PostQuoteRow = PostQuoteRow {
@@ -133,7 +122,7 @@ instance ToJSON PostQuote where
134-- instance SOP.Generic PostQuoteRow
123-- instance SOP.Generic PostQuoteRow
135-- instance SOP.HasDatatypeInfo PostQuoteRow
124-- instance SOP.HasDatatypeInfo PostQuoteRow
137-- rowsToQuote :: M.Map Int64 [ElementRow PostQuote] -> M.Map Int64 PostQuoteRow -> PostQuoteRow -> Maybe PostQuote
126-- rowsToQuote :: M.Map Int64 [ElementRow PostQuote] -> M.Map Int64 PostQuoteRow -> PostQuoteRow -> Maybe PostQuote
138-- rowsToQuote erqs pqrs (PostQuoteRow qId pId) = do
127-- rowsToQuote erqs pqrs (PostQuoteRow qId pId) = do
139-- elementRows <- M.lookup qId erqs
128-- elementRows <- M.lookup qId erqs