-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af87da7
commit 87ff45b
Showing
5 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters