Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Category service

Smaug#673965db98c5e138
diff --git a/backend/app/app.go b/backend/app/app.go
index 36187d91..2283a11d 100644
--- a/backend/app/app.go
+++ b/backend/app/app.go
@@ -34,6 +34,7 @@ type Services struct {
Session services.AuthService
Log services.LogService
Document services.DocumentService
+ Category services.CategoryService
Ressource services.RessourceService
}
@@ -56,6 +57,7 @@ func InitApp(config Config) *App {
Session: services.NewAuthService(app.DB),
Log: services.NewLogService(app.DB),
Document: services.NewDocumentService(app.DB),
+ Category: services.NewCategoryService(app.DB),
Ressource: services.NewRessourceService(app.DB),
}
diff --git a/backend/services/category.service.go b/backend/services/category.service.go
new file mode 100644
index 00000000..fe0617aa
--- /dev/null
+++ b/backend/services/category.service.go
@@ -0,0 +1,32 @@
+package services
+
+import (
+ "alexandrie/models"
+ "database/sql"
+)
+
+type CategoryService interface {
+ GetAllCategories(userId int64) ([]*models.Category, error)
+}
+
+func NewCategoryService(db *sql.DB) CategoryService {
+ return &Service{db: db}
+}
+
+func (s *Service) GetAllCategories(userId int64) ([]*models.Category, error) {
+ var categories []*models.Category
+ rows, err := s.db.Query("SELECT * FROM categories WHERE author_id = ? ORDER BY order", userId)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ for rows.Next() {
+ var category models.Category
+ if err := rows.Scan(&category.Id, &category.Name, &category.Icon, &category.Order, &category.Role, &category.WorkspaceId, &category.ParentId, &category.AuthorId); err != nil {
+ return nil, err
+ }
+ categories = append(categories, &category)
+ }
+ return categories, nil
+}