feat: add model store and product, migrate to database
This commit is contained in:
parent
638e34e186
commit
98e1b81213
|
@ -38,17 +38,31 @@ func ConnectDatabase() {
|
|||
&model.Village{},
|
||||
// ==wilayah indonesia==
|
||||
|
||||
// ==main feature==
|
||||
// ==============main feature==============
|
||||
// =>user preparation<=
|
||||
&model.User{},
|
||||
&model.Role{},
|
||||
&model.UserPin{},
|
||||
&model.Address{},
|
||||
// =>user preparation<=
|
||||
|
||||
// =>store preparation<=
|
||||
&model.Store{},
|
||||
&model.Product{},
|
||||
&model.ProductImage{},
|
||||
// =>store preparation<=
|
||||
// ==============main feature==============
|
||||
|
||||
// ==============additional content========
|
||||
&model.Article{},
|
||||
&model.Banner{},
|
||||
&model.InitialCoint{},
|
||||
|
||||
// =>Trash Model<=
|
||||
&model.TrashCategory{},
|
||||
&model.TrashDetail{},
|
||||
// ==main feature==
|
||||
// =>Trash Model<=
|
||||
// ==============additional content========
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("Error performing auto-migration: %v", err)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Product struct {
|
||||
ID string `gorm:"primaryKey;type:uuid;default:uuid_generate_v4();unique;not null" json:"id"`
|
||||
StoreID string `gorm:"type:uuid;not null" json:"storeId"`
|
||||
Store Store `gorm:"foreignKey:StoreID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"store"`
|
||||
ProductName string `gorm:"not null" json:"productName"`
|
||||
ProductImages []ProductImage `gorm:"foreignKey:ProductID;constraint:OnDelete:CASCADE;" json:"productImages"`
|
||||
Quantity int `gorm:"not null" json:"quantity"`
|
||||
Saled int `gorm:"default:0" json:"saled"`
|
||||
CreatedAt time.Time `gorm:"default:current_timestamp" json:"createdAt"`
|
||||
UpdatedAt time.Time `gorm:"default:current_timestamp" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type ProductImage struct {
|
||||
ID string `gorm:"primaryKey;type:uuid;default:uuid_generate_v4();unique;not null" json:"id"`
|
||||
ProductID string `gorm:"type:uuid;not null" json:"productId"`
|
||||
Product Product `gorm:"foreignKey:ProductID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"product"`
|
||||
ImageURL string `gorm:"not null" json:"imageURL"`
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Store struct {
|
||||
ID string `gorm:"primaryKey;type:uuid;default:uuid_generate_v4();unique;not null" json:"id"`
|
||||
UserID string `gorm:"type:uuid;not null" json:"userId"`
|
||||
User User `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user"`
|
||||
StoreName string `gorm:"not null" json:"storeName"`
|
||||
StoreLogo string `gorm:"not null" json:"storeLogo"`
|
||||
StoreBanner string `gorm:"not null" json:"storeBanner"`
|
||||
StoreInfo string `gorm:"not null" json:"storeInfo"`
|
||||
StoreAddressID string `gorm:"type:uuid;not null" json:"storeAddressId"`
|
||||
StoreAddress Address `gorm:"foreignKey:StoreAddressID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"storeAddress"`
|
||||
Followers int `gorm:"default:0" json:"followers"`
|
||||
Products []Product `gorm:"foreignKey:StoreID;constraint:OnDelete:CASCADE;" json:"products"`
|
||||
CreatedAt time.Time `gorm:"default:current_timestamp" json:"createdAt"`
|
||||
UpdatedAt time.Time `gorm:"default:current_timestamp" json:"updatedAt"`
|
||||
}
|
Loading…
Reference in New Issue