Do not do table count when plurality=singular

Rebasing commits by @ruslantalpa
This commit is contained in:
Joe Nelson
2016-03-23 20:30:51 -07:00
parent 01355f39a1
commit cd81e9346f
3 changed files with 15 additions and 2 deletions
+6 -2
View File
@@ -130,7 +130,7 @@ userApiRequest schema req reqBody =
, iPayload = relevantPayload
, iPreferRepresentation = representation
, iPreferSingular = singular
, iPreferCount = not $ hasPrefer "count=none"
, iPreferCount = not $ singular || hasPrefer "count=none"
, iFilters = [ (k, fromJust v) | (k,v) <- qParams, k `notElem` ["select", "order"], isJust v ]
, iSelect = if method == "DELETE"
then "*"
@@ -145,7 +145,11 @@ userApiRequest schema req reqBody =
hdrs = requestHeaders req
qParams = [(cs k, cs <$> v)|(k,v) <- queryString req]
lookupHeader = flip lookup hdrs
hasPrefer val = any (\(h,v) -> h == "Prefer" && v == val) hdrs
hasPrefer :: T.Text -> Bool
hasPrefer val = any (\(h,v) -> h == "Prefer" && val `elem` split v) hdrs
where
split :: BS.ByteString -> [T.Text]
split = map T.strip . T.split (==';') . cs
singular = hasPrefer "plurality=singular"
representation
| hasPrefer "return=representation" = Full