From e3a8edbf94885309699ba3ec29b25a21e09d00f2 Mon Sep 17 00:00:00 2001 From: willbasky Date: Thu, 31 Oct 2019 19:25:09 +0500 Subject: [PATCH 1/4] fix getItem --- back/src/Guide/Api/Methods.hs | 17 ++++++++++++++--- back/src/Guide/Api/Types.hs | 31 +++++++++++++++++++++++-------- back/src/Guide/State.hs | 1 + 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/back/src/Guide/Api/Methods.hs b/back/src/Guide/Api/Methods.hs index 0e2ea535..fb68dccc 100644 --- a/back/src/Guide/Api/Methods.hs +++ b/back/src/Guide/Api/Methods.hs @@ -97,10 +97,21 @@ deleteCategory catId = ---------------------------------------------------------------------------- -- | Get item by item ID. -getItem :: Uid Item -> Guider CItemFull -getItem itemId = +-- +-- Pass 'True' to ignore disabled sections and get full item. +getItem :: Bool -> Uid Item -> Guider CItemFull +getItem isIgnored itemId = logHandler "getItem" [attr "itemId" itemId] $ do - toCItemFull <$> getItemOrFail itemId + item <- getItemOrFail itemId + sections <- categoryEnabledSections <$> dbQuery (GetCategoryByItem itemId) + if isIgnored then pure $ toCItemFull allSections item + else pure $ toCItemFull sections item + where + allSections = S.fromList + [ ItemProsConsSection + , ItemEcosystemSection + , ItemNotesSection + ] -- | Create a new item, given the name. -- diff --git a/back/src/Guide/Api/Types.hs b/back/src/Guide/Api/Types.hs index e00de5dd..cf2f0eb6 100644 --- a/back/src/Guide/Api/Types.hs +++ b/back/src/Guide/Api/Types.hs @@ -153,6 +153,10 @@ data ItemSite route = ItemSite { _getItem :: route :- Summary "Get item by id" :> ErrorResponse 404 "Item not found" + :> "ignore selections" + :> QueryParam' '[Required, Strict, + Description "Ignore disabled sections to get full item"] + "bool" Bool :> "item" :> Capture "itemId" (Uid Item) :> Get '[JSON] CItemFull @@ -505,7 +509,7 @@ toCCategoryFull $(fields 'Category) = CCategoryFull , ccfStatus = categoryStatus , ccfDescription = toCMarkdown categoryNotes , ccfSections = categoryEnabledSections - , ccfItems = fmap toCItemFull categoryItems + , ccfItems = fmap (toCItemFull categoryEnabledSections) categoryItems } where -- Ignored fields @@ -674,23 +678,34 @@ instance ToSchema CItemFull where field "toc" . inlineSchema . description ?= "Table of contents" -- | Factory to create a 'CItemFull' from an 'Item' -toCItemFull :: Item -> CItemFull -toCItemFull $(fields 'Item) = CItemFull +-- +-- Pass to 'Set ItemSection' all kinds of sections +-- to ignore disabled sections and get full item content. +toCItemFull :: Set ItemSection -> Item -> CItemFull +toCItemFull selections $(fields 'Item) = CItemFull { cifId = itemUid , cifName = itemName , cifCreated = itemCreated , cifHackage = itemHackage , cifSummary = toCMarkdown itemSummary - , cifPros = fmap toCTrait itemPros - , cifCons = fmap toCTrait itemCons - , cifEcosystem = toCMarkdown itemEcosystem - , cifNotes = toCMarkdown itemNotes + , cifPros = fmap toCTrait pros + , cifCons = fmap toCTrait cons + , cifEcosystem = toCMarkdown ecosystem + , cifNotes = toCMarkdown notes , cifLink = itemLink , cifToc = map toCTocHeading (markdownTreeTOC itemNotes) } where - -- Ignored fields _ = (itemProsDeleted, itemConsDeleted) + ecosystem = if (ItemEcosystemSection `elem` selections) + then itemEcosystem + else toMarkdownBlock "" + notes = if (ItemNotesSection `elem` selections) + then itemNotes + else toMarkdownTree "" "" + (pros, cons) = if (ItemProsConsSection `elem` selections) + then (itemPros, itemCons) + else ([],[]) ---------------------------------------------------------------------------- -- CTrait diff --git a/back/src/Guide/State.hs b/back/src/Guide/State.hs index dce91b65..992a105f 100644 --- a/back/src/Guide/State.hs +++ b/back/src/Guide/State.hs @@ -845,6 +845,7 @@ deriving instance Show GetGlobalState -- category deriving instance Show GetCategories deriving instance Show GetCategoryMaybe +deriving instance Show GetCategoryByItem deriving instance Show AddCategory deriving instance Show DeleteCategory deriving instance Show SetCategoryGroup From 97acd06b60215c9ac5a8ddc33036fe917b3bd40c Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Thu, 31 Oct 2019 16:37:32 +0000 Subject: [PATCH 2/4] Regenerate swagger.json --- back/swagger.json | 67 +++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/back/swagger.json b/back/swagger.json index 82fcf27c..9508468b 100644 --- a/back/swagger.json +++ b/back/swagger.json @@ -443,6 +443,44 @@ } }, "paths": { + "/ignore selections/item/{itemId}": { + "get": { + "summary": "Get item by id", + "responses": { + "404": { + "description": "Item not found" + }, + "200": { + "schema": { + "$ref": "#/definitions/CItemFull" + }, + "description": "" + } + }, + "produces": [ + "application/json;charset=utf-8" + ], + "parameters": [ + { + "required": true, + "in": "query", + "name": "bool", + "type": "boolean", + "description": "Ignore disabled sections to get full item" + }, + { + "format": "Item ID", + "required": true, + "in": "path", + "name": "itemId", + "type": "string" + } + ], + "tags": [ + "02. Items" + ] + } + }, "/item/{itemId}/info": { "put": { "summary": "Set item's info", @@ -725,35 +763,6 @@ } }, "/item/{itemId}": { - "get": { - "summary": "Get item by id", - "responses": { - "404": { - "description": "Item not found" - }, - "200": { - "schema": { - "$ref": "#/definitions/CItemFull" - }, - "description": "" - } - }, - "produces": [ - "application/json;charset=utf-8" - ], - "parameters": [ - { - "format": "Item ID", - "required": true, - "in": "path", - "name": "itemId", - "type": "string" - } - ], - "tags": [ - "02. Items" - ] - }, "delete": { "summary": "Delete an item", "responses": { From 3f53ff647940d2cfab3d816ba06fcbd731c5cc37 Mon Sep 17 00:00:00 2001 From: willbasky Date: Sat, 2 Nov 2019 20:09:23 +0500 Subject: [PATCH 3/4] Fix tests --- back/src/Guide/Api/Types.hs | 2 +- back/tests/ApiSpec.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/back/src/Guide/Api/Types.hs b/back/src/Guide/Api/Types.hs index cf2f0eb6..f32c68f3 100644 --- a/back/src/Guide/Api/Types.hs +++ b/back/src/Guide/Api/Types.hs @@ -153,7 +153,7 @@ data ItemSite route = ItemSite { _getItem :: route :- Summary "Get item by id" :> ErrorResponse 404 "Item not found" - :> "ignore selections" + :> "ignore_selections" :> QueryParam' '[Required, Strict, Description "Ignore disabled sections to get full item"] "bool" Bool diff --git a/back/tests/ApiSpec.hs b/back/tests/ApiSpec.hs index ba9e5088..4b84f85d 100644 --- a/back/tests/ApiSpec.hs +++ b/back/tests/ApiSpec.hs @@ -81,7 +81,7 @@ tests = describe "api" $ do it "get item by id" $ do req <- withItem $ \(Uid itemId) -> do request <- makeRequest - (Path $ "item/" <> toString itemId) + (Path $ "ignore_selections/item/" <> toString itemId <> "?bool=false") (Method "GET") (Status 200 "OK", _ :: CItemFull) <- runRequest request pure request From 63eaee60b53eaabe3287e91288abcfd4546ff0f8 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Sat, 2 Nov 2019 15:19:49 +0000 Subject: [PATCH 4/4] Regenerate swagger.json --- back/swagger.json | 76 +++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/back/swagger.json b/back/swagger.json index 9508468b..393bda4c 100644 --- a/back/swagger.json +++ b/back/swagger.json @@ -443,44 +443,6 @@ } }, "paths": { - "/ignore selections/item/{itemId}": { - "get": { - "summary": "Get item by id", - "responses": { - "404": { - "description": "Item not found" - }, - "200": { - "schema": { - "$ref": "#/definitions/CItemFull" - }, - "description": "" - } - }, - "produces": [ - "application/json;charset=utf-8" - ], - "parameters": [ - { - "required": true, - "in": "query", - "name": "bool", - "type": "boolean", - "description": "Ignore disabled sections to get full item" - }, - { - "format": "Item ID", - "required": true, - "in": "path", - "name": "itemId", - "type": "string" - } - ], - "tags": [ - "02. Items" - ] - } - }, "/item/{itemId}/info": { "put": { "summary": "Set item's info", @@ -1075,6 +1037,44 @@ ] } }, + "/ignore_selections/item/{itemId}": { + "get": { + "summary": "Get item by id", + "responses": { + "404": { + "description": "Item not found" + }, + "200": { + "schema": { + "$ref": "#/definitions/CItemFull" + }, + "description": "" + } + }, + "produces": [ + "application/json;charset=utf-8" + ], + "parameters": [ + { + "required": true, + "in": "query", + "name": "bool", + "type": "boolean", + "description": "Ignore disabled sections to get full item" + }, + { + "format": "Item ID", + "required": true, + "in": "path", + "name": "itemId", + "type": "string" + } + ], + "tags": [ + "02. Items" + ] + } + }, "/item/{itemId}/trait/{traitId}/move": { "post": { "summary": "Move trait",