Skip to content

Commit

Permalink
[#119] Remove JSON body from set-field-visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sancho20021 committed Jul 28, 2022
1 parent f9c5fa6 commit 4a373e2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/Web/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type API
:<|> "set-field-visibility"
:> RequiredParam "path" EntryPath
:> RequiredParam "field" FieldName
:> ReqBody '[JSON] FieldVisibility
:> Post '[JSON] Entry
:> ( "public" :> Post '[JSON] Entry
:<|> "private" :> Post '[JSON] Entry
)

:<|> "delete-field"
:> RequiredParam "path" EntryPath
Expand Down
12 changes: 11 additions & 1 deletion lib/Web/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,24 @@ reportErrors io = do
Right (Right a) -> do
return a

-- setFieldVisibility
-- :: (forall a. Command a -> Handler a)
-- -> Bool
-- -> EntryPath
-- -> FieldName
-- -> Handler Entry

makeServer
:: (SomeBackend -> (forall a. Command a -> Handler a))
-> Server API
makeServer run backend
= view (run backend)
:<|> create (run backend)
:<|> setField (run backend)
:<|> setFieldVisibility (run backend)
:<|> (\path field->
setFieldVisibility (run backend) path field Public
:<|> setFieldVisibility (run backend) path field Private
)
:<|> deleteField (run backend)
:<|> find' (run backend)
:<|> rename (run backend)
Expand Down
4 changes: 2 additions & 2 deletions tests/server-integration/SetField/SetFieldTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ unit_set_field_visibility = cofferTest do
createEntry "dir/entry"
void $ setField "dir/entry" "private-field" Nothing "contents"
void $ setField "dir/entry" "public-field" Nothing "contents"
changeFieldVisibility "dir/entry" "private-field" False
changeFieldVisibility "dir/entry" "public-field" True
changeFieldVisibility "dir/entry" "private-field" "private"
changeFieldVisibility "dir/entry" "public-field" "public"

response <-
executeCommand
Expand Down
8 changes: 4 additions & 4 deletions tests/server-integration/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ setField path name public contents =
where
visibility = boolToVisibility <$> public

changeFieldVisibility :: Text -> Text -> Bool -> IO ()
changeFieldVisibility path field public = void $
changeFieldVisibility :: Text -> Text -> Text -> IO ()
changeFieldVisibility path field visibility = void $
executeCommand
POST
["set-field-visibility"]
(ReqBodyJson $ String $ boolToVisibility public)
["set-field-visibility", visibility]
NoReqBody
ignoreResponse
( mconcat
[ "path" =: path
Expand Down
2 changes: 1 addition & 1 deletion tests/server-integration/View/ViewTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ unit_view_an_entry = cofferTest do
createEntry "dir/entry"
void $ setField "dir/entry" "public-field" Nothing "contents"
void $ setField "dir/entry" "private-field" Nothing "multiline\ncontents"
changeFieldVisibility "dir/entry" "private-field" False
changeFieldVisibility "dir/entry" "private-field" "private"

response <-
executeCommand
Expand Down

0 comments on commit 4a373e2

Please sign in to comment.