build multi tenant

This commit is contained in:
2025-10-12 15:47:00 +07:00
parent e466e2f801
commit 1fbb202002
24 changed files with 1947 additions and 29 deletions

View File

@@ -1,8 +1,14 @@
package model
import "time"
// Project represent a collection of related tasks (tags of Habitica)
type Project struct {
ID int64 `storm:"id,increment",json:"id"`
Title string `storm:"index",json:"title"`
UUID string `storm:"unique",json:"uuid,omitempty"`
ID int64 `storm:"id,increment" db:"id" json:"id"`
TenantID int64 `db:"tenant_id" json:"tenant_id"`
UserID int64 `db:"user_id" json:"user_id"`
Title string `storm:"index" db:"title" json:"title"`
UUID string `storm:"unique" db:"uuid" json:"uuid,omitempty"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}

View File

@@ -1,12 +1,18 @@
package model
import "time"
// Task represent a task - the building block of the TaskManager app
type Task struct {
ID int64 `storm:"id,increment",json:"id"`
ProjectID int64 `storm:"index",json:"project_id"`
UUID string `storm:"unique",json:"uuid,omitempty"`
Title string `json:"text"`
Details string `json:"notes"`
Completed bool `storm:"index",json:"completed"`
DueDate int64 `storm:"index",json:"due_date,omitempty"`
ID int64 `storm:"id,increment" db:"id" json:"id"`
TenantID int64 `db:"tenant_id" json:"tenant_id"`
UserID int64 `db:"user_id" json:"user_id"`
ProjectID int64 `storm:"index" db:"project_id" json:"project_id"`
UUID string `storm:"unique" db:"uuid" json:"uuid,omitempty"`
Title string `db:"title" json:"text"`
Details string `db:"details" json:"notes"`
Completed bool `storm:"index" db:"completed" json:"completed"`
DueDate *int64 `storm:"index" db:"due_date" json:"due_date,omitempty"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}

39
model/user.go Normal file
View File

@@ -0,0 +1,39 @@
package model
import (
"time"
)
// Tenant represents a tenant in the multi-tenant system
type Tenant struct {
ID int64 `db:"id" json:"id"`
Name string `db:"name" json:"name"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}
// User represents a user within a tenant
type User struct {
ID int64 `db:"id" json:"id"`
TenantID int64 `db:"tenant_id" json:"tenant_id"`
Username string `db:"username" json:"username"`
Email string `db:"email" json:"email"`
PasswordHash string `db:"password_hash" json:"-"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}
// UserSession represents a user session for authentication
type UserSession struct {
ID int64 `db:"id" json:"id"`
UserID int64 `db:"user_id" json:"user_id"`
Token string `db:"token" json:"token"`
ExpiresAt time.Time `db:"expires_at" json:"expires_at"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
}
// UserContext holds the current user and tenant information
type UserContext struct {
User *User
Tenant *Tenant
}