Skip to content

Commit

Permalink
feat : added elevate
Browse files Browse the repository at this point in the history
  • Loading branch information
surajhub255 committed Oct 9, 2024
1 parent af87da7 commit 87ff45b
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 1 deletion.
95 changes: 95 additions & 0 deletions controllers/elevate_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package controllers

import (
"app.myriadflow.com/db"
"net/http"
"app.myriadflow.com/models"
"github.com/gin-gonic/gin"
)

func CreateElevate(c *gin.Context) {
var elevate models.Elevate
if err := c.ShouldBindJSON(&elevate); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if err := db.DB.Create(&elevate).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusOK, elevate)
}

func GetElevate(c *gin.Context) {
id := c.Param("id")
var elevate models.Elevate
if err := db.DB.First(&elevate, "id = ?", id).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Elevate not found"})
return
}

c.JSON(http.StatusOK, elevate)
}

func GetAllElevate(c *gin.Context) {
var elevate []models.Elevate
if err := db.DB.Find(&elevate).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, elevate)
}

func GetAllElevateByChainType(c *gin.Context) {
chaintypeId := c.Param("chaintype_id")
var elevate []models.Elevate
if err := db.DB.Where("chaintype_id = ? " , chaintypeId).Find(&elevate).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, elevate)
}

func GetElevateByWalletAddress(c *gin.Context) {
walletAddress := c.Param("walletAddress")
var elevate models.Elevate
if err := db.DB.Where("wallet_address = ?", walletAddress).First(&elevate).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Profile not found"})
return
}

c.JSON(http.StatusOK, elevate)
}

func UpdateElevate(c *gin.Context) {
id := c.Param("id")
var elevate models.Elevate
if err := db.DB.First(&elevate, "id = ?", id).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Elevate not found"})
return
}

if err := c.ShouldBindJSON(&elevate); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if err := db.DB.Save(&elevate).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusOK, elevate)
}

func DeleteElevate(c *gin.Context) {
id := c.Param("id")
if err := db.DB.Delete(&models.Elevate{}, "id = ?", id).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Elevate not found"})
return
}

c.JSON(http.StatusOK, gin.H{"message": "Elevate deleted"})
}
2 changes: 1 addition & 1 deletion db/db.connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Init() {
log.Println(err)
}

err = DB.AutoMigrate(&models.User{}, &models.Brand{}, &models.Collection{}, &models.Phygital{}, &models.WebXR{}, &models.Avatar{}, &models.Variant{}, &models.FanToken{}, &models.ChainType{}, &models.NftEntries{}, &models.Profile{}, &models.CartItem{}, &models.OTPStore{}, &models.OTPData{}, &models.MainnetFanToken{}, &models.DelegateMintFanTokenRequest{})
err = DB.AutoMigrate(&models.User{}, &models.Brand{}, &models.Collection{}, &models.Phygital{}, &models.WebXR{}, &models.Avatar{}, &models.Variant{}, &models.FanToken{}, &models.ChainType{}, &models.NftEntries{}, &models.Profile{}, &models.CartItem{}, &models.OTPStore{}, &models.OTPData{}, &models.MainnetFanToken{}, &models.DelegateMintFanTokenRequest{} , &models.Elevate{})
if err != nil {
log.Fatalf("failed to migrate database: %v", err)
}
Expand Down
28 changes: 28 additions & 0 deletions models/elevate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package models

import (
"time"

"github.com/google/uuid"
"gorm.io/gorm"
)

type Elevate struct {
ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"`
FullName string `json:"full_name"`
EmailAddress string `json:"email_address"`
BrandDescription string `json:"brand_description"`
ProgramAlignment string `json:"program_alignment"`
BrandVision string `json:"brand_vision"`
AdditionalInformation string `json:"additional_information"`
Status string `json:"status"`
WalletAddress string `json:"wallet_address"`
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 (e *Elevate) BeforeCreate(tx *gorm.DB) (err error) {
e.ID = uuid.New()
return
}
1 change: 1 addition & 0 deletions models/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Profile struct {
Website string `json:"website"`
X string `json:"x"`
Instagram string `json:"instagram"`
Basename string `json:"basename"`
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"`
Expand Down
9 changes: 9 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,13 @@ func Routes(r *gin.Engine) {
r.PUT("/update-mint-fantoken/:id", controllers.UpdateMintFanToken)
r.DELETE("/delete-mint-fantoken/:id", controllers.DeleteMintFanToken)

//Elevate routes
r.POST("/elevate", controllers.CreateElevate)
r.GET("/elevate/:id", controllers.GetElevate)
r.GET("/elevate/all", controllers.GetAllElevate)
r.GET("/elevate/walletaddress/:walletAddress" , controllers.GetElevateByWalletAddress)
r.GET("/elevate/all/:chaintype_id", controllers.GetAllElevateByChainType)
r.PUT("/elevate/:id", controllers.UpdateElevate)
r.DELETE("/elevate/:id", controllers.DeleteElevate)

}

0 comments on commit 87ff45b

Please sign in to comment.