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.

Remove old utils functions (move to a service)

Smaug6739f6211dfe0435
diff --git a/backend/models/document.model.go b/backend/models/document.model.go
index 6072ea39..0e004ddb 100644
--- a/backend/models/document.model.go
+++ b/backend/models/document.model.go
@@ -1,13 +1,8 @@
package models
-import (
- "database/sql"
- "errors"
-)
-
type Document struct {
- Id int64 `json:"id"`
- Name string `json:"name"`
+ Id int64 `json:"id" form:"id" binding:"omitempty"`
+ Name string `json:"name" `
Description *string `json:"description"`
Tags *string `json:"tags"`
Category *int64 `json:"category"`
@@ -19,61 +14,3 @@ type Document struct {
CreatedTimestamp int64 `json:"created_timestamp"`
UpdatedTimestamp int64 `json:"updated_timestamp"`
}
-
-func (m *Model) GetAllDocuments(authorId int64) ([]Document, error) {
- var documents []Document
- rows, err := m.DB.Query("SELECT id, name, description, tags, category, parent_id, accessibility, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ? ORDER BY name", authorId)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- for rows.Next() {
- var doc Document
- err := rows.Scan(
- &doc.Id, &doc.Name, &doc.Description, &doc.Tags, &doc.Category,
- &doc.ParentId, &doc.Accessibility, &doc.AuthorId, &doc.CreatedTimestamp, &doc.UpdatedTimestamp,
- )
- if err != nil {
- return nil, err
- }
- documents = append(documents, doc)
- }
- return documents, nil
-}
-
-func (m *Model) GetDocument(id, authorId int64) (*Document, error) {
- var doc Document
- err := m.DB.QueryRow("SELECT id, name, description, tags, category, parent_id, accessibility, author_id, created_timestamp, updated_timestamp FROM documents WHERE id = ? AND author_id = ?", id, authorId).Scan(
- &doc.Id, &doc.Name, &doc.Description, &doc.Tags, &doc.Category,
- &doc.ParentId, &doc.Accessibility, &doc.AuthorId, &doc.CreatedTimestamp, &doc.UpdatedTimestamp,
- )
- if errors.Is(err, sql.ErrNoRows) {
- return nil, nil
- }
- if err != nil {
- return nil, err
- }
- return &doc, nil
-}
-
-func (m *Model) AddDocument(doc Document) error {
- _, err := m.DB.Exec(
- "INSERT INTO documents (id, name, description, tags, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- doc.Id, doc.Name, doc.Description, doc.Tags, doc.Category, doc.ParentId, doc.Accessibility, doc.ContentMarkdown, doc.ContentHtml, doc.AuthorId, doc.CreatedTimestamp, doc.UpdatedTimestamp,
- )
- return err
-}
-
-func (m *Model) UpdateDocument(id int64, doc Document) error {
- _, err := m.DB.Exec(
- "UPDATE documents SET name = ?, description = ?, tags = ?, category = ?, parent_id = ?, accessibility = ?, content_markdown = ?, content_html = ?, updated_timestamp = ? WHERE id = ?",
- doc.Name, doc.Description, doc.Tags, doc.Category, doc.ParentId, doc.Accessibility, doc.ContentMarkdown, doc.ContentHtml, doc.UpdatedTimestamp, id,
- )
- return err
-}
-
-func (m *Model) DeleteDocument(id int64) error {
- _, err := m.DB.Exec("DELETE FROM documents WHERE id = ?", id)
- return err
-}