diff --git a/controllers/avatar_controller.go b/controllers/avatar_controller.go index 0c45c05..6571b62 100644 --- a/controllers/avatar_controller.go +++ b/controllers/avatar_controller.go @@ -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 diff --git a/controllers/webxr_controller.go b/controllers/webxr_controller.go index d08ef85..83e06e3 100644 --- a/controllers/webxr_controller.go +++ b/controllers/webxr_controller.go @@ -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 diff --git a/server/server.go b/server/server.go index 3fca1c8..5d6ed2d 100644 --- a/server/server.go +++ b/server/server.go @@ -68,6 +68,7 @@ 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) @@ -75,6 +76,7 @@ func Routes(r *gin.Engine) { 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)