From 1874ae24eba210785d8327b45686847ea9fe0169 Mon Sep 17 00:00:00 2001 From: Shubham Prajapati Date: Thu, 27 Jun 2024 21:53:38 +0530 Subject: [PATCH] mofying all update functionallity --- controllers/collection_controller.go | 102 +------------------ controllers/phygital_controller.go | 145 ++++----------------------- controllers/webxr_controller.go | 92 +---------------- go.mod | 7 +- go.sum | 28 +++++- models/collection.go | 23 +++-- models/phygital.go | 51 +++++----- models/webxr.go | 25 ++--- 8 files changed, 108 insertions(+), 365 deletions(-) diff --git a/controllers/collection_controller.go b/controllers/collection_controller.go index 1b96bd6..7fe63fc 100644 --- a/controllers/collection_controller.go +++ b/controllers/collection_controller.go @@ -1,15 +1,11 @@ package controllers import ( - "encoding/json" - "fmt" "net/http" - "time" "app.myriadflow.com/db" "app.myriadflow.com/models" "github.com/gin-gonic/gin" - "github.com/google/uuid" ) func CreateCollection(c *gin.Context) { @@ -29,115 +25,25 @@ func CreateCollection(c *gin.Context) { func GetCollection(c *gin.Context) { id := c.Param("id") - var collection Collection + var collection models.Collection if err := db.DB.First(&collection, "id = ?", id).Error; err != nil { c.JSON(http.StatusNotFound, gin.H{"error": "Collection not found"}) return } - var categoryMap map[string]interface{} - if len(collection.Category) > 0 { - err := json.Unmarshal(collection.Category, &categoryMap) - if err != nil { - c.JSON(http.StatusInternalServerError, fmt.Errorf("error unmarshalling category for collection ID %s: %v", collection.ID, err)) - // return nil, fmt.Errorf("error unmarshalling category for collection ID %s: %v", collection.ID, err) - } - } - newCollections := models.Collection{ - ID: collection.ID, - Name: collection.Name, - Description: collection.Description, - LogoImage: collection.LogoImage, - CoverImage: collection.CoverImage, - Category: categoryMap, - Tags: collection.Tags, - Status: collection.Status, - BrandID: collection.BrandID, - CreatedAt: collection.CreatedAt, - UpdatedAt: collection.UpdatedAt, - } - - c.JSON(http.StatusOK, newCollections) -} - -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 []byte `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"` + c.JSON(http.StatusOK, collection) } // get all connection api func GetAllCollections(c *gin.Context) { - var collections []Collection + var collections []models.Collection if err := db.DB.Find(&collections).Error; err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } - // // Convert Category []byte to map[string]interface{} - // for i := range collections { - // var categoryMap map[string]interface{} - // if err := json.Unmarshal(collections[i].Category, &categoryMap); err != nil { - // c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to unmarshal category"}) - // return - // } - // collections[i].Category = categoryMap - // } - data, errors := convertCollections(collections) - if errors != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": errors}) - return - } - - c.JSON(http.StatusOK, data) -} - -func convertCollections(oldCollections []Collection) ([]models.Collection, error) { - newCollections := make([]models.Collection, len(oldCollections)) - - for i, oldCollection := range oldCollections { - var categoryMap map[string]interface{} - if len(oldCollection.Category) > 0 { - err := json.Unmarshal(oldCollection.Category, &categoryMap) - if err != nil { - return nil, fmt.Errorf("error unmarshalling category for collection ID %s: %v", oldCollection.ID, err) - } - } - - newCollections[i] = models.Collection{ - ID: oldCollection.ID, - Name: oldCollection.Name, - Description: oldCollection.Description, - LogoImage: oldCollection.LogoImage, - CoverImage: oldCollection.CoverImage, - Category: categoryMap, - Tags: oldCollection.Tags, - Status: oldCollection.Status, - BrandID: oldCollection.BrandID, - CreatedAt: oldCollection.CreatedAt, - UpdatedAt: oldCollection.UpdatedAt, - } - } - - return newCollections, nil + c.JSON(http.StatusOK, collections) } -// func GetAllCollections(c *gin.Context) { -// var collections []Collection -// if err := db.DB.Raw("SELECT * FROM collections").Scan(&collections).Error; err != nil { -// c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) -// return -// } -// c.JSON(http.StatusOK, collections) -// } - func UpdateCollection(c *gin.Context) { id := c.Param("id") var collection models.Collection diff --git a/controllers/phygital_controller.go b/controllers/phygital_controller.go index 9f7e931..5b71081 100644 --- a/controllers/phygital_controller.go +++ b/controllers/phygital_controller.go @@ -2,15 +2,12 @@ package controllers import ( "encoding/json" - "fmt" "net/http" - "time" "app.myriadflow.com/db" "app.myriadflow.com/models" "github.com/gin-gonic/gin" - "github.com/google/uuid" ) func CreatePhygital(c *gin.Context) { @@ -31,84 +28,52 @@ func CreatePhygital(c *gin.Context) { func GetPhygital(c *gin.Context) { id := c.Param("id") - var oldPhygital Phygital + var oldPhygital models.Phygital if err := db.DB.First(&oldPhygital, "id = ?", id).Error; err != nil { c.JSON(http.StatusNotFound, gin.H{"error": "Phygital not found"}) return } - var categoryMap map[string]interface{} - if len(oldPhygital.Category) > 0 { - err := json.Unmarshal(oldPhygital.Category, &categoryMap) - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Errorf("error unmarshalling category for Phygital ID %s: %v", oldPhygital.ID, err)}) - } - } - newPhygitals := models.Phygital{ - ID: oldPhygital.ID, - Name: oldPhygital.Name, - BrandName: oldPhygital.BrandName, - Category: categoryMap, - Description: oldPhygital.Description, - Price: oldPhygital.Price, - Quantity: oldPhygital.Quantity, - Royality: oldPhygital.Royality, - Image: oldPhygital.Image, - ProductInfo: oldPhygital.ProductInfo, - Color: oldPhygital.Color, - Size: oldPhygital.Size, - Weight: oldPhygital.Weight, - Material: oldPhygital.Material, - Usage: oldPhygital.Usage, - Quality: oldPhygital.Quality, - Manufacturer: oldPhygital.Manufacturer, - OriginCountry: oldPhygital.OriginCountry, - MetadataURI: oldPhygital.MetadataURI, - DeployerAddress: oldPhygital.DeployerAddress, - ContractAddress: oldPhygital.ContractAddress, - GraphURL: oldPhygital.GraphURL, - CollectionID: oldPhygital.CollectionID, - CreatedAt: oldPhygital.CreatedAt, - UpdatedAt: oldPhygital.UpdatedAt, - } - - c.JSON(http.StatusOK, newPhygitals) + c.JSON(http.StatusOK, oldPhygital) } // get all phygital api func GetAllPhygital(c *gin.Context) { - var phygitals []Phygital + var phygitals []models.Phygital if err := db.DB.Find(&phygitals).Error; err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } - data, errr := convertPhygitals(phygitals) - if errr != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": errr.Error()}) - return - } - c.JSON(http.StatusOK, data) + c.JSON(http.StatusOK, phygitals) } func UpdatePhygital(c *gin.Context) { id := c.Param("id") - var phygital models.Phygital - if err := db.DB.First(&phygital, "id = ?", id).Error; err != nil { + var Phygital models.Phygital + + if err := db.DB.First(&Phygital, "id = ?", id).Error; err != nil { c.JSON(http.StatusNotFound, gin.H{"error": "Phygital not found"}) return } - if err := c.ShouldBindJSON(&phygital); err != nil { + var input models.Phygital + if err := c.ShouldBindJSON(&input); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } - - if err := db.DB.Save(&phygital).Error; err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + var err1 error + // Ensure the input Category is properly converted to JSON + input.Category, err1 = json.Marshal(input.Category) + if err1 != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err1.Error()}) return } - c.JSON(http.StatusOK, phygital) + // Update fields + db.DB.Model(&Phygital).Updates(input) + + c.JSON(http.StatusOK, Phygital) + } func DeletePhygital(c *gin.Context) { @@ -120,75 +85,3 @@ func DeletePhygital(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "Phygital deleted successfully"}) } - -func convertPhygitals(oldPhygitals []Phygital) ([]models.Phygital, error) { - newPhygitals := make([]models.Phygital, len(oldPhygitals)) - - for i, oldPhygital := range oldPhygitals { - var categoryMap map[string]interface{} - if len(oldPhygital.Category) > 0 { - err := json.Unmarshal(oldPhygital.Category, &categoryMap) - if err != nil { - return nil, fmt.Errorf("error unmarshalling category for Phygital ID %s: %v", oldPhygital.ID, err) - } - } - - newPhygitals[i] = models.Phygital{ - ID: oldPhygital.ID, - Name: oldPhygital.Name, - BrandName: oldPhygital.BrandName, - Category: categoryMap, - Description: oldPhygital.Description, - Price: oldPhygital.Price, - Quantity: oldPhygital.Quantity, - Royality: oldPhygital.Royality, - Image: oldPhygital.Image, - ProductInfo: oldPhygital.ProductInfo, - Color: oldPhygital.Color, - Size: oldPhygital.Size, - Weight: oldPhygital.Weight, - Material: oldPhygital.Material, - Usage: oldPhygital.Usage, - Quality: oldPhygital.Quality, - Manufacturer: oldPhygital.Manufacturer, - OriginCountry: oldPhygital.OriginCountry, - MetadataURI: oldPhygital.MetadataURI, - DeployerAddress: oldPhygital.DeployerAddress, - ContractAddress: oldPhygital.ContractAddress, - GraphURL: oldPhygital.GraphURL, - CollectionID: oldPhygital.CollectionID, - CreatedAt: oldPhygital.CreatedAt, - UpdatedAt: oldPhygital.UpdatedAt, - } - } - - return newPhygitals, nil -} - -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 []byte `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"` -} diff --git a/controllers/webxr_controller.go b/controllers/webxr_controller.go index 06a37f6..d08ef85 100644 --- a/controllers/webxr_controller.go +++ b/controllers/webxr_controller.go @@ -1,18 +1,11 @@ package controllers import ( - "encoding/json" - "fmt" - "time" + "net/http" "app.myriadflow.com/db" - "app.myriadflow.com/models" - - "net/http" - "github.com/gin-gonic/gin" - "github.com/google/uuid" ) func CreateWebXR(c *gin.Context) { @@ -32,99 +25,24 @@ func CreateWebXR(c *gin.Context) { func GetWebXR(c *gin.Context) { id := c.Param("id") - var webxr WebXR + var webxr models.WebXR if err := db.DB.First(&webxr, "id = ?", id).Error; err != nil { c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) return } - var customizationsMap map[string]interface{} - if len(webxr.Customizations) > 0 { - err1 := json.Unmarshal(webxr.Customizations, &customizationsMap) - if err1 != nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "error": fmt.Errorf("error unmarshalling customizations for WebXR ID %s: %v", webxr.ID, err1.Error()), - }) - return - } - } - - newWebXRs := models.WebXR{ - ID: webxr.ID, - Image360: webxr.Image360, - Video360: webxr.Video360, - RewardsMetadataURI: webxr.RewardsMetadataURI, - Customizations: customizationsMap, - FreeNFTImage: webxr.FreeNFTImage, - GoldReward: webxr.GoldReward, - SilverReward: webxr.SilverReward, - BronzeReward: webxr.BronzeReward, - PhygitalID: webxr.PhygitalID, - CreatedAt: webxr.CreatedAt, - UpdatedAt: webxr.UpdatedAt, - } - - c.JSON(http.StatusOK, newWebXRs) -} -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 []byte `gorm:"type:jsonb" 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"` + c.JSON(http.StatusOK, webxr) } // get all webxr func GetAllWebXR(c *gin.Context) { - var webxr []WebXR + var webxr []models.WebXR if err := db.DB.Find(&webxr).Error; err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } - data, errors := convertWebXRs(webxr) - if errors != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": errors.Error()}) - return - } - c.JSON(http.StatusOK, data) -} - -func convertWebXRs(oldWebXRs []WebXR) ([]models.WebXR, error) { - newWebXRs := make([]models.WebXR, len(oldWebXRs)) - - for i, oldWebXR := range oldWebXRs { - var customizationsMap map[string]interface{} - if len(oldWebXR.Customizations) > 0 { - err := json.Unmarshal(oldWebXR.Customizations, &customizationsMap) - if err != nil { - return nil, fmt.Errorf("error unmarshalling customizations for WebXR ID %s: %v", oldWebXR.ID, err) - } - } - - newWebXRs[i] = models.WebXR{ - ID: oldWebXR.ID, - Image360: oldWebXR.Image360, - Video360: oldWebXR.Video360, - RewardsMetadataURI: oldWebXR.RewardsMetadataURI, - Customizations: customizationsMap, - FreeNFTImage: oldWebXR.FreeNFTImage, - GoldReward: oldWebXR.GoldReward, - SilverReward: oldWebXR.SilverReward, - BronzeReward: oldWebXR.BronzeReward, - PhygitalID: oldWebXR.PhygitalID, - CreatedAt: oldWebXR.CreatedAt, - UpdatedAt: oldWebXR.UpdatedAt, - } - } - return newWebXRs, nil + c.JSON(http.StatusOK, webxr) } func UpdateWebXR(c *gin.Context) { diff --git a/go.mod b/go.mod index ebd9873..d602cfd 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,15 @@ go 1.22.2 require ( github.com/gin-gonic/gin v1.10.0 - github.com/gofrs/uuid v4.4.0+incompatible github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 + gorm.io/datatypes v1.2.1 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.10 ) require ( + filippo.io/edwards25519 v1.1.0 // indirect github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect @@ -21,9 +22,10 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect github.com/jackc/pgx/v5 v5.5.5 // indirect github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -47,4 +49,5 @@ require ( golang.org/x/text v0.15.0 // indirect google.golang.org/protobuf v1.34.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/mysql v1.5.6 // indirect ) diff --git a/go.sum b/go.sum index 8982c56..4fc2799 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= @@ -24,10 +26,15 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= -github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= +github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -35,8 +42,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= +github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= @@ -61,6 +68,10 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= +github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/microsoft/go-mssqldb v0.17.0 h1:Fto83dMZPnYv1Zwx5vHHxpNraeEaUlQ/hhHLgZiaenE= +github.com/microsoft/go-mssqldb v0.17.0/go.mod h1:OkoNGhGEs8EZqchVTtochlXruEhEOaO4S0d2sB5aeGQ= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -113,8 +124,17 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/datatypes v1.2.1 h1:r+g0bk4LPCW2v4+Ls7aeNgGme7JYdNDQ2VtvlNUfBh0= +gorm.io/datatypes v1.2.1/go.mod h1:hYK6OTb/1x+m96PgoZZq10UXJ6RvEBb9kRDQ2yyhzGs= +gorm.io/driver/mysql v1.5.6 h1:Ld4mkIickM+EliaQZQx3uOJDJHtrd70MxAUqWqlx3Y8= +gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= +gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU= +gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI= +gorm.io/driver/sqlserver v1.4.1 h1:t4r4r6Jam5E6ejqP7N82qAJIJAht27EGT41HyPfXRw0= +gorm.io/driver/sqlserver v1.4.1/go.mod h1:DJ4P+MeZbc5rvY58PnmN1Lnyvb5gw5NPzGshHDnJLig= +gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s= gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= diff --git a/models/collection.go b/models/collection.go index c3b0796..57c9d57 100644 --- a/models/collection.go +++ b/models/collection.go @@ -4,21 +4,22 @@ import ( "time" "github.com/google/uuid" + "gorm.io/datatypes" "gorm.io/gorm" ) 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 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"` + 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"` + 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 02ec3aa..ff6dea2 100644 --- a/models/phygital.go +++ b/models/phygital.go @@ -4,35 +4,36 @@ import ( "time" "github.com/google/uuid" + "gorm.io/datatypes" "gorm.io/gorm" ) 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 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"` + ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` + Name string `json:"name"` + BrandName string `json:"brand_name"` + Category datatypes.JSON `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 b701403..f5024ee 100644 --- a/models/webxr.go +++ b/models/webxr.go @@ -4,22 +4,23 @@ import ( "time" "github.com/google/uuid" + "gorm.io/datatypes" "gorm.io/gorm" ) 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 map[string]interface{} `gorm:"type:jsonb" 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 datatypes.JSON `gorm:"type:jsonb" 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"` } func (w *WebXR) BeforeCreate(tx *gorm.DB) (err error) {