diff --git a/CHANGELOG.md b/CHANGELOG.md index 8355b61..9e827e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.5.1] +## [1.6.0] ### Changed - 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 diff --git a/package.yaml b/package.yaml index 4dd5145..98fe2f8 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: zgo-backend -version: 1.5.1 +version: 1.6.0 git: "https://git.vergara.tech/Vergara_Tech/zgo-backend" license: BOSL author: "Rene Vergara" diff --git a/src/Item.hs b/src/Item.hs index 6fef76e..a249370 100644 --- a/src/Item.hs +++ b/src/Item.hs @@ -12,6 +12,7 @@ import Data.Time.Clock import Database.MongoDB import GHC.Generics import Test.QuickCheck +import User -- | Type to represent a ZGo item data Item = diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index d5e8485..4c9b92b 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -1025,16 +1025,22 @@ routes pipe config = do else status noContent204 --Get items associated with the given address get "/api/items" $ do - addr <- param "address" - items <- liftAndCatchIO $ run (findItems addr) - case items of - [] -> status noContent204 - _ -> do - let pItems = map (cast' . Doc) items :: [Maybe Item] - status ok200 - Web.Scotty.json - (object - ["message" .= ("Items found!" :: String), "items" .= toJSON pItems]) + session <- param "session" + user <- liftAndCatchIO $ run (findUser session) + case cast' . Doc =<< user of + Nothing -> status unauthorized401 + Just u -> do + items <- liftAndCatchIO $ run (findItems $ uaddress u) + case items of + [] -> status noContent204 + _ -> do + let pItems = map (cast' . Doc) items :: [Maybe Item] + status ok200 + Web.Scotty.json + (object + [ "message" .= ("Items found!" :: String) + , "items" .= toJSON pItems + ]) --Upsert item post "/api/item" $ do i <- jsonData diff --git a/zgo-backend.cabal b/zgo-backend.cabal index 1ffd556..b70613d 100644 --- a/zgo-backend.cabal +++ b/zgo-backend.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: zgo-backend -version: 1.5.1 +version: 1.6.0 synopsis: Haskell Back-end for the ZGo point-of-sale application description: Please see the README at category: Web