]> git.openstreetmap.org Git - rails.git/commitdiff
Added JSON support to user preferences
authorMichal Migurski <migurski@fb.com>
Wed, 7 Apr 2021 02:20:02 +0000 (19:20 -0700)
committerMichal Migurski <migurski@fb.com>
Wed, 7 Apr 2021 04:27:54 +0000 (21:27 -0700)
app/controllers/api/user_preferences_controller.rb
app/views/api/user_preferences/_user_preference.json.jbuilder [new file with mode: 0644]
app/views/api/user_preferences/index.json.jbuilder [new file with mode: 0644]

index ddc5d7f430a9eff0c085bedaf40cf3a9d70a76b5..10b01d69688ebdebeff0c4b4d2cff6dbd42c6543 100644 (file)
@@ -7,12 +7,17 @@ module Api
 
     around_action :api_call_handle_error
 
+    before_action :set_request_formats
+
     ##
     # return all the preferences as an XML document
     def index
       @user_preferences = current_user.preferences
 
-      render :formats => [:xml]
+      respond_to do |format|
+        format.xml
+        format.json
+      end
     end
 
     ##
diff --git a/app/views/api/user_preferences/_user_preference.json.jbuilder b/app/views/api/user_preferences/_user_preference.json.jbuilder
new file mode 100644 (file)
index 0000000..38bafa3
--- /dev/null
@@ -0,0 +1,6 @@
+attrs = {
+  "k" => user_preference.k,
+  "v" => user_preference.v
+}
+
+json.preference(attrs)
diff --git a/app/views/api/user_preferences/index.json.jbuilder b/app/views/api/user_preferences/index.json.jbuilder
new file mode 100644 (file)
index 0000000..b325556
--- /dev/null
@@ -0,0 +1 @@
+json.partial! @user_preferences