Do not quote params in Location header
Also treat the enum field in OPTIONS as an array uniformly
This commit is contained in:
+7
-1
@@ -116,7 +116,7 @@ app req =
|
||||
then inserted
|
||||
else filterWithKey (const . (`elem` primaryKeys)) inserted
|
||||
let params = urlEncodeVars
|
||||
$ map (\t -> (cs $ fst t, "eq." <> cs (encode $ snd t)))
|
||||
$ map (\t -> (cs $ fst t, "eq." <> cs (unquoted $ snd t)))
|
||||
$ sortBy (comparing fst) $ toList primaries
|
||||
return $ responseLBS status201
|
||||
[ jsonH
|
||||
@@ -224,6 +224,12 @@ handleJsonObj req handler = do
|
||||
jErr = encode . object $
|
||||
[("error", String "Expecting a JSON object")]
|
||||
|
||||
unquoted :: Value -> Text
|
||||
unquoted (String t) = t
|
||||
unquoted (Number n) = cs . show $ n
|
||||
unquoted (Bool b) = cs . show $ b
|
||||
unquoted _ = ""
|
||||
|
||||
data TableOptions = TableOptions {
|
||||
tblOptcolumns :: [Column]
|
||||
, tblOptpkey :: [Text]
|
||||
|
||||
+12
-6
@@ -1,7 +1,7 @@
|
||||
{-# LANGUAGE QuasiQuotes, ScopedTypeVariables #-}
|
||||
module Auth where
|
||||
|
||||
import qualified Data.Aeson as JSON
|
||||
import Data.Aeson
|
||||
import Control.Monad (mzero)
|
||||
import Control.Applicative ( (<*>), (<$>) )
|
||||
import Crypto.BCrypt
|
||||
@@ -16,13 +16,19 @@ data AuthUser = AuthUser {
|
||||
, userRole :: String
|
||||
}
|
||||
|
||||
instance JSON.FromJSON AuthUser where
|
||||
parseJSON (JSON.Object v) = AuthUser <$>
|
||||
v JSON..: "id" <*>
|
||||
v JSON..: "pass" <*>
|
||||
v JSON..: "role"
|
||||
instance FromJSON AuthUser where
|
||||
parseJSON (Object v) = AuthUser <$>
|
||||
v .: "id" <*>
|
||||
v .: "pass" <*>
|
||||
v .: "role"
|
||||
parseJSON _ = mzero
|
||||
|
||||
instance ToJSON AuthUser where
|
||||
toJSON u = object [
|
||||
"id" .= userId u
|
||||
, "pass" .= userPass u
|
||||
, "role" .= userRole u ]
|
||||
|
||||
type DbRole = Text
|
||||
|
||||
data LoginAttempt =
|
||||
|
||||
+10
-6
@@ -1,4 +1,5 @@
|
||||
{-# LANGUAGE QuasiQuotes, MultiParamTypeClasses, ScopedTypeVariables #-}
|
||||
{-# LANGUAGE QuasiQuotes, OverloadedStrings,
|
||||
MultiParamTypeClasses, ScopedTypeVariables #-}
|
||||
module PgStructure where
|
||||
|
||||
import PgQuery (QualifiedTable(..))
|
||||
@@ -127,7 +128,7 @@ data Column = Column {
|
||||
, colMaxLen :: Maybe Int
|
||||
, colPrecision :: Maybe Int
|
||||
, colDefault :: Maybe Text
|
||||
, colEnum :: Maybe [Text]
|
||||
, colEnum :: [Text]
|
||||
, colFK :: Maybe ForeignKey
|
||||
} deriving (Show)
|
||||
|
||||
@@ -143,19 +144,22 @@ instance H.RowParser H.Postgres Column where
|
||||
maxLen = H.parseResult $ r V.! 7
|
||||
precision = H.parseResult $ r V.! 8
|
||||
defValue = H.parseResult $ r V.! 9
|
||||
enum = H.parseResult $ r V.! 10 in
|
||||
enum = either (const $ Right []) (Right . split (==','))
|
||||
(H.parseResult $ r V.! 10 :: Either Text Text)
|
||||
in
|
||||
if V.length r /= 11
|
||||
then Left "Wrong number of fields in Column"
|
||||
else Column <$> schema <*> table <*> name <*> position <*> nullable
|
||||
<*> typ <*> updatable <*> maxLen <*> precision
|
||||
<*> defValue <*> enum <*> return Nothing
|
||||
<*> defValue <*> enum
|
||||
<*> return Nothing
|
||||
|
||||
|
||||
instance H.RowParser H.Postgres Table where
|
||||
parseRow r =
|
||||
let schema = H.parseResult $ r V.! 0
|
||||
name = H.parseResult $ r V.! 2
|
||||
insertable = toBool <$> (H.parseResult $ r V.! 3 :: Either Text Text) in
|
||||
name = H.parseResult $ r V.! 1
|
||||
insertable = toBool <$> (H.parseResult $ r V.! 2 :: Either Text Text) in
|
||||
if V.length r /= 3
|
||||
then Left "Wrong number of fields in Table"
|
||||
else Table <$> schema <*> name <*> insertable
|
||||
|
||||
Reference in New Issue
Block a user