DeleteApplication deletes an application by its id. swagger:operation DELETE /application/{id} application deleteApp Delete an application. --- consumes: [application/json] produces: [application/json] parameters: - name: id in: path description: the application id required: true
(ctx *gin.Context)
| 182 | // schema: |
| 183 | // $ref: "#/definitions/Error" |
| 184 | func (a *ApplicationAPI) DeleteApplication(ctx *gin.Context) { |
| 185 | withID(ctx, "id", func(id uint) { |
| 186 | app, err := a.DB.GetApplicationByID(id) |
| 187 | if success := successOrAbort(ctx, 500, err); !success { |
| 188 | return |
| 189 | } |
| 190 | if app != nil && app.UserID == auth.GetUserID(ctx) { |
| 191 | if app.Internal { |
| 192 | ctx.AbortWithError(400, errors.New("cannot delete internal application")) |
| 193 | return |
| 194 | } |
| 195 | if success := successOrAbort(ctx, 500, a.DB.DeleteApplicationByID(id)); !success { |
| 196 | return |
| 197 | } |
| 198 | if app.Image != "" { |
| 199 | os.Remove(a.ImageDir + app.Image) |
| 200 | } |
| 201 | } else { |
| 202 | ctx.AbortWithError(404, fmt.Errorf("app with id %d doesn't exists", id)) |
| 203 | } |
| 204 | }) |
| 205 | } |
| 206 | |
| 207 | // UpdateApplication updates an application info by its id. |
| 208 | // swagger:operation PUT /application/{id} application updateApplication |