refactor: remove db package and move database logic to service layer

This commit is contained in:
2026-03-29 21:24:09 +02:00
parent 6ff013dd2a
commit 4ebcb88628
16 changed files with 163 additions and 217 deletions

View File

@@ -1,7 +1,6 @@
package cmd
import (
"axolotl/db"
"axolotl/models"
"axolotl/output"
"axolotl/service"
@@ -14,7 +13,7 @@ import (
)
var (
uTitle, uContent, uDue string
uTitle, uContent, uDue string
uClearDue bool
uAddTags, uRmTags, uAddRels, uRmRels []string
)
@@ -22,12 +21,11 @@ var (
var updateCmd = &cobra.Command{
Use: "update <id>", Short: "Update a node", Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
svc, err := service.GetNodeService(cfg)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
svc := service.NewSQLiteNodeService(d.DB, cfg.GetUser())
node, err := svc.GetByID(args[0])
if err != nil {
@@ -65,7 +63,7 @@ var updateCmd = &cobra.Command{
} else if slices.Contains(uAddTags, "_status::open") {
uRmTags = append(uRmTags, "_status::done")
}
for _, prefix := range []string{"_type::", "_status::", "_prio::", "_namespace::"} {
if slices.ContainsFunc(uAddTags, func(e string) bool { return strings.HasPrefix(e, prefix) }) {
for _, existing := range node.Tags {
@@ -76,7 +74,6 @@ var updateCmd = &cobra.Command{
}
}
if cmd.Flags().Changed("title") {
node.Title = uTitle
}
@@ -117,7 +114,7 @@ var updateCmd = &cobra.Command{
return
}
if n, err := svc.GetByID(args[0]); err == nil {
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
output.PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
} else {
fmt.Fprintln(os.Stderr, "failed to fetch node:", err)
}