Modify endpoint to create new owner
This commit is contained in:
parent
cbc4e02766
commit
a201810134
3 changed files with 71 additions and 26 deletions
|
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Modified API tests to use `session` parameter.
|
- Modified API tests to use `session` parameter.
|
||||||
|
- Modified `api/owner` endpoint to use a specific data structure to create new owners
|
||||||
|
|
||||||
## [1.4.1] - 2023-05-02
|
## [1.4.1] - 2023-05-02
|
||||||
|
|
||||||
|
|
33
src/Owner.hs
33
src/Owner.hs
|
@ -275,6 +275,39 @@ instance Val Owner where
|
||||||
, "crmToken" =: cT
|
, "crmToken" =: cT
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- | Type to represent informational data for Owners from UI
|
||||||
|
data OwnerData =
|
||||||
|
OwnerData
|
||||||
|
{ od_first :: T.Text
|
||||||
|
, od_last :: T.Text
|
||||||
|
, od_name :: T.Text
|
||||||
|
, od_street :: T.Text
|
||||||
|
, od_city :: T.Text
|
||||||
|
, od_state :: T.Text
|
||||||
|
, od_postal :: T.Text
|
||||||
|
, od_country :: T.Text
|
||||||
|
, od_email :: T.Text
|
||||||
|
, od_website :: T.Text
|
||||||
|
, od_phone :: T.Text
|
||||||
|
}
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
instance FromJSON OwnerData where
|
||||||
|
parseJSON =
|
||||||
|
withObject "OwnerData" $ \obj -> do
|
||||||
|
f <- obj .: "first"
|
||||||
|
l <- obj .: "last"
|
||||||
|
n <- obj .: "name"
|
||||||
|
s <- obj .: "street"
|
||||||
|
c <- obj .: "city"
|
||||||
|
st <- obj .: "state"
|
||||||
|
p <- obj .: "postal"
|
||||||
|
co <- obj .: "country"
|
||||||
|
e <- obj .: "email"
|
||||||
|
w <- obj .: "website"
|
||||||
|
ph <- obj .: "phone"
|
||||||
|
pure $ OwnerData f l n s c st p co e w ph
|
||||||
|
|
||||||
-- Database actions
|
-- Database actions
|
||||||
-- | Function to upsert an Owner
|
-- | Function to upsert an Owner
|
||||||
upsertOwner :: Owner -> Action IO ()
|
upsertOwner :: Owner -> Action IO ()
|
||||||
|
|
|
@ -938,33 +938,44 @@ routes pipe config = do
|
||||||
])
|
])
|
||||||
--Upsert owner to DB
|
--Upsert owner to DB
|
||||||
post "/api/owner" $ do
|
post "/api/owner" $ do
|
||||||
|
s <- param "session"
|
||||||
|
u <- liftAndCatchIO $ run (findUser s)
|
||||||
o <- jsonData
|
o <- jsonData
|
||||||
let q = payload (o :: Payload Owner)
|
now <- liftIO getCurrentTime
|
||||||
if not (opayconf q)
|
let q = payload (o :: Payload OwnerData)
|
||||||
then do
|
case parseUserBson =<< u of
|
||||||
_ <- liftAndCatchIO $ run (upsertOwner q)
|
Nothing -> status internalServerError500
|
||||||
status created201
|
Just u' -> do
|
||||||
else do
|
|
||||||
known <- liftAndCatchIO $ listAddresses nodeUser nodePwd
|
|
||||||
if oaddress q `elem` map addy known
|
|
||||||
then do
|
|
||||||
_ <- liftAndCatchIO $ run (upsertOwner q)
|
|
||||||
status created201
|
|
||||||
else do
|
|
||||||
vkInfo <-
|
|
||||||
liftAndCatchIO $
|
liftAndCatchIO $
|
||||||
makeZcashCall
|
run $
|
||||||
nodeUser
|
upsertOwner $
|
||||||
nodePwd
|
Owner
|
||||||
"z_importviewingkey"
|
Nothing
|
||||||
[Data.Aeson.String (T.strip (oviewkey q)), "no"]
|
(uaddress u')
|
||||||
let content = getResponseBody vkInfo :: RpcResponse Object
|
(od_name q)
|
||||||
if isNothing (err content)
|
"usd"
|
||||||
then do
|
False
|
||||||
_ <- liftAndCatchIO $ run (upsertOwner q)
|
0
|
||||||
status created201
|
False
|
||||||
else do
|
0
|
||||||
status internalServerError500
|
(od_first q)
|
||||||
|
(od_last q)
|
||||||
|
(od_email q)
|
||||||
|
(od_street q)
|
||||||
|
(od_city q)
|
||||||
|
(od_state q)
|
||||||
|
(od_postal q)
|
||||||
|
(od_phone q)
|
||||||
|
(od_website q)
|
||||||
|
(od_country q)
|
||||||
|
False
|
||||||
|
False
|
||||||
|
False
|
||||||
|
now
|
||||||
|
False
|
||||||
|
""
|
||||||
|
""
|
||||||
|
status accepted202
|
||||||
--Get items associated with the given address
|
--Get items associated with the given address
|
||||||
get "/api/items" $ do
|
get "/api/items" $ do
|
||||||
addr <- param "address"
|
addr <- param "address"
|
||||||
|
|
Loading…
Reference in a new issue