1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-22 20:31:31 +03:00

Add deleted field to category (#373)

* Add deleted field to category

* fix forgotten
This commit is contained in:
Vladislav Sabanov 2019-08-14 21:37:42 +05:00 committed by mergify[bot]
parent 83f77c9309
commit 156d794991
5 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -230,6 +230,7 @@ getCategoryRowMaybe catId = do
, notes
, enabled_sections
, items_order
, deleted
FROM categories
WHERE uid = $1
|]

View File

@ -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
);
|]

View File

@ -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

View File

@ -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