DeleteClient deletes a client by its id. swagger:operation DELETE /client/{id} client deleteClient Delete a client. --- consumes: [application/json] produces: [application/json] parameters: - name: id in: path description: the client id required: true type: integer format: int6
(ctx *gin.Context)
| 221 | // schema: |
| 222 | // $ref: "#/definitions/Error" |
| 223 | func (a *ClientAPI) DeleteClient(ctx *gin.Context) { |
| 224 | withID(ctx, "id", func(id uint) { |
| 225 | client, err := a.DB.GetClientByID(id) |
| 226 | if success := successOrAbort(ctx, 500, err); !success { |
| 227 | return |
| 228 | } |
| 229 | if client != nil && client.UserID == auth.GetUserID(ctx) { |
| 230 | a.NotifyDeleted(client.UserID, client.Token) |
| 231 | successOrAbort(ctx, 500, a.DB.DeleteClientByID(id)) |
| 232 | } else { |
| 233 | ctx.AbortWithError(404, fmt.Errorf("client with id %d doesn't exists", id)) |
| 234 | } |
| 235 | }) |
| 236 | } |
| 237 | |
| 238 | func (a *ClientAPI) clientExists(token string) bool { |
| 239 | client, _ := a.DB.GetClientByToken(token) |