61 lines
2.3 KiB
Go
61 lines
2.3 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
// ModelUser represents a user in the system
|
|
type ModelUser struct {
|
|
bun.BaseModel `bun:"table:users,alias:u"`
|
|
|
|
ID int64 `bun:"id,pk,autoincrement,type:bigint"`
|
|
Username string `bun:"username,notnull,type:varchar(100),unique:idx_username"`
|
|
Email string `bun:"email,notnull,type:varchar(255),unique"`
|
|
Password string `bun:"password,notnull,type:varchar(255)"`
|
|
FirstName *string `bun:"first_name,type:varchar(100)"`
|
|
LastName *string `bun:"last_name,type:varchar(100)"`
|
|
Bio *string `bun:"bio,type:text"`
|
|
IsActive bool `bun:"is_active,type:boolean"`
|
|
CreatedAt time.Time `bun:"created_at,type:timestamp"`
|
|
UpdatedAt time.Time `bun:"updated_at,type:timestamp"`
|
|
|
|
Posts []*ModelPost `bun:"rel:has-many,join:id=user_id"`
|
|
}
|
|
|
|
// ModelPost represents a blog post
|
|
type ModelPost struct {
|
|
bun.BaseModel `bun:"table:posts,alias:p"`
|
|
|
|
ID int64 `bun:"id,pk,autoincrement,type:bigint"`
|
|
UserID int64 `bun:"user_id,notnull,type:bigint"`
|
|
Title string `bun:"title,notnull,type:varchar(255)"`
|
|
Slug string `bun:"slug,notnull,type:varchar(255),unique:idx_slug"`
|
|
Content string `bun:"content,notnull,type:text"`
|
|
Excerpt *string `bun:"excerpt,type:text"`
|
|
Published bool `bun:"published,type:boolean"`
|
|
ViewCount int64 `bun:"view_count,type:bigint"`
|
|
PublishedAt *time.Time `bun:"published_at,type:timestamp,nullzero"`
|
|
CreatedAt time.Time `bun:"created_at,type:timestamp"`
|
|
UpdatedAt time.Time `bun:"updated_at,type:timestamp"`
|
|
|
|
User *ModelUser `bun:"rel:belongs-to,join:user_id=id"`
|
|
Comments []*ModelComment `bun:"rel:has-many,join:id=post_id"`
|
|
}
|
|
|
|
// ModelComment represents a comment on a post
|
|
type ModelComment struct {
|
|
bun.BaseModel `bun:"table:comments,alias:c"`
|
|
|
|
ID int64 `bun:"id,pk,autoincrement,type:bigint"`
|
|
PostID int64 `bun:"post_id,notnull,type:bigint"`
|
|
UserID *int64 `bun:"user_id,type:bigint"`
|
|
Content string `bun:"content,notnull,type:text"`
|
|
CreatedAt time.Time `bun:"created_at,type:timestamp"`
|
|
UpdatedAt time.Time `bun:"updated_at,type:timestamp"`
|
|
|
|
Post *ModelPost `bun:"rel:belongs-to,join:post_id=id"`
|
|
User *ModelUser `bun:"rel:belongs-to,join:user_id=id"`
|
|
}
|