From af87da7e45c82b3d9ad3a898f462a2c6d9a3eba0 Mon Sep 17 00:00:00 2001 From: Suraj Mahto Date: Tue, 8 Oct 2024 23:35:03 +0530 Subject: [PATCH] feat : added elevateRegion --- controllers/avatar_controller.go | 9 +++++++++ controllers/brand_controller.go | 9 +++++++++ controllers/collection_controller.go | 9 +++++++++ controllers/phygital_controller.go | 9 +++++++++ controllers/variant_controller.go | 9 +++++++++ controllers/webxr_controller.go | 9 +++++++++ models/avatar.go | 19 ++++++++++--------- models/brand.go | 13 +++++++------ models/collection.go | 25 +++++++++++++------------ models/phygital.go | 5 +++-- models/variant.go | 15 ++++++++------- models/webxr.go | 3 ++- server/server.go | 6 ++++++ 13 files changed, 103 insertions(+), 37 deletions(-) diff --git a/controllers/avatar_controller.go b/controllers/avatar_controller.go index d155e62..b1f20c1 100644 --- a/controllers/avatar_controller.go +++ b/controllers/avatar_controller.go @@ -59,6 +59,15 @@ func GetAllAvatarsByChainType(c *gin.Context) { c.JSON(http.StatusOK, avatars) } +func GetAllAvatarByRegion(c *gin.Context) { + var avatars []models.Avatar + if err := db.DB.Where("elevate_region = ?", "Africa").Find(&avatars).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, avatars) +} + func GetAllAvatars(c *gin.Context) { var avatars []models.Avatar if err := db.DB.Find(&avatars).Error; err != nil { diff --git a/controllers/brand_controller.go b/controllers/brand_controller.go index 3f0184a..6f10db2 100644 --- a/controllers/brand_controller.go +++ b/controllers/brand_controller.go @@ -68,6 +68,15 @@ func GetBrandsByManager(c *gin.Context) { c.JSON(http.StatusOK, brands) } +func GetAllBrandsByRegion(c *gin.Context) { + var brands []models.Brand + if err := db.DB.Where("elevate_region = ?", "Africa").Find(&brands).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, brands) +} + func UpdateBrand(c *gin.Context) { id := c.Param("id") var brand models.Brand diff --git a/controllers/collection_controller.go b/controllers/collection_controller.go index 9a1a0a3..e93f7a0 100644 --- a/controllers/collection_controller.go +++ b/controllers/collection_controller.go @@ -33,6 +33,15 @@ func GetCollection(c *gin.Context) { c.JSON(http.StatusOK, collection) } +func GetAllCollectionByRegion(c *gin.Context) { + var collection []models.Collection + if err := db.DB.Where("elevate_region = ?", "Africa").Find(&collection).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, collection) +} + func GetCollectionByBrandId(c *gin.Context) { brand_id := c.Param("brandId") var collection models.Collection diff --git a/controllers/phygital_controller.go b/controllers/phygital_controller.go index 7ce9f98..db8f61a 100644 --- a/controllers/phygital_controller.go +++ b/controllers/phygital_controller.go @@ -37,6 +37,15 @@ func GetPhygital(c *gin.Context) { c.JSON(http.StatusOK, oldPhygital) } +func GetAllPhygitalByRegion(c *gin.Context) { + var phygitals []models.Phygital + if err := db.DB.Where("elevate_region = ?", "Africa").Find(&phygitals).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, phygitals) +} + func GetPhygitalByWalletAddress(c *gin.Context) { deployer_address := c.Param("deployer_address") var oldPhygital models.Phygital diff --git a/controllers/variant_controller.go b/controllers/variant_controller.go index 606a5e5..8cbde3d 100644 --- a/controllers/variant_controller.go +++ b/controllers/variant_controller.go @@ -47,6 +47,15 @@ func GetAllVariantByChainType(c *gin.Context) { c.JSON(http.StatusOK, variants) } +func GetAllVariantByRegion(c *gin.Context) { + var variants []models.Variant + if err := db.DB.Where("elevate_region = ?", "Africa").Find(&variants).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, variants) +} + func GetAllVariant(c *gin.Context) { var variants []models.Variant if err := db.DB.Find(&variants).Error; err != nil { diff --git a/controllers/webxr_controller.go b/controllers/webxr_controller.go index a76276c..7f6bdad 100644 --- a/controllers/webxr_controller.go +++ b/controllers/webxr_controller.go @@ -56,6 +56,15 @@ func GetAllWebXRByChainType(c *gin.Context) { c.JSON(http.StatusOK, webxr) } +func GetAllWebxrByRegion(c *gin.Context) { + var webxr []models.WebXR + if err := db.DB.Where("elevate_region = ?", "Africa").Find(&webxr).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, webxr) +} + func GetAllWebXR(c *gin.Context) { var webxr []models.WebXR if err := db.DB.Find(&webxr).Error; err != nil { diff --git a/models/avatar.go b/models/avatar.go index c759792..22a7be7 100644 --- a/models/avatar.go +++ b/models/avatar.go @@ -8,15 +8,16 @@ import ( ) type Avatar struct { - ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` - AvatarID string `json:"avatar_id"` - URL string `json:"url"` - UserID string `json:"user_id"` - PhygitalID string `json:"phygital_id"` - AvatarVoice string `json:"avatar_voice"` - ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_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"` + AvatarID string `json:"avatar_id"` + URL string `json:"url"` + UserID string `json:"user_id"` + PhygitalID string `json:"phygital_id"` + AvatarVoice string `json:"avatar_voice"` + ElevateRegion string `json:"elevate_region"` + ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_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 (a *Avatar) BeforeCreate(tx *gorm.DB) (err error) { diff --git a/models/brand.go b/models/brand.go index 0850cf8..cbdb939 100644 --- a/models/brand.go +++ b/models/brand.go @@ -18,13 +18,13 @@ type Brand struct { ContactEmail string `json:"contact_email"` ContactPhone string `json:"contact_phone"` ShippingAddress string `json:"shipping_address"` - Website string `json:"website"` + Website string `json:"website"` Twitter string `json:"twitter"` - Instagram string `json:"instagram"` - Facebook string `json:"facebook"` + Instagram string `json:"instagram"` + Facebook string `json:"facebook"` AdditionalLink string `json:"additional_link"` - Link string `json:"link"` - Discord string `json:"discord"` + Link string `json:"link"` + Discord string `json:"discord"` AdditionalInfo string `json:"additional_info"` Industry string `json:"industry"` Tags string `json:"tags"` @@ -34,8 +34,9 @@ type Brand struct { TradeHub string `json:"trade_hub"` Blockchain string `json:"blockchain"` ChainID string `json:"chain_id"` - ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_id"` + ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_id"` ManagerID string `json:"manager_id"` //user walletaddress + ElevateRegion string `json:"elevate_region"` CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` } diff --git a/models/collection.go b/models/collection.go index 978c2d6..f6e92b2 100644 --- a/models/collection.go +++ b/models/collection.go @@ -9,18 +9,19 @@ 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 datatypes.JSON `gorm:"type:jsonb" json:"category"` - Tags string `json:"tags"` - Status int `json:"status"` - BrandID string `json:"brand_id"` - ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_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 datatypes.JSON `gorm:"type:jsonb" json:"category"` + Tags string `json:"tags"` + Status int `json:"status"` + BrandID string `json:"brand_id"` + ElevateRegion string `json:"elevate_region"` + ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_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 57fe208..e7d385b 100644 --- a/models/phygital.go +++ b/models/phygital.go @@ -13,9 +13,9 @@ type Phygital struct { Name string `json:"name"` BrandName string `json:"brand_name"` Category datatypes.JSON `gorm:"type:jsonb" json:"category"` - Tags datatypes.JSON `gorm:"type:jsonb" json:"tags"` + Tags datatypes.JSON `gorm:"type:jsonb" json:"tags"` Description string `json:"description"` - Price *float64 `json:"price" gorm:"type:decimal(20,10);"` + Price *float64 `json:"price" gorm:"type:decimal(20,10);"` Quantity int `json:"quantity"` Royality int `json:"royality"` Image string `json:"image"` @@ -33,6 +33,7 @@ type Phygital struct { DeployerAddress string `json:"deployer_address"` ContractAddress string `json:"contract_address"` GraphURL string `json:"graph_url"` + ElevateRegion string `json:"elevate_region"` CollectionID uuid.UUID `json:"collection_id"` ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_id"` CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` diff --git a/models/variant.go b/models/variant.go index b2eb832..d1b4850 100644 --- a/models/variant.go +++ b/models/variant.go @@ -8,13 +8,14 @@ import ( ) type Variant struct { - ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` - Variant string `json:"variant"` - Description string `json:"description"` - PhygitalID string `json:"phygital_id"` - ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_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"` + Variant string `json:"variant"` + Description string `json:"description"` + ElevateRegion string `json:"elevate_region"` + PhygitalID string `json:"phygital_id"` + ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_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 (v *Variant) BeforeCreate(tx *gorm.DB) (err error) { diff --git a/models/webxr.go b/models/webxr.go index ec17dd4..19b6c86 100644 --- a/models/webxr.go +++ b/models/webxr.go @@ -18,8 +18,9 @@ type WebXR struct { GoldReward string `json:"gold_reward"` SilverReward string `json:"silver_reward"` BronzeReward string `json:"bronze_reward"` + ElevateRegion string `json:"elevate_region"` PhygitalID string `json:"phygital_id"` - ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_id"` + ChaintypeID uuid.UUID `gorm:"type:uuid" json:"chaintype_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"` } diff --git a/server/server.go b/server/server.go index ca6ef8f..576a855 100644 --- a/server/server.go +++ b/server/server.go @@ -46,6 +46,7 @@ func Routes(r *gin.Engine) { r.PUT("/brands/:id", controllers.UpdateBrand) r.DELETE("/brands/:id", controllers.DeleteBrand) r.GET("/brands/manager/:manager_id", controllers.GetBrandsByManager) + r.GET("/brands/region", controllers.GetAllBrandsByRegion) // Collection routes r.POST("/collections", controllers.CreateCollection) @@ -56,6 +57,7 @@ func Routes(r *gin.Engine) { r.PUT("/collections/:id", controllers.UpdateCollection) r.PUT("/collections/brand-id/:brandId", controllers.UpdateCollectionByBrandId) r.DELETE("/collections/:id", controllers.DeleteCollection) + r.GET("/collections/region", controllers.GetAllCollectionByRegion) // Phygital routes r.POST("/phygitals", controllers.CreatePhygital) @@ -65,6 +67,7 @@ func Routes(r *gin.Engine) { r.GET("/phygitals/all", controllers.GetAllPhygital) r.PUT("/phygitals/:id", controllers.UpdatePhygital) r.DELETE("/phygitals/:id", controllers.DeletePhygital) + r.GET("/phygitals/region", controllers.GetAllPhygitalByRegion) // WebXR routes r.POST("/webxr", controllers.CreateWebXR) @@ -74,6 +77,7 @@ func Routes(r *gin.Engine) { r.PUT("/webxr/:id", controllers.UpdateWebXR) r.DELETE("/webxr/:id", controllers.DeleteWebXR) r.GET("/webxr/phygital/:phygital_id", controllers.GetWebXRByPhygitalID) + r.GET("/webxr/region", controllers.GetAllWebxrByRegion) // Avatar routes r.POST("/avatars", controllers.CreateAvatar) @@ -83,6 +87,7 @@ func Routes(r *gin.Engine) { r.PUT("/avatars/:id", controllers.UpdateAvatar) r.DELETE("/avatars/:id", controllers.DeleteAvatar) r.GET("/avatars/phygital/:phygital_id", controllers.GetAvatarByPhygitalID) + r.GET("/avatars/region", controllers.GetAllAvatarByRegion) // Variant routes r.POST("/variants", controllers.CreateVariant) @@ -91,6 +96,7 @@ func Routes(r *gin.Engine) { r.GET("/variants/all", controllers.GetAllVariant) r.PUT("/variants/:id", controllers.UpdateVariant) r.DELETE("/variants/:id", controllers.DeleteVariant) + r.GET("/variants/region", controllers.GetAllVariantByRegion) //FanToken routes r.POST("/fantoken", controllers.CreateFanToken)