Skip to content

Commit

Permalink
feat : updated to get avatar and webxr by phygital_id
Browse files Browse the repository at this point in the history
  • Loading branch information
surajhub255 committed Jul 1, 2024
1 parent e320531 commit 742288b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions controllers/avatar_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func GetAvatar(c *gin.Context) {
c.JSON(http.StatusOK, avatar)
}

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

c.JSON(http.StatusOK, avatar)
}


// get all avatars api
func GetAllAvatars(c *gin.Context) {
var avatars []models.Avatar
Expand Down
11 changes: 11 additions & 0 deletions controllers/webxr_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ func GetWebXR(c *gin.Context) {
c.JSON(http.StatusOK, webxr)
}

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

c.JSON(http.StatusOK, webxr)
}

// get all webxr
func GetAllWebXR(c *gin.Context) {
var webxr []models.WebXR
Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ func Routes(r *gin.Engine) {
r.GET("/webxr/all", controllers.GetAllWebXR)
r.PUT("/webxr/:id", controllers.UpdateWebXR)
r.DELETE("/webxr/:id", controllers.DeleteWebXR)
r.GET("/webxr/phygital/:phygital_id", controllers.GetWebXRByPhygitalID)

// Avatar routes
r.POST("/avatars", controllers.CreateAvatar)
r.GET("/avatars/:id", controllers.GetAvatar)
r.GET("/avatars/all", controllers.GetAllAvatars)
r.PUT("/avatars/:id", controllers.UpdateAvatar)
r.DELETE("/avatars/:id", controllers.DeleteAvatar)
r.GET("/avatars/phygital/:phygital_id", controllers.GetAvatarByPhygitalID)

// Variant routes
r.POST("/variants", controllers.CreateVariant)
Expand Down

0 comments on commit 742288b

Please sign in to comment.