From aef26675b417ef2148c06134e00d937bd89fceba Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Fri, 12 May 2023 08:32:55 -0500 Subject: [PATCH] Enhance owner endpoint --- CHANGELOG.md | 1 + src/ZGoBackend.hs | 44 ++++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4f81bd..98fb08a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Modified API tests to use `session` parameter. - Modified `api/owner` endpoint to use a specific data structure to create new owners +- Modified `api/owner` endpoint to use session as input ## [1.4.1] - 2023-05-02 diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 32d3190..d3dfc70 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -914,35 +914,35 @@ routes pipe config = do get "/getaddr" $ do Web.Scotty.json (object ["addr" .= nodeAddress]) --Get owner by address get "/api/owner" $ do - addr <- param "address" - owner <- liftAndCatchIO $ run (findOwner addr) - case owner of + session <- param "session" + user <- liftAndCatchIO $ run (findUser session) + case parseUserBson =<< user of Nothing -> status noContent204 - Just o -> do - let pOwner = cast' (Doc o) - case pOwner of - Nothing -> status internalServerError500 - Just q -> do + Just u -> do + owner <- liftAndCatchIO $ run (findOwner $ uaddress u) + case cast' . Doc =<< owner of + Nothing -> status noContent204 + Just o -> do status ok200 Web.Scotty.json (object [ "message" .= ("Owner found!" :: String) , "owner" .= object - [ "_id" .= (maybe "" show $ o_id q :: String) - , "address" .= oaddress q - , "name" .= oname q - , "currency" .= ocurrency q - , "tax" .= otax q - , "taxValue" .= otaxValue q - , "vat" .= ovat q - , "vatValue" .= ovatValue q - , "paid" .= opaid q - , "zats" .= ozats q - , "invoices" .= oinvoices q - , "expiration" .= oexpiration q - , "payconf" .= opayconf q - , "crmToken" .= ocrmToken q + [ "_id" .= (maybe "" show $ o_id o :: String) + , "address" .= oaddress o + , "name" .= oname o + , "currency" .= ocurrency o + , "tax" .= otax o + , "taxValue" .= otaxValue o + , "vat" .= ovat o + , "vatValue" .= ovatValue o + , "paid" .= opaid o + , "zats" .= ozats o + , "invoices" .= oinvoices o + , "expiration" .= oexpiration o + , "payconf" .= opayconf o + , "crmToken" .= ocrmToken o ] ]) get "/api/ownerid" $ do