chores: refactor struct and structure project
This commit is contained in:
@@ -5,17 +5,10 @@ import (
|
||||
)
|
||||
|
||||
type Category struct {
|
||||
ID string `gorm:"primaryKey" json:"id"`
|
||||
Code string `gorm:"not null;unique" json:"code"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
}
|
||||
|
||||
type CategoryModel struct {
|
||||
ID string `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"not null;unique" json:"name"`
|
||||
Code string `gorm:"not null" json:"code"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
DeletedAt time.Time `gorm:"default:null" json:"deleted_at"`
|
||||
}
|
||||
|
||||
+3
-3
@@ -58,8 +58,8 @@ func (db *DB) Migrate() error {
|
||||
// &Tag{},
|
||||
// &Category{},
|
||||
// &News{},
|
||||
&NewsModel{},
|
||||
&TagModel{},
|
||||
&CategoryModel{},
|
||||
&News{},
|
||||
&Tag{},
|
||||
&Category{},
|
||||
)
|
||||
}
|
||||
|
||||
+6
-20
@@ -6,30 +6,16 @@ import (
|
||||
|
||||
type News struct {
|
||||
ID string `gorm:"primaryKey" json:"id"`
|
||||
Title string `gorm:"default:null" json:"title"`
|
||||
Tags []Tag `gorm:"many2many:news_tags" json:"tags"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Categories []Category `gorm:"many2many:news_categories" json:"categories"`
|
||||
Content string `gorm:"default:null" json:"content"`
|
||||
LiveAt time.Time `gorm:"not null" json:"live_at"`
|
||||
AuthorID string `gorm:"not null" json:"author_id"`
|
||||
Tags []Tag `gorm:"many2many:news_tags" json:"tags"`
|
||||
IsPremium bool `gorm:"default:false" json:"is_premium"`
|
||||
Slug string `gorm:"default:null" json:"slug"`
|
||||
FeaturedImage string `gorm:"default:null" json:"featured_image"`
|
||||
AuthorID string `gorm:"not null" json:"author_id"`
|
||||
LiveAt time.Time `gorm:"not null" json:"live_at"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
}
|
||||
|
||||
type NewsModel struct {
|
||||
ID string `gorm:"primaryKey" json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Categories []CategoryModel `gorm:"many2many:news_categories" json:"categories"`
|
||||
Tags []TagModel `gorm:"many2many:news_tags" json:"tags"`
|
||||
IsPremium bool `gorm:"default:false" json:"is_premium"`
|
||||
Slug string `gorm:"default:null" json:"slug"`
|
||||
FeaturedImage string `gorm:"default:null" json:"featured_image"`
|
||||
AuthorID string `gorm:"not null" json:"author_id"`
|
||||
LiveAt time.Time `gorm:"not null" json:"live_at"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
DeletedAt time.Time `gorm:"default:null" json:"deleted_at"`
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ type Staff struct {
|
||||
Password string `gorm:"not null" json:"password"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
DeletedAt time.Time `gorm:"default:null" json:"deleted_at"`
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ type Subscribe struct {
|
||||
AutoRenew bool `gorm:"default:true"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
|
||||
DeletedAt time.Time `gorm:"default:null" json:"deleted_at"`
|
||||
|
||||
SubscribePlan SubscribePlan `gorm:"foreignKey:SubscribePlanID;constraint:OnDelete:CASCADE"`
|
||||
SubscribePlan SubscribePlan `gorm:"foreignKey:SubscribePlanID;constraint:OnDelete:CASCADE" json:"subscribe_plan"`
|
||||
}
|
||||
|
||||
type SubscribePlan struct {
|
||||
|
||||
@@ -5,17 +5,10 @@ import (
|
||||
)
|
||||
|
||||
type Tag struct {
|
||||
ID string `gorm:"primaryKey" json:"id"`
|
||||
Code string `gorm:"not null;unique" json:"code"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
}
|
||||
|
||||
type TagModel struct {
|
||||
ID string `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"not null;unique" json:"name"`
|
||||
Code string `gorm:"not null" json:"code"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
DeletedAt time.Time `gorm:"default:null" json:"deleted_at"`
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ type User struct {
|
||||
Phone string `gorm:"default:not null;unique" json:"phone"`
|
||||
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
DeletedAt time.Time `gorm:"default:null" json:"deleted_at"`
|
||||
|
||||
Subscribe Subscribe `gorm:"foreignKey:SubscribeID;constraint:OnDelete:CASCADE"`
|
||||
Subscribe Subscribe `gorm:"foreignKey:SubscribeID;constraint:OnDelete:CASCADE" json:"subscribe"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user