-
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
742288b
commit 3113077
Showing
4 changed files
with
100 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,75 @@ | ||
package controllers | ||
|
||
import( | ||
"net/http" | ||
|
||
"app.myriadflow.com/db" | ||
"app.myriadflow.com/models" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func CreateFanToken(c *gin.Context) { | ||
var fantoken models.FanToken | ||
if err := c.ShouldBindJSON(&fantoken); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
if err := db.DB.Create(&fantoken).Error; err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, fantoken) | ||
} | ||
|
||
func GetFanToken(c *gin.Context) { | ||
id := c.Param("id") | ||
var fantoken models.FanToken | ||
if err := db.DB.First(&fantoken, "id = ?", id).Error; err != nil { | ||
c.JSON(http.StatusNotFound, gin.H{"error": "FanToken not found"}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, fantoken) | ||
} | ||
|
||
func GetAllFanToken(c *gin.Context) { | ||
var fantoken []models.FanToken | ||
if err := db.DB.Find(&fantoken).Error; err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
c.JSON(http.StatusOK, fantoken) | ||
} | ||
|
||
func UpdateFanToken(c *gin.Context) { | ||
id := c.Param("id") | ||
var fantoken models.FanToken | ||
if err := db.DB.First(&fantoken, "id = ?", id).Error; err != nil { | ||
c.JSON(http.StatusNotFound, gin.H{"error": "FanToken not found"}) | ||
return | ||
} | ||
|
||
if err := c.ShouldBindJSON(&fantoken); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
if err := db.DB.Save(&fantoken).Error; err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, fantoken) | ||
} | ||
|
||
func DeleteFanToken(c *gin.Context) { | ||
id := c.Param("id") | ||
if err := db.DB.Delete(&models.FanToken{}, "id = ?", id).Error; err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, gin.H{"message": "FanToken deleted successfully"}) | ||
} |
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,17 @@ | ||
package models | ||
|
||
import( | ||
"time" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type FanToken struct { | ||
ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key" json:"id"` | ||
BrandID string `json:"brand_id"` | ||
CollectionID uuid.UUID `json:"collection_id"` | ||
PhygitalID string `json:"phygital_id"` | ||
TokenFestID string `json:"tokenFest_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"` | ||
} | ||
|
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