move src file to seperate direcotry

This commit is contained in:
2026-04-01 22:29:20 +02:00
parent 228cefb921
commit e42397cc7a
30 changed files with 0 additions and 0 deletions
+103
View File
@@ -0,0 +1,103 @@
package models
import (
"slices"
"strings"
)
type Node struct {
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
DueDate string `json:"due_date,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Tags []string `json:"tags,omitempty"`
Relations map[string][]string `json:"relations,omitempty"`
}
func NewNode() *Node {
return &Node{
Relations: make(map[string][]string),
}
}
func (n *Node) AddTag(tag string) {
if tag == "" {
return
}
// If it's a property (name::value format), replace any existing tag with the same prefix.
if idx := strings.Index(tag, "::"); idx >= 0 {
prefix := tag[:idx+2]
var newTags []string
for _, t := range n.Tags {
if !strings.HasPrefix(t, prefix) {
newTags = append(newTags, t)
}
}
n.Tags = newTags
}
if !slices.Contains(n.Tags, tag) {
n.Tags = append(n.Tags, tag)
}
}
func (n *Node) RemoveTag(tag string) {
var newTags []string
for _, t := range n.Tags {
if t != tag {
newTags = append(newTags, t)
}
}
n.Tags = newTags
}
func (n *Node) AddRelation(relType RelType, target string) {
if n.Relations == nil {
n.Relations = make(map[string][]string)
}
if relType == RelAssignee || relType == RelCreated || relType == RelInNamespace {
n.Relations[string(relType)] = []string{target}
return
}
if !slices.Contains(n.Relations[string(relType)], target) {
n.Relations[string(relType)] = append(n.Relations[string(relType)], target)
}
}
func (n *Node) RemoveRelation(relType RelType, target string) {
if n.Relations == nil {
return
}
var newTgts []string
for _, tgt := range n.Relations[string(relType)] {
if tgt != target {
newTgts = append(newTgts, tgt)
}
}
if len(newTgts) == 0 {
delete(n.Relations, string(relType))
} else {
n.Relations[string(relType)] = newTgts
}
}
func (n *Node) GetProperty(k string) string {
prefix := "_" + k + "::"
for _, t := range n.Tags {
if strings.HasPrefix(t, prefix) {
return strings.TrimPrefix(t, prefix)
}
}
return ""
}
func (n *Node) GetDisplayTags() []string {
var tags []string
for _, t := range n.Tags {
if !strings.HasPrefix(t, "_") {
tags = append(tags, t)
}
}
return tags
}
+24
View File
@@ -0,0 +1,24 @@
package models
type RelType string
type Rel struct {
Type RelType
Target string
}
const (
RelBlocks RelType = "blocks"
RelSubtask RelType = "subtask"
RelRelated RelType = "related"
RelCreated RelType = "created"
RelAssignee RelType = "assignee"
RelInNamespace RelType = "in_namespace"
RelMentions RelType = "mentions"
// Permission rels (subject → object). Levels are inclusive and transitive.
RelCanRead RelType = "can_read" // level 1: visible in list/show
RelCanCreateRel RelType = "can_create_rel" // level 2: can create relations between nodes
RelCanWrite RelType = "can_write" // level 3: can update/delete
RelHasOwnership RelType = "has_ownership" // level 4: sole owner; deletion cascades to owned nodes
)