mirror of
https://github.com/arnaucube/gogame.git
synced 2026-02-07 03:26:39 +01:00
add get planet data
This commit is contained in:
@@ -121,6 +121,28 @@ func handleGetUserPlanets(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func handleGetPlanet(c *gin.Context) {
|
||||
claims := jwt.ExtractClaims(c)
|
||||
userid := bson.ObjectIdHex(claims[constants.JWTIdKey].(string))
|
||||
planetid := c.Param("planetid")
|
||||
|
||||
user, err := userservice.GetUserById(userid)
|
||||
if err != nil {
|
||||
fail(c, err, "error on getting user")
|
||||
return
|
||||
}
|
||||
|
||||
planet, err := gameservice.GetBuildings(user, bson.ObjectIdHex(planetid))
|
||||
if err != nil {
|
||||
fail(c, err, "error upgrading building")
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
"planet": planet,
|
||||
})
|
||||
}
|
||||
|
||||
type BuildMsg struct {
|
||||
PlanetId string
|
||||
Building string
|
||||
|
||||
@@ -96,6 +96,7 @@ func newApiService() *gin.Engine {
|
||||
api.GET("/", handleGetUser)
|
||||
api.GET("/resources", handleGetResources)
|
||||
api.GET("/planets", handleGetUserPlanets)
|
||||
api.GET("/planets/:planetid", handleGetPlanet)
|
||||
api.POST("/buildings", handlePostUpgradeBuilding)
|
||||
}
|
||||
return api
|
||||
|
||||
Reference in New Issue
Block a user