domain

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessType

type AccessType string
const (
	AccessTypeViewer  AccessType = "viewer"
	AccessTypeEditor  AccessType = "editor"
	AccessTypeComment AccessType = "comment"
	AccessTypeFull    AccessType = "full"
)

AccessTypeViewer is the access type viewer

type Action

type Action struct {
	Id string

	UserId string
	User   User `gorm:"foreignKey:UserId;references:Id"`

	// Optional: scope action to a specific space or database
	SpaceId    *string
	Space      *Space `gorm:"foreignKey:SpaceId;references:Id"`
	DatabaseId *string

	Name        string
	Description string

	// Trigger configuration
	TriggerType   ActionTriggerType
	TriggerConfig JSONB // Trigger-specific configuration

	// Action steps to execute
	Steps JSONB // [{type, config}]

	// Status
	Active       bool
	LastRunAt    *time.Time
	LastError    string
	RunCount     int
	SuccessCount int
	FailureCount int

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

Action represents an automation rule

func (*Action) TableName

func (a *Action) TableName() string

type ActionPers

type ActionPers interface {
	Create(action *Action) error
	GetById(id string) (*Action, error)
	GetByUserId(userId string) ([]Action, error)
	GetActiveByTrigger(triggerType ActionTriggerType, spaceId *string, databaseId *string) ([]Action, error)
	Update(action *Action) error
	Delete(id string) error
	IncrementSuccess(id string) error
	RecordFailure(id string, errorMsg string) error
	UpdateLastRun(id string) error
}

type ActionRun

type ActionRun struct {
	Id string

	ActionId string
	Action   Action `gorm:"foreignKey:ActionId;references:Id"`

	TriggerData JSONB // Data that triggered the action
	StepsResult JSONB // Result of each step
	Success     bool
	Error       string
	Duration    int // milliseconds

	CreatedAt time.Time
}

ActionRun records individual action execution

func (*ActionRun) TableName

func (r *ActionRun) TableName() string

type ActionRunPers

type ActionRunPers interface {
	Create(run *ActionRun) error
	GetByActionId(actionId string, limit int) ([]ActionRun, error)
}

type ActionStepType

type ActionStepType string

ActionStepType defines the types of actions that can be executed

const (
	// Notification actions
	StepSendEmail   ActionStepType = "send_email"
	StepSendSlack   ActionStepType = "send_slack"
	StepSendWebhook ActionStepType = "send_webhook"

	// Document actions
	StepCreateDocument    ActionStepType = "create_document"
	StepUpdateDocument    ActionStepType = "update_document"
	StepMoveDocument      ActionStepType = "move_document"
	StepDuplicateDocument ActionStepType = "duplicate_document"

	// Database actions
	StepCreateRow      ActionStepType = "create_row"
	StepUpdateRow      ActionStepType = "update_row"
	StepDeleteRow      ActionStepType = "delete_row"
	StepUpdateProperty ActionStepType = "update_property"

	// Misc actions
	StepAddComment  ActionStepType = "add_comment"
	StepAssignUser  ActionStepType = "assign_user"
	StepSetReminder ActionStepType = "set_reminder"
)

type ActionTriggerType

type ActionTriggerType string

ActionTriggerType defines when an action should be triggered

const (
	// Document triggers
	TriggerDocumentCreated ActionTriggerType = "document.created"
	TriggerDocumentUpdated ActionTriggerType = "document.updated"
	TriggerDocumentDeleted ActionTriggerType = "document.deleted"
	TriggerDocumentMoved   ActionTriggerType = "document.moved"
	TriggerDocumentShared  ActionTriggerType = "document.shared"

	// Database triggers
	TriggerRowCreated      ActionTriggerType = "row.created"
	TriggerRowUpdated      ActionTriggerType = "row.updated"
	TriggerRowDeleted      ActionTriggerType = "row.deleted"
	TriggerPropertyChanged ActionTriggerType = "property.changed"

	// Comment triggers
	TriggerCommentCreated  ActionTriggerType = "comment.created"
	TriggerCommentResolved ActionTriggerType = "comment.resolved"

	// Schedule triggers
	TriggerSchedule ActionTriggerType = "schedule"
)

type ApiKey

type ApiKey struct {
	Id string

	UserId string
	User   User `gorm:"foreignKey:UserId;references:Id"`

	Name        string
	KeyHash     string // Hashed API key (never store plain text)
	KeyPrefix   string // First 8 chars for identification (e.g., "zk_abc123")
	Permissions JSONB  // Scopes: ["read:documents", "write:documents", etc.]

	LastUsedAt *time.Time
	ExpiresAt  *time.Time

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

func (*ApiKey) HasScope

func (k *ApiKey) HasScope(scope ApiKeyScope) bool

func (*ApiKey) TableName

func (k *ApiKey) TableName() string

type ApiKeyPers

type ApiKeyPers interface {
	Create(apiKey *ApiKey) error
	GetById(id string) (*ApiKey, error)
	GetByKeyHash(keyHash string) (*ApiKey, error)
	GetByUserId(userId string) ([]ApiKey, error)
	Update(apiKey *ApiKey) error
	Delete(id string) error
	UpdateLastUsed(id string) error
	// Admin methods
	GetAll(limit, offset int) ([]ApiKey, int64, error)
}

type ApiKeyScope

type ApiKeyScope string

ApiKeyScope defines available permission scopes

const (
	ApiKeyScopeReadDocuments   ApiKeyScope = "read:documents"
	ApiKeyScopeWriteDocuments  ApiKeyScope = "write:documents"
	ApiKeyScopeReadSpaces      ApiKeyScope = "read:spaces"
	ApiKeyScopeWriteSpaces     ApiKeyScope = "write:spaces"
	ApiKeyScopeReadComments    ApiKeyScope = "read:comments"
	ApiKeyScopeWriteComments   ApiKeyScope = "write:comments"
	ApiKeyScopeManageWebhooks  ApiKeyScope = "manage:webhooks"
	ApiKeyScopeManageDatabases ApiKeyScope = "manage:databases"
)

type Comment

type Comment struct {
	Id string

	DocumentId string
	Document   Document `gorm:"foreignKey:DocumentId;references:Id"`

	UserId string
	User   User `gorm:"foreignKey:UserId;references:Id"`

	// For replies - optional parent comment
	ParentId *string
	Parent   *Comment `gorm:"foreignKey:ParentId;references:Id"`

	Content string

	// For inline comments - optional block reference
	BlockId *string

	Resolved  bool
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

func (*Comment) TableName

func (c *Comment) TableName() string

type CommentPers

type CommentPers interface {
	Create(comment *Comment) error
	GetById(commentId string) (*Comment, error)
	GetByDocumentId(documentId string) ([]Comment, error)
	Update(comment *Comment) error
	Delete(commentId string) error
	Resolve(commentId string, resolved bool) error
}

type Database

type Database struct {
	Id string

	SpaceId string
	Space   Space `gorm:"foreignKey:SpaceId;references:Id"`

	// Optional: database can be inline in a document
	DocumentId *string
	Document   *Document `gorm:"foreignKey:DocumentId;references:Id"`

	Name        string
	Description string
	Icon        string

	// Schema defines the columns/properties of the database
	Schema JSONBArray // [{id, name, type, options}]

	// Views configuration (table, board, calendar, etc.)
	Views JSONBArray // [{id, name, type, filter, sort, columns}]

	// Default view type
	DefaultView string

	// Type of database: "spreadsheet" or "document"
	Type DatabaseType

	Position int

	CreatedBy string
	User      User `gorm:"foreignKey:CreatedBy;references:Id"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

Database represents a Notion-like database (table)

func (*Database) TableName

func (d *Database) TableName() string

type DatabasePers

type DatabasePers interface {
	Create(database *Database) error
	GetById(id string) (*Database, error)
	GetBySpaceId(spaceId string) ([]Database, error)
	GetByDocumentId(documentId string) ([]Database, error)
	Update(database *Database) error
	Delete(id string) error
	Search(query string, userId string, spaceId *string, limit int) ([]Database, error)
}

type DatabaseRow

type DatabaseRow struct {
	Id string

	DatabaseId string
	Database   Database `gorm:"foreignKey:DatabaseId;references:Id"`

	// Properties holds the values for each column
	Properties JSONB // {propertyId: value}

	// Row can optionally have page content
	Content JSONB

	// ShowInSidebar indicates if this row should appear in sidebar (for document databases)
	ShowInSidebar bool

	CreatedBy   string
	CreatedUser User `gorm:"foreignKey:CreatedBy;references:Id"`

	UpdatedBy   string
	UpdatedUser User `gorm:"foreignKey:UpdatedBy;references:Id"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

DatabaseRow represents a row/page in a database

func (*DatabaseRow) TableName

func (r *DatabaseRow) TableName() string

type DatabaseRowPers

type DatabaseRowPers interface {
	Create(row *DatabaseRow) error
	GetById(id string) (*DatabaseRow, error)
	GetByDatabaseId(databaseId string, limit, offset int) ([]DatabaseRow, error)
	GetByDatabaseIdWithOptions(databaseId string, options RowQueryOptions) ([]DatabaseRow, error)
	GetRowCount(databaseId string) (int64, error)
	GetRowCountWithFilter(databaseId string, filter *FilterConfig) (int64, error)
	Update(row *DatabaseRow) error
	Delete(id string) error
	BulkDelete(ids []string) error
}

type DatabaseType

type DatabaseType string

DatabaseType defines the types of databases

const (
	DatabaseTypeSpreadsheet DatabaseType = "spreadsheet"
	DatabaseTypeDocument    DatabaseType = "document"
)

type Document

type Document struct {
	Id   string
	Name string
	Slug string

	Config   DocumentConfig
	Metadata JSONB

	ParentId *string
	Parent   *Document `gorm:"foreignKey:ParentId;references:Id"`

	SpaceId string
	Space   Space `gorm:"foreignKey:SpaceId;references:Id"`

	Public bool

	// Permissions spécifiques au document (optionnelles)
	Permissions []Permission `gorm:"foreignKey:DocumentId;references:Id"`

	Content datatypes.JSON

	Position int

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

func (*Document) CanManagePermissions

func (d *Document) CanManagePermissions(userId string) bool

CanManagePermissions returns true if the user can manage document permissions This requires being owner of the document OR admin/owner of the space

func (*Document) HasPermission

func (d *Document) HasPermission(userId string, requiredRole PermissionRole) bool

func (*Document) TableName

func (d *Document) TableName() string

type DocumentConfig

type DocumentConfig struct {
	FullWidth        bool   `json:"full_width"`
	Icon             string `json:"icon"`
	Lock             bool   `json:"lock"`
	HeaderBackground string `json:"header_background"`
}

func (*DocumentConfig) Scan

func (dc *DocumentConfig) Scan(value any) error

Scan implements the sql.Scanner interface

func (DocumentConfig) Value

func (dc DocumentConfig) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type DocumentPers

type DocumentPers interface {
	GetDocumentWithPermissions(documentId, userId string) (*Document, error)
	GetDocumentByIdOrSlugWithUserPermissions(spaceId string, id *string, slug *string, userId string) (*Document, error)
	GetRootDocumentsFromSpaceWithUserPermissions(spaceId, userId string) ([]Document, error)
	GetChildDocumentsWithUserPermissions(parentId, userId string) ([]Document, error)
	Create(document *Document, userId string) error
	Update(document *Document, userId string) error
	Delete(documentId, userId string) error
	Move(documentId string, newParentId *string, userId string) (*Document, error)
	// Trash management
	GetDeletedDocuments(spaceId, userId string) ([]Document, error)
	Restore(documentId, userId string) error
	// Public sharing
	SetPublic(documentId string, public bool, userId string) error
	GetPublicDocument(spaceId string, id *string, slug *string) (*Document, error)
	// Search
	Search(query string, userId string, spaceId *string, limit int) ([]Document, error)
	// Reorder
	Reorder(spaceId string, items []ReorderItem, userId string) error
	GetMaxPosition(spaceId string, parentId *string) (int, error)
}

type DocumentVersion

type DocumentVersion struct {
	Id string

	DocumentId string
	Document   Document `gorm:"foreignKey:DocumentId;references:Id"`

	// User who created this version
	UserId string
	User   User `gorm:"foreignKey:UserId;references:Id"`

	// Version number (auto-incremented per document)
	Version int

	// Snapshot of document at this version
	Name    string
	Content datatypes.JSON
	Config  DocumentConfig

	// Optional description of changes
	Description string

	CreatedAt time.Time
}

func (*DocumentVersion) TableName

func (v *DocumentVersion) TableName() string

type DocumentVersionPers

type DocumentVersionPers interface {
	Create(version *DocumentVersion) error
	GetByDocumentId(documentId string, limit int, offset int) ([]DocumentVersion, error)
	GetById(versionId string) (*DocumentVersion, error)
	GetLatestVersion(documentId string) (*DocumentVersion, error)
	GetVersionCount(documentId string) (int64, error)
	DeleteOldVersions(documentId string, keepCount int) error
}

type Drawing

type Drawing struct {
	Id string

	SpaceId string
	Space   Space `gorm:"foreignKey:SpaceId;references:Id"`

	// Optional: drawing can be inline in a document
	DocumentId *string
	Document   *Document `gorm:"foreignKey:DocumentId;references:Id"`

	Name string
	Icon string // Emoji icon for the drawing

	// Excalidraw data
	Elements JSONBArray // Excalidraw elements array
	AppState JSONB      // Excalidraw appState
	Files    JSONB      // Embedded files (images in base64)

	// Base64 PNG thumbnail for preview
	Thumbnail string

	Position int

	CreatedBy string
	User      User `gorm:"foreignKey:CreatedBy;references:Id"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

Drawing represents an Excalidraw drawing

func (*Drawing) TableName

func (d *Drawing) TableName() string

type DrawingPers

type DrawingPers interface {
	Create(drawing *Drawing) error
	GetById(id string) (*Drawing, error)
	GetBySpaceId(spaceId string) ([]Drawing, error)
	GetByDocumentId(documentId string) ([]Drawing, error)
	Update(drawing *Drawing) error
	Delete(id string) error
}

type Favorite

type Favorite struct {
	Id string

	UserId string
	User   User `gorm:"foreignKey:UserId;references:Id"`

	DocumentId string
	Document   Document `gorm:"foreignKey:DocumentId;references:Id"`

	SpaceId string
	Space   Space `gorm:"foreignKey:SpaceId;references:Id"`

	Position int

	CreatedAt time.Time
}

func (*Favorite) TableName

func (f *Favorite) TableName() string

type FavoritePers

type FavoritePers interface {
	GetLatestFavoritePositionByUser(userId string) (int, error)
	Create(favorite *Favorite) error
	Delete(documentId, userId string, spaceId string) error
	GetMyFavoritesWithMainDocumentInformations(userId string) ([]Favorite, error)
	UpdateFavoritePosition(favorite *Favorite) error
	GetFavoriteByIdAndUserId(favoriteId, userId string) (*Favorite, error)
}

type FilterConfig

type FilterConfig struct {
	And []FilterRule `json:"and,omitempty"`
	Or  []FilterRule `json:"or,omitempty"`
}

FilterConfig defines the filter configuration with AND/OR groups

type FilterRule

type FilterRule struct {
	Property  string      `json:"property"`
	Condition string      `json:"condition"` // eq, neq, gt, lt, gte, lte, contains, is_empty, is_not_empty
	Value     interface{} `json:"value,omitempty"`
}

FilterRule defines a single filter condition

type Group

type Group struct {
	Id          string
	Name        string
	Description string

	Role Role `gorm:"type:role;default:'user'"`

	// Owner is the username of the user who owns the group
	OwnerId string
	// OwnerUser is the user who owns the group
	OwnerUser User `gorm:"foreignKey:OwnerId;references:Id"`

	// Members is the list of users who are members of the group
	Members []User `gorm:"many2many:group_members;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

func (*Group) TableName

func (g *Group) TableName() string

type GroupPers

type GroupPers interface {
	Create(group *Group) error
	GetById(groupId string) (*Group, error)
	GetAll(limit, offset int) ([]Group, int64, error)
	Update(group *Group) error
	Delete(groupId string) error

	// Member management
	AddMember(groupId, userId string) error
	RemoveMember(groupId, userId string) error
	GetMembers(groupId string) ([]User, error)
}

GroupPers defines the persistence interface for groups

type JSONB

type JSONB map[string]any

JSONB is a map of strings to interfaces

func (*JSONB) Scan

func (j *JSONB) Scan(value any) error

Scan implements the sql.Scanner interface

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type JSONBArray

type JSONBArray []any

JSONBArray is a slice that can be stored as JSONB in PostgreSQL

func (*JSONBArray) Scan

func (j *JSONBArray) Scan(value any) error

Scan implements the sql.Scanner interface

func (JSONBArray) Value

func (j JSONBArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Member

type Member struct {
	Id     string
	Type   MemberType
	Access AccessType
}

type MemberType

type MemberType string
const (
	MemberTypeUser  MemberType = "user"
	MemberTypeGroup MemberType = "group"
)

MemberType is the type of member

type MemberWithUsersOrGroups

type MemberWithUsersOrGroups struct {
	Member
	User  User
	Group Group
}

MemberWithUser is a model for a member with user information

type Members

type Members []Member

type MembersWithUsersOrGroups

type MembersWithUsersOrGroups []MemberWithUsersOrGroups

type Permission

type Permission struct {
	Id   string
	Type PermissionType // "space", "document", "database", "drawing"

	// Resource IDs - only one should be set based on Type
	SpaceId    *string
	Space      *Space `gorm:"foreignKey:SpaceId;references:Id"`
	DocumentId *string
	Document   *Document `gorm:"foreignKey:DocumentId;references:Id"`
	DatabaseId *string
	Database   *Database `gorm:"foreignKey:DatabaseId;references:Id"`
	DrawingId  *string
	Drawing    *Drawing `gorm:"foreignKey:DrawingId;references:Id"`

	// Target - either a user or a group
	UserId *string
	User   *User `gorm:"foreignKey:UserId;references:Id"`

	GroupId *string
	Group   *Group `gorm:"foreignKey:GroupId;references:Id"`

	Role PermissionRole

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

Permission represents a unified permission entry for any resource type

func (*Permission) TableName

func (p *Permission) TableName() string

type PermissionPers

type PermissionPers interface {
	// Generic methods
	ListByResource(resourceType PermissionType, resourceId string) ([]Permission, error)
	GetByResourceAndUser(resourceType PermissionType, resourceId, userId string) (*Permission, error)
	GetByResourceAndGroup(resourceType PermissionType, resourceId, groupId string) (*Permission, error)
	UpsertUser(resourceType PermissionType, resourceId, userId string, role PermissionRole) error
	UpsertGroup(resourceType PermissionType, resourceId, groupId string, role PermissionRole) error
	DeleteUser(resourceType PermissionType, resourceId, userId string) error
	DeleteGroup(resourceType PermissionType, resourceId, groupId string) error
}

PermissionPers is the persistence interface for permissions

type PermissionRole

type PermissionRole string

PermissionRole defines the role/access level

const (
	PermissionRoleOwner  PermissionRole = "owner"  // Full control, can manage permissions
	PermissionRoleAdmin  PermissionRole = "admin"  // Admin access (for spaces)
	PermissionRoleEditor PermissionRole = "editor" // Can edit
	PermissionRoleViewer PermissionRole = "viewer" // Read-only
	PermissionRoleDenied PermissionRole = "denied" // Explicitly deny access
)

type PermissionType

type PermissionType string

PermissionType defines the type of resource the permission applies to

const (
	PermissionTypeSpace    PermissionType = "space"
	PermissionTypeDocument PermissionType = "document"
	PermissionTypeDatabase PermissionType = "database"
	PermissionTypeDrawing  PermissionType = "drawing"
)

type PropertyType

type PropertyType string

PropertyType defines the types of properties/columns

const (
	PropertyTypeTitle       PropertyType = "title"
	PropertyTypeText        PropertyType = "text"
	PropertyTypeNumber      PropertyType = "number"
	PropertyTypeSelect      PropertyType = "select"
	PropertyTypeMultiSelect PropertyType = "multi_select"
	PropertyTypeDate        PropertyType = "date"
	PropertyTypeCheckbox    PropertyType = "checkbox"
	PropertyTypeUrl         PropertyType = "url"
	PropertyTypeEmail       PropertyType = "email"
	PropertyTypePhone       PropertyType = "phone"
	PropertyTypeRelation    PropertyType = "relation"
	PropertyTypeRollup      PropertyType = "rollup"
	PropertyTypeFormula     PropertyType = "formula"
	PropertyTypeCreatedTime PropertyType = "created_time"
	PropertyTypeUpdatedTime PropertyType = "updated_time"
	PropertyTypeCreatedBy   PropertyType = "created_by"
	PropertyTypeUpdatedBy   PropertyType = "updated_by"
	PropertyTypeFiles       PropertyType = "files"
	PropertyTypePerson      PropertyType = "person"
)

type ReorderItem

type ReorderItem struct {
	Id       string
	Position int
}

ReorderItem represents a single item in a reorder request

type Role

type Role string
const (
	RoleUser  Role = "user"
	RoleAdmin Role = "admin"
	RoleGest  Role = "guest"
)

type RowQueryOptions

type RowQueryOptions struct {
	Filter *FilterConfig
	Sort   []SortRule
	Limit  int
	Offset int
}

RowQueryOptions contains filter and sort options for row queries

type Session

type Session struct {
	Id     string
	UserId string

	User      User `gorm:"foreignKey:UserId;references:Id"`
	UserAgent string
	IpAddress string
	ExpiresAt time.Time

	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*Session) TableName

func (s *Session) TableName() string

type SessionPers

type SessionPers interface {
	Create(session *Session) error
	GetById(id string) (*Session, error)
	DeleteById(id string) error
}

type SortRule

type SortRule struct {
	PropertyId string `json:"property_id"`
	Direction  string `json:"direction"` // "asc" or "desc"
}

SortRule defines a sort condition

type Space

type Space struct {
	Id   string
	Name string

	Slug      string
	Icon      string
	IconColor string

	Type SpaceType

	OwnerId *string
	Owner   *User `gorm:"foreignKey:OwnerId;references:Id"`

	Documents []Document `gorm:"foreignKey:SpaceId;references:Id"`

	Permissions []Permission `gorm:"foreignKey:SpaceId;references:Id"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

func (*Space) GetUserRole

func (s *Space) GetUserRole(userId string) *PermissionRole

func (*Space) HasPermission

func (s *Space) HasPermission(userId string, requiredRole PermissionRole) bool

func (*Space) TableName

func (s *Space) TableName() string

type SpacePers

type SpacePers interface {
	Create(space *Space) error
	GetSpacesForUser(userId string) ([]Space, error)
	GetSpaceById(spaceId string) (*Space, error)
	Update(space *Space) error
	Delete(spaceId string) error
	// Admin methods
	GetAll(limit, offset int) ([]Space, int64, error)
}

type SpaceType

type SpaceType string

SpaceType is the type of space

const (
	// SpaceTypePublic is the public space type
	SpaceTypePublic SpaceType = "public"
	// SpaceTypePrivate is the private space type
	SpaceTypePrivate SpaceType = "private"
	// SpaceTypeRestricted is the restricted space type
	SpaceTypeRestricted SpaceType = "restricted"
	// SpaceTypePersonal is the personal space type
	SpaceTypePersonal SpaceType = "personal"
)

type User

type User struct {
	Id       string
	Username string
	Email    string
	Password string

	AvatarUrl   string
	Preferences JSONB
	Active      bool

	Role Role `gorm:"type:role;default:'user'"`

	Favorites []Favorite `gorm:"foreignKey:UserId;references:Id"`

	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*User) TableName

func (u *User) TableName() string

type UserPers

type UserPers interface {
	GetByUsername(username string) (User, error)
	GetByEmail(email string) (User, error)
	GetById(id string) (User, error)
	Create(user User) (User, error)
	Update(user *User) error
	UpdatePassword(userId, hashedPassword string) error
	// Admin methods
	GetAll(limit, offset int) ([]User, int64, error)
	UpdateRole(userId string, role Role) error
	UpdateActive(userId string, active bool) error
	Delete(userId string) error
}

type ViewType

type ViewType string

ViewType defines the types of database views

const (
	ViewTypeTable    ViewType = "table"
	ViewTypeBoard    ViewType = "board"
	ViewTypeCalendar ViewType = "calendar"
	ViewTypeGallery  ViewType = "gallery"
	ViewTypeList     ViewType = "list"
	ViewTypeTimeline ViewType = "timeline"
)

type Webhook

type Webhook struct {
	Id string

	UserId string
	User   User `gorm:"foreignKey:UserId;references:Id"`

	// Optional: scope webhook to a specific space
	SpaceId *string
	Space   *Space `gorm:"foreignKey:SpaceId;references:Id"`

	Name   string
	Url    string
	Secret string // Used for signature verification

	// Events to trigger on
	Events JSONB // ["document.created", "document.updated", etc.]

	// Status
	Active       bool
	LastError    string
	LastErrorAt  *time.Time
	SuccessCount int
	FailureCount int

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

func (*Webhook) HasEvent

func (w *Webhook) HasEvent(event WebhookEvent) bool

func (*Webhook) TableName

func (w *Webhook) TableName() string

type WebhookDelivery

type WebhookDelivery struct {
	Id string

	WebhookId string
	Webhook   Webhook `gorm:"foreignKey:WebhookId;references:Id"`

	Event      string
	Payload    JSONB
	StatusCode int
	Response   string
	Duration   int // milliseconds
	Success    bool

	CreatedAt time.Time
}

WebhookDelivery records individual delivery attempts

func (*WebhookDelivery) TableName

func (d *WebhookDelivery) TableName() string

type WebhookDeliveryPers

type WebhookDeliveryPers interface {
	Create(delivery *WebhookDelivery) error
	GetByWebhookId(webhookId string, limit int) ([]WebhookDelivery, error)
}

type WebhookEvent

type WebhookEvent string

Webhook events

const (
	WebhookEventDocumentCreated WebhookEvent = "document.created"
	WebhookEventDocumentUpdated WebhookEvent = "document.updated"
	WebhookEventDocumentDeleted WebhookEvent = "document.deleted"
	WebhookEventCommentCreated  WebhookEvent = "comment.created"
	WebhookEventCommentResolved WebhookEvent = "comment.resolved"
	WebhookEventSpaceCreated    WebhookEvent = "space.created"
	WebhookEventSpaceUpdated    WebhookEvent = "space.updated"
)

type WebhookPers

type WebhookPers interface {
	Create(webhook *Webhook) error
	GetById(id string) (*Webhook, error)
	GetByUserId(userId string) ([]Webhook, error)
	GetActiveByEvent(event WebhookEvent, spaceId *string) ([]Webhook, error)
	Update(webhook *Webhook) error
	Delete(id string) error
	IncrementSuccess(id string) error
	RecordFailure(id string, errorMsg string) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL