diff --git a/back/src/Guide/Database/Add.hs b/back/src/Guide/Database/Add.hs index 2f796b0..ace3757 100644 --- a/back/src/Guide/Database/Add.hs +++ b/back/src/Guide/Database/Add.hs @@ -65,8 +65,9 @@ addCategory , notes , enabled_sections , items_order + , deleted ) - VALUES ($1,$2,$3,$4,$5,$6,$7,$8) + VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) |] lift $ HT.statement CategoryRow @@ -78,6 +79,7 @@ addCategory , categoryRowNotes = "" , categoryRowEnabledSections = enabledSections , categoryRowItemsOrder = [] + , categoryRowDeleted = False } statement diff --git a/back/src/Guide/Database/Get.hs b/back/src/Guide/Database/Get.hs index 3e8dfb6..f80be0a 100644 --- a/back/src/Guide/Database/Get.hs +++ b/back/src/Guide/Database/Get.hs @@ -230,6 +230,7 @@ getCategoryRowMaybe catId = do , notes , enabled_sections , items_order + , deleted FROM categories WHERE uid = $1 |] diff --git a/back/src/Guide/Database/Schema.hs b/back/src/Guide/Database/Schema.hs index afbd7bf..7be8d89 100644 --- a/back/src/Guide/Database/Schema.hs +++ b/back/src/Guide/Database/Schema.hs @@ -179,9 +179,11 @@ v0_createTableCategories = HS.statement () $ enabled_sections text[] -- Item sections to show to users; the list of NOT NULL, -- possible section names is defined by backend items_order text[] -- Uids of items in the category; this list - NOT NULL -- specifies in what order they should be + NOT NULL, -- specifies in what order they should be -- displayed, and is necessary to allow moving -- items up and down + deleted boolean -- Whether the category is deleted + NOT NULL ); |] diff --git a/back/src/Guide/Database/Set.hs b/back/src/Guide/Database/Set.hs index de13d8b..7485b95 100644 --- a/back/src/Guide/Database/Set.hs +++ b/back/src/Guide/Database/Set.hs @@ -111,6 +111,12 @@ modifyCategoryRow catId f = do statement = [execute|UPDATE categories SET items_order = $2 WHERE uid = $1|] lift $ HT.statement (catId, new_categoryRowItemsOrder) statement + -- Update deleted + when (old_categoryRowDeleted /= new_categoryRowDeleted) $ do + let statement :: Statement (Uid Category, Bool) () + statement = [execute|UPDATE categories SET deleted = $2 WHERE uid = $1|] + lift $ HT.statement (catId, new_categoryRowDeleted) statement + -- | Delete category completly. deleteCategory :: Uid Category -> ExceptT DatabaseError Transaction () deleteCategory catId = do diff --git a/back/src/Guide/Database/Types.hs b/back/src/Guide/Database/Types.hs index 22f65a6..2505614 100644 --- a/back/src/Guide/Database/Types.hs +++ b/back/src/Guide/Database/Types.hs @@ -65,6 +65,7 @@ data CategoryRow = CategoryRow , categoryRowNotes :: Text , categoryRowEnabledSections :: Set ItemSection , categoryRowItemsOrder :: [Uid Item] + , categoryRowDeleted :: Bool } deriving (Show, Generic) -- | Make CategoryRowLenses Class to use lenses with this type. @@ -145,8 +146,8 @@ categoryRowToCategory } -- | Convert Category to CategoryRow. -categoryToRowCategory :: Category -> CategoryRow -categoryToRowCategory $(fields 'Category) = CategoryRow +categoryToRowCategory :: Category -> "deleted" :! Bool -> CategoryRow +categoryToRowCategory $(fields 'Category) (arg #deleted -> deleted) = CategoryRow { categoryRowUid = categoryUid , categoryRowTitle = categoryTitle , categoryRowCreated = categoryCreated @@ -155,6 +156,7 @@ categoryToRowCategory $(fields 'Category) = CategoryRow , categoryRowNotes = markdownBlockSource categoryNotes , categoryRowEnabledSections = categoryEnabledSections , categoryRowItemsOrder = map itemUid categoryItems + , categoryRowDeleted = deleted } where -- Ignored fields