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

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
}