Save and retrieve account data (#166)

* Save function for account data

* Fix upsert + add empty routes and function

* Save account data

* Retrieval functions

* Implement retrieval in /sync

* Fix arrays not correctly initialised

* Merge account data retrieval functions

* Request DB only once per request

* Initialise array

* Fix comment
This commit is contained in:
Brendan Abolivier 2017-07-26 14:53:11 +01:00 committed by Mark Haines
parent 6d073dcf9f
commit 3e394e9e21
6 changed files with 266 additions and 18 deletions

View file

@ -274,9 +274,16 @@ func Setup(
)
r0mux.Handle("/user/{userID}/account_data/{type}",
common.MakeAPI("user_account_data", func(req *http.Request) util.JSONResponse {
// TODO: Set and get the account_data
return util.JSONResponse{Code: 200, JSON: struct{}{}}
common.MakeAuthAPI("user_account_data", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
vars := mux.Vars(req)
return readers.SaveAccountData(req, accountDB, device, vars["userID"], "", vars["type"])
}),
)
r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
common.MakeAuthAPI("user_account_data", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
vars := mux.Vars(req)
return readers.SaveAccountData(req, accountDB, device, vars["userID"], vars["roomID"], vars["type"])
}),
)