/
iteminfo.go
32 lines (26 loc) · 1.08 KB
/
iteminfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package controllers
import (
"ffxiv-profit-api/app/controllers/mongoDB"
"ffxiv-profit-api/app/models"
"github.com/revel/revel"
)
// ItemInfo handles the endpoints for a specific item, without any user information
type ItemInfo struct {
*revel.Controller
}
// Obtain grabs all recipe information from XIVAPI, and returns all of the information about the materials and main recipe.
func (c ItemInfo) Obtain(recipeID int) revel.Result {
var baseinfo mongoDB.Information
// We have to initialize the maps here, to be able to allow recursive calls.
var innerinfo mongoDB.InnerInformation
innerrecipes := make(map[int]*models.Recipes) // Contains the inner recipes for some key = Recipe.ID
innerinfo.Recipes = innerrecipes
mongoDB.BaseInformation(DB, recipeID, innerinfo)
// The baseinfo should also be in the maps themselves.
baseinfo.Recipes = innerinfo.Recipes[recipeID]
// We need to render this information as a single JSON object
jsonObject := make(map[string]interface{})
jsonObject["MainRecipe"] = baseinfo
jsonObject["InnerRecipes"] = innerinfo
return c.RenderJSON(jsonObject)
}