From 94fa2e5688a325eac3f4d7374eeb96e882371bf1 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Tue, 15 Mar 2022 23:17:40 +0300 Subject: [PATCH] Categories: Draft the API for categories package --- files/files.go | 5 +++++ hyphae/categories/tags.go | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 hyphae/categories/tags.go diff --git a/files/files.go b/files/files.go index af913e9..1bc4e9d 100644 --- a/files/files.go +++ b/files/files.go @@ -15,6 +15,7 @@ var paths struct { configPath string tokensJSON string userCredentialsJSON string + categoriesJSON string } // HyphaeDir returns the path to hyphae storage. @@ -38,6 +39,9 @@ func TokensJSON() string { return paths.tokensJSON } // UserCredentialsJSON returns the path to the JSON user credentials storage. func UserCredentialsJSON() string { return paths.userCredentialsJSON } +// CategoriesJSON returns the path to the JSON categories storage. +func CategoriesJSON() string { return paths.categoriesJSON } + // FileInRoot returns full path for the given filename if it was placed in the root of the wiki structure. func FileInRoot(filename string) string { return filepath.Join(cfg.WikiDir, filename) } @@ -67,6 +71,7 @@ func PrepareWikiRoot() error { paths.userCredentialsJSON = filepath.Join(cfg.WikiDir, "users.json") paths.tokensJSON = filepath.Join(paths.cacheDir, "tokens.json") + paths.categoriesJSON = filepath.Join(cfg.WikiDir, "tags.json") return nil } diff --git a/hyphae/categories/tags.go b/hyphae/categories/tags.go new file mode 100644 index 0000000..73315ed --- /dev/null +++ b/hyphae/categories/tags.go @@ -0,0 +1,44 @@ +// Package categories provides category management. +// +// As per the long pondering, this is how categories (cats for short) +// work in Mycorrhiza: +// +// - Cats are not hyphae. Cats are separate entities. This is not as +// vibeful as I would have wanted, but seems to be more practical +// due to //the reasons//. +// - Cats are stored outside of git. Instead, they are stored in a +// JSON file, path to which is determined by files.CategoriesJSON. +// - Due to not being stored in git, no cat history is tracked, and +// cat operations are not mentioned on the recent changes page. +// - For cat A, if there are 0 hyphae in the cat, cat A does not +// exist. If there are 1 or more hyphae in the cat, cat A exists. +package categories + +// For WithHypha and Contents, should the results be sorted? + +// WithHypha returns what categories have the given hypha. +func WithHypha(hyphaName string) (categoryList []string) { + panic("todo") + return +} + +// Contents returns what hyphae are in the category. If the returned slice is empty, the category does not exist, and vice versa. +func Contents(catName string) (hyphaList []string) { + panic("todo") + return +} + +// AddHyphaToCategory adds the hypha to the category and updates the records on the disk. If the hypha is already in the category, nothing happens. This operation is async-safe. +func AddHyphaToCategory(hyphaName, catName string) { + for _, cat := range WithHypha(hyphaName) { + if cat == catName { + return + } + } + panic("todo") +} + +// RemoveHyphaFromCategory removes the hypha from the category and updates the records on the disk. If the hypha is not in the category, nothing happens. This operation is async-safe. +func RemoveHyphaFromCategory(hyphaName, catName string) { + panic("todo") +}