2023-03-08 17:47:09 +00:00
|
|
|
package protocol
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
func (db *sqlitePersistence) UpsertCollapsedCommunityCategory(category CollapsedCommunityCategory) error {
|
2023-03-08 17:47:09 +00:00
|
|
|
var err error
|
|
|
|
if category.Collapsed {
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = db.db.Exec("INSERT INTO collapsed_community_categories(community_id, category_id) VALUES(?,?)", category.CommunityID, category.CategoryID)
|
2023-03-08 17:47:09 +00:00
|
|
|
} else {
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = db.db.Exec("DELETE FROM collapsed_community_categories WHERE community_id = ? AND category_id = ?", category.CommunityID, category.CategoryID)
|
2023-03-08 17:47:09 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
func (db *sqlitePersistence) CollapsedCommunityCategories() ([]CollapsedCommunityCategory, error) {
|
2023-03-08 17:47:09 +00:00
|
|
|
var categories []CollapsedCommunityCategory
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
rows, err := db.db.Query(`
|
2023-03-08 17:47:09 +00:00
|
|
|
SELECT
|
|
|
|
community_id,
|
2023-03-16 13:06:34 +00:00
|
|
|
category_id
|
2023-03-08 17:47:09 +00:00
|
|
|
FROM
|
|
|
|
collapsed_community_categories
|
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var c CollapsedCommunityCategory
|
|
|
|
err = rows.Scan(
|
|
|
|
&c.CommunityID,
|
|
|
|
&c.CategoryID,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
categories = append(categories, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return categories, nil
|
|
|
|
}
|