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
import (
"github.com/revel/revel"
"gopkg.in/ganggo/api.v0/app/helpers"
"gopkg.in/ganggo/ganggo.v0/app/models"
"net/http"
)
......@@ -40,6 +41,7 @@ type ApiNotification struct {
* @apiGroup Notifications
*
* @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
*
* @apiSuccess {String} CreatedAt Timestamp of creation
......@@ -53,18 +55,18 @@ type ApiNotification struct {
*
* @apiSuccessExample {json} Success-Response
* HTTP/1.1 200 OK
* [
* {
* "ID": 12,
* "CreatedAt": "2018-01-08T15:25:43Z",
* "UpdatedAt": "2018-01-08T15:25:43Z",
* "TargetGuid": "cc783a9749f09c7d817a1707a4c052bc",
* "PersonID": 1,
* "UserID": 2,
* "Unread": true,
* "TargetType": "Post"
* }
* ]
* {
* "0": {
* "ID": 12,
* "CreatedAt": "2018-01-08T15:25:43Z",
* "UpdatedAt": "2018-01-08T15:25:43Z",
* "TargetGuid": "cc783a9749f09c7d817a1707a4c052bc",
* "PersonID": 1,
* "UserID": 2,
* "Unread": true,
* "TargetType": "Post"
* }
* }
*
* @apiError (Errors) {String} error Contains the recent error message
*
......@@ -81,8 +83,8 @@ type ApiNotification struct {
* }
*
*/
func (n ApiNotification) Index(offset int) revel.Result {
user, err := models.CurrentUser(n.Params, n.Session)
func (n ApiNotification) Index(fields string, offset int) revel.Result {
user, err := models.CurrentUser(n)
if err != nil {
n.Log.Error(TAG, "db", err, "api", ERR_UNAUTHORIZED)
return n.ApiError(http.StatusUnauthorized, ERR_UNAUTHORIZED)
......@@ -95,7 +97,8 @@ func (n ApiNotification) Index(offset int) revel.Result {
return n.ApiError(http.StatusInternalServerError, ERR_SERVER)
}
return n.RenderJSON(notify)
return n.RenderJSON(
helpers.SelectStructFields(notify, fields))
}
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