summaryrefslogtreecommitdiffstats
path: root/api/preference.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-10-16 08:16:40 -0400
committerChristopher Speller <crspeller@gmail.com>2015-10-16 08:16:40 -0400
commit099d8538770271bfc41416b871a899362bf9a086 (patch)
tree103ecc42fe274694d387a4e5969f860767594139 /api/preference.go
parent269476d694f425764dbe0cccd4eaa3f23956ba61 (diff)
parent327b0b5a2119ae888c812f682b3934061b8f59bf (diff)
downloadchat-099d8538770271bfc41416b871a899362bf9a086.tar.gz
chat-099d8538770271bfc41416b871a899362bf9a086.tar.bz2
chat-099d8538770271bfc41416b871a899362bf9a086.zip
Merge pull request #1079 from hmhealey/initprefs
Added an initial call to get all user preferences on page load
Diffstat (limited to 'api/preference.go')
-rw-r--r--api/preference.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/api/preference.go b/api/preference.go
index 3a0535473..6d6ac1a7f 100644
--- a/api/preference.go
+++ b/api/preference.go
@@ -14,11 +14,22 @@ func InitPreference(r *mux.Router) {
l4g.Debug("Initializing preference api routes")
sr := r.PathPrefix("/preferences").Subrouter()
+ sr.Handle("/", ApiUserRequired(getAllPreferences)).Methods("GET")
sr.Handle("/save", ApiUserRequired(savePreferences)).Methods("POST")
sr.Handle("/{category:[A-Za-z0-9_]+}", ApiUserRequired(getPreferenceCategory)).Methods("GET")
sr.Handle("/{category:[A-Za-z0-9_]+}/{name:[A-Za-z0-9_]+}", ApiUserRequired(getPreference)).Methods("GET")
}
+func getAllPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
+ if result := <-Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil {
+ c.Err = result.Err
+ } else {
+ data := result.Data.(model.Preferences)
+
+ w.Write([]byte(data.ToJson()))
+ }
+}
+
func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
preferences, err := model.PreferencesFromJson(r.Body)
if err != nil {