fix: readers and linting issues
Some checks failed
CI / Test (1.24) (push) Failing after -24m50s
CI / Test (1.25) (push) Failing after -24m42s
CI / Build (push) Successful in -25m49s
CI / Lint (push) Successful in -25m36s

This commit is contained in:
2025-12-19 22:28:24 +02:00
parent d9225a7310
commit aad5db5175
16 changed files with 1237 additions and 80 deletions

View File

@@ -0,0 +1,60 @@
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"`
}

View File

@@ -0,0 +1,18 @@
package models
import (
"time"
"github.com/uptrace/bun"
)
type User struct {
bun.BaseModel `bun:"table:users,alias:u"`
ID int64 `bun:"id,pk,autoincrement,type:bigint"`
Email string `bun:"email,notnull,type:varchar(255),unique"`
Name string `bun:"name,type:text"`
Age *int `bun:"age,type:integer"`
IsActive bool `bun:"is_active,type:boolean"`
CreatedAt time.Time `bun:"created_at,type:timestamp,default:now()"`
}

View File

@@ -0,0 +1,65 @@
package models
import (
"time"
)
// ModelUser represents a user in the system
type ModelUser struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement;type:bigint"`
Username string `gorm:"column:username;type:varchar(100);not null;uniqueIndex:idx_username"`
Email string `gorm:"column:email;type:varchar(255);not null;uniqueIndex"`
Password string `gorm:"column:password;type:varchar(255);not null"`
FirstName *string `gorm:"column:first_name;type:varchar(100)"`
LastName *string `gorm:"column:last_name;type:varchar(100)"`
Bio *string `gorm:"column:bio;type:text"`
IsActive bool `gorm:"column:is_active;type:boolean;default:true"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:now()"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:now()"`
Posts []*ModelPost `gorm:"foreignKey:UserID;association_foreignkey:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
Comments []*ModelComment `gorm:"foreignKey:UserID;association_foreignkey:ID;constraint:OnDelete:SET NULL"`
}
func (ModelUser) TableName() string {
return "users"
}
// ModelPost represents a blog post
type ModelPost struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement;type:bigint"`
UserID int64 `gorm:"column:user_id;type:bigint;not null;index:idx_user_id"`
Title string `gorm:"column:title;type:varchar(255);not null"`
Slug string `gorm:"column:slug;type:varchar(255);not null;uniqueIndex:idx_slug"`
Content string `gorm:"column:content;type:text;not null"`
Excerpt *string `gorm:"column:excerpt;type:text"`
Published bool `gorm:"column:published;type:boolean;default:false"`
ViewCount int64 `gorm:"column:view_count;type:bigint;default:0"`
PublishedAt *time.Time `gorm:"column:published_at;type:timestamp"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:now()"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:now()"`
User *ModelUser `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
Comments []*ModelComment `gorm:"foreignKey:PostID;association_foreignkey:ID;constraint:OnDelete:CASCADE"`
}
func (ModelPost) TableName() string {
return "posts"
}
// ModelComment represents a comment on a post
type ModelComment struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement;type:bigint"`
PostID int64 `gorm:"column:post_id;type:bigint;not null;index:idx_post_id"`
UserID *int64 `gorm:"column:user_id;type:bigint;index:idx_user_id"`
Content string `gorm:"column:content;type:text;not null"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:now()"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:now()"`
Post *ModelPost `gorm:"foreignKey:PostID;references:ID;constraint:OnDelete:CASCADE"`
User *ModelUser `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:SET NULL"`
}
func (ModelComment) TableName() string {
return "comments"
}

View File

@@ -0,0 +1,18 @@
package models
import (
"time"
)
type User struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement;type:bigint"`
Email string `gorm:"column:email;type:varchar(255);not null"`
Name string `gorm:"column:name;type:text"`
Age *int `gorm:"column:age;type:integer"`
IsActive bool `gorm:"column:is_active;type:boolean"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:now()"`
}
func (User) TableName() string {
return "users"
}