From 3f88d06d05584ad72ebdf69b571df4c382c72810 Mon Sep 17 00:00:00 2001 From: Shubham Prajapati Date: Thu, 27 Jun 2024 00:13:49 +0530 Subject: [PATCH] updating models --- db/db.connection.go | 2 +- models/collection.go | 22 +++++++++---------- models/phygital.go | 50 ++++++++++++++++++++++---------------------- models/webxr.go | 24 ++++++++++----------- server/server.go | 8 ++++++- 5 files changed, 56 insertions(+), 50 deletions(-) diff --git a/db/db.connection.go b/db/db.connection.go index 503071d..e310061 100644 --- a/db/db.connection.go +++ b/db/db.connection.go @@ -31,7 +31,7 @@ func Init() { InitMigration(DB) - err = DB.AutoMigrate(&models.User{}, &models.Brand{}, &models.Collection{}, &models.Phygital{}, &models.WebXR{}, &models.Avatar{}, &models.Variant{}) + err = DB.Debug().AutoMigrate(&models.User{}, &models.Brand{}, &models.Collection{}, &models.Phygital{}, &models.WebXR{}, &models.Avatar{}, &models.Variant{}) if err != nil { log.Fatalf("failed to migrate database: %v", err) } diff --git a/models/collection.go b/models/collection.go index 8aebe02..c3b0796 100644 --- a/models/collection.go +++ b/models/collection.go @@ -8,17 +8,17 @@ import ( ) type Collection struct { - ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` - Name string `json:"name"` - Description string `json:"description"` - LogoImage string `json:"logo_image"` - CoverImage string `json:"cover_image"` - Category string `json:"category"` - Tags string `json:"tags"` - Status int `json:"status"` - BrandID string `json:"brand_id"` - CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` - UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` + ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` + Name string `json:"name"` + Description string `json:"description"` + LogoImage string `json:"logo_image"` + CoverImage string `json:"cover_image"` + Category map[string]interface{} `gorm:"type:jsonb" json:"category"` + Tags string `json:"tags"` + Status int `json:"status"` + BrandID string `json:"brand_id"` + CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` + UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` } func (c *Collection) BeforeCreate(tx *gorm.DB) (err error) { diff --git a/models/phygital.go b/models/phygital.go index 8d52c90..02ec3aa 100644 --- a/models/phygital.go +++ b/models/phygital.go @@ -8,31 +8,31 @@ import ( ) type Phygital struct { - ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` - Name string `json:"name"` - BrandName string `json:"brand_name"` - Category string `json:"category"` - Description string `json:"description"` - Price int `json:"price"` - Quantity int `json:"quantity"` - Royality int `json:"royality"` - Image string `json:"image"` - ProductInfo string `json:"product_info"` - Color string `json:"color"` - Size string `json:"size"` - Weight int `json:"weight"` - Material string `json:"material"` - Usage string `json:"usage"` - Quality string `json:"quality"` - Manufacturer string `json:"manufacturer"` - OriginCountry string `json:"origin_country"` - MetadataURI string `json:"metadata_uri"` - DeployerAddress string `json:"deployer_address"` - ContractAddress string `json:"contract_address"` - GraphURL string `json:"graph_url"` - CollectionID uuid.UUID `json:"collection_id"` - CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` - UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` + ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` + Name string `json:"name"` + BrandName string `json:"brand_name"` + Category map[string]interface{} `gorm:"type:jsonb" json:"category"` + Description string `json:"description"` + Price int `json:"price"` + Quantity int `json:"quantity"` + Royality int `json:"royality"` + Image string `json:"image"` + ProductInfo string `json:"product_info"` + Color string `json:"color"` + Size string `json:"size"` + Weight int `json:"weight"` + Material string `json:"material"` + Usage string `json:"usage"` + Quality string `json:"quality"` + Manufacturer string `json:"manufacturer"` + OriginCountry string `json:"origin_country"` + MetadataURI string `json:"metadata_uri"` + DeployerAddress string `json:"deployer_address"` + ContractAddress string `json:"contract_address"` + GraphURL string `json:"graph_url"` + CollectionID uuid.UUID `json:"collection_id"` + CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` + UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` } func (p *Phygital) BeforeCreate(tx *gorm.DB) (err error) { diff --git a/models/webxr.go b/models/webxr.go index 0b8b4c6..abf129a 100644 --- a/models/webxr.go +++ b/models/webxr.go @@ -8,18 +8,18 @@ import ( ) type WebXR struct { - ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` - Image360 string `json:"image360"` - Video360 string `json:"video360"` - RewardsMetadataURI string `json:"rewards_metadata_uri"` - Customizations string `json:"customizations"` - FreeNFTImage string `json:"free_nft_image"` - GoldReward string `json:"gold_reward"` - SilverReward string `json:"silver_reward"` - BronzeReward string `json:"bronze_reward"` - PhygitalID string `json:"phygital_id"` - CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` - UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` + ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` + Image360 string `json:"image360"` + Video360 string `json:"video360"` + RewardsMetadataURI string `json:"rewards_metadata_uri"` + Customizations map[string]interface{} `gorm:"type:jsonb" json:"category"` + FreeNFTImage string `json:"free_nft_image"` + GoldReward string `json:"gold_reward"` + SilverReward string `json:"silver_reward"` + BronzeReward string `json:"bronze_reward"` + PhygitalID string `json:"phygital_id"` + CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` + UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` } func (w *WebXR) BeforeCreate(tx *gorm.DB) (err error) { diff --git a/server/server.go b/server/server.go index e889720..8d8d995 100644 --- a/server/server.go +++ b/server/server.go @@ -1,6 +1,8 @@ package server import ( + "os" + "app.myriadflow.com/controllers" "app.myriadflow.com/middleware" "github.com/gin-gonic/gin" @@ -8,7 +10,11 @@ import ( func Router() { router := gin.Default() - gin.SetMode(gin.DebugMode) + if len(os.Getenv("GIN_MODE")) == 0 { + gin.SetMode(gin.ReleaseMode) + } else { + gin.SetMode(gin.DebugMode) + } // adding middleware server router.Use(middleware.CORSMiddleware())