GetMessagesWithApplication returns all messages from a specific application. swagger:operation GET /application/{id}/message message getAppMessages Return all messages from a specific application. --- produces: [application/json] security: [clientTokenAuthorizationHeader: [], clientTokenHeader:
(ctx *gin.Context)
| 178 | // schema: |
| 179 | // $ref: "#/definitions/Error" |
| 180 | func (a *MessageAPI) GetMessagesWithApplication(ctx *gin.Context) { |
| 181 | withID(ctx, "id", func(id uint) { |
| 182 | withPaging(ctx, func(params *pagingParams) { |
| 183 | app, err := a.DB.GetApplicationByID(id) |
| 184 | if success := successOrAbort(ctx, 500, err); !success { |
| 185 | return |
| 186 | } |
| 187 | if app != nil && app.UserID == auth.GetUserID(ctx) { |
| 188 | // the +1 is used to check if there are more messages and will be removed on buildWithPaging |
| 189 | messages, err := a.DB.GetMessagesByApplicationSince(id, params.Limit+1, params.Since) |
| 190 | if success := successOrAbort(ctx, 500, err); !success { |
| 191 | return |
| 192 | } |
| 193 | ctx.JSON(200, buildWithPaging(ctx, params, messages)) |
| 194 | } else { |
| 195 | ctx.AbortWithError(404, errors.New("application does not exist")) |
| 196 | } |
| 197 | }) |
| 198 | }) |
| 199 | } |
| 200 | |
| 201 | // DeleteMessages delete all messages from a user. |
| 202 | // swagger:operation DELETE /message message deleteMessages |