Commit 563eba03 authored by zauberstuhl's avatar zauberstuhl

Return map instead of struct in APINotification.Index

add fields as optional parameter
parent c7ce8503
...@@ -19,6 +19,7 @@ package controllers ...@@ -19,6 +19,7 @@ package controllers
import ( import (
"github.com/revel/revel" "github.com/revel/revel"
"gopkg.in/ganggo/api.v0/app/helpers"
"gopkg.in/ganggo/ganggo.v0/app/models" "gopkg.in/ganggo/ganggo.v0/app/models"
"net/http" "net/http"
) )
...@@ -40,6 +41,7 @@ type ApiNotification struct { ...@@ -40,6 +41,7 @@ type ApiNotification struct {
* @apiGroup Notifications * @apiGroup Notifications
* *
* @apiParam {String} access_token Oauth access token * @apiParam {String} access_token Oauth access token
* @apiParam {String} [fields] Display only specific fields, e.g. fields=ID,Person(ID:Profile(ID:ImageUrl))
* @apiParam {Number} [offset] Post offset for database * @apiParam {Number} [offset] Post offset for database
* *
* @apiSuccess {String} CreatedAt Timestamp of creation * @apiSuccess {String} CreatedAt Timestamp of creation
...@@ -53,18 +55,18 @@ type ApiNotification struct { ...@@ -53,18 +55,18 @@ type ApiNotification struct {
* *
* @apiSuccessExample {json} Success-Response * @apiSuccessExample {json} Success-Response
* HTTP/1.1 200 OK * HTTP/1.1 200 OK
* [ * {
* { * "0": {
* "ID": 12, * "ID": 12,
* "CreatedAt": "2018-01-08T15:25:43Z", * "CreatedAt": "2018-01-08T15:25:43Z",
* "UpdatedAt": "2018-01-08T15:25:43Z", * "UpdatedAt": "2018-01-08T15:25:43Z",
* "TargetGuid": "cc783a9749f09c7d817a1707a4c052bc", * "TargetGuid": "cc783a9749f09c7d817a1707a4c052bc",
* "PersonID": 1, * "PersonID": 1,
* "UserID": 2, * "UserID": 2,
* "Unread": true, * "Unread": true,
* "TargetType": "Post" * "TargetType": "Post"
* } * }
* ] * }
* *
* @apiError (Errors) {String} error Contains the recent error message * @apiError (Errors) {String} error Contains the recent error message
* *
...@@ -81,8 +83,8 @@ type ApiNotification struct { ...@@ -81,8 +83,8 @@ type ApiNotification struct {
* } * }
* *
*/ */
func (n ApiNotification) Index(offset int) revel.Result { func (n ApiNotification) Index(fields string, offset int) revel.Result {
user, err := models.CurrentUser(n.Params, n.Session) user, err := models.CurrentUser(n)
if err != nil { if err != nil {
n.Log.Error(TAG, "db", err, "api", ERR_UNAUTHORIZED) n.Log.Error(TAG, "db", err, "api", ERR_UNAUTHORIZED)
return n.ApiError(http.StatusUnauthorized, ERR_UNAUTHORIZED) return n.ApiError(http.StatusUnauthorized, ERR_UNAUTHORIZED)
...@@ -95,7 +97,8 @@ func (n ApiNotification) Index(offset int) revel.Result { ...@@ -95,7 +97,8 @@ func (n ApiNotification) Index(offset int) revel.Result {
return n.ApiError(http.StatusInternalServerError, ERR_SERVER) return n.ApiError(http.StatusInternalServerError, ERR_SERVER)
} }
return n.RenderJSON(notify) return n.RenderJSON(
helpers.SelectStructFields(notify, fields))
} }
func (n ApiNotification) Create() revel.Result { func (n ApiNotification) Create() revel.Result {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment