Enhance GET items

This commit is contained in:
Rene Vergara 2023-05-25 10:42:40 -05:00
parent 958f04ee11
commit 857a298b96
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
5 changed files with 21 additions and 13 deletions

View file

@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.5.1] ## [1.6.0]
### Changed ### Changed
- Modified the process to mark paid orders to ensure only payments to the shop's wallet get marked as paid - Modified the process to mark paid orders to ensure only payments to the shop's wallet get marked as paid
- Modified the `items` endpoint to use the login session to identify records
## [1.5.0] - 2023-05-15 ## [1.5.0] - 2023-05-15

View file

@ -1,5 +1,5 @@
name: zgo-backend name: zgo-backend
version: 1.5.1 version: 1.6.0
git: "https://git.vergara.tech/Vergara_Tech/zgo-backend" git: "https://git.vergara.tech/Vergara_Tech/zgo-backend"
license: BOSL license: BOSL
author: "Rene Vergara" author: "Rene Vergara"

View file

@ -12,6 +12,7 @@ import Data.Time.Clock
import Database.MongoDB import Database.MongoDB
import GHC.Generics import GHC.Generics
import Test.QuickCheck import Test.QuickCheck
import User
-- | Type to represent a ZGo item -- | Type to represent a ZGo item
data Item = data Item =

View file

@ -1025,16 +1025,22 @@ routes pipe config = do
else status noContent204 else status noContent204
--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" session <- param "session"
items <- liftAndCatchIO $ run (findItems addr) user <- liftAndCatchIO $ run (findUser session)
case items of case cast' . Doc =<< user of
[] -> status noContent204 Nothing -> status unauthorized401
_ -> do Just u -> do
let pItems = map (cast' . Doc) items :: [Maybe Item] items <- liftAndCatchIO $ run (findItems $ uaddress u)
status ok200 case items of
Web.Scotty.json [] -> status noContent204
(object _ -> do
["message" .= ("Items found!" :: String), "items" .= toJSON pItems]) let pItems = map (cast' . Doc) items :: [Maybe Item]
status ok200
Web.Scotty.json
(object
[ "message" .= ("Items found!" :: String)
, "items" .= toJSON pItems
])
--Upsert item --Upsert item
post "/api/item" $ do post "/api/item" $ do
i <- jsonData i <- jsonData

View file

@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
name: zgo-backend name: zgo-backend
version: 1.5.1 version: 1.6.0
synopsis: Haskell Back-end for the ZGo point-of-sale application synopsis: Haskell Back-end for the ZGo point-of-sale application
description: Please see the README at <https://git.vergara.tech/Vergara_Tech//zgo-backend#readme> description: Please see the README at <https://git.vergara.tech/Vergara_Tech//zgo-backend#readme>
category: Web category: Web