diff --git a/config/database.go b/config/database.go index 5322c65..9e5a624 100644 --- a/config/database.go +++ b/config/database.go @@ -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) diff --git a/model/product_model.go b/model/product_model.go new file mode 100644 index 0000000..48ce531 --- /dev/null +++ b/model/product_model.go @@ -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"` +} diff --git a/model/store_model.go b/model/store_model.go new file mode 100644 index 0000000..4b7af9b --- /dev/null +++ b/model/store_model.go @@ -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"` +}