api

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2018 License: MIT Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationAPI added in v1.2.0

type ApplicationAPI struct {
	DB       ApplicationDatabase
	ImageDir string
}

The ApplicationAPI provides handlers for managing applications.

func (*ApplicationAPI) CreateApplication added in v1.2.0

func (a *ApplicationAPI) CreateApplication(ctx *gin.Context)

CreateApplication creates an application and returns the access token. swagger:operation POST /application application createApp

Create an application.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: body in: body description: the application to add required: true schema: $ref: "#/definitions/Application"

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/Application"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*ApplicationAPI) DeleteApplication added in v1.2.0

func (a *ApplicationAPI) DeleteApplication(ctx *gin.Context)

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 type: integer

security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] responses:

200:
  description: Ok
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

func (*ApplicationAPI) GetApplications added in v1.2.0

func (a *ApplicationAPI) GetApplications(ctx *gin.Context)

GetApplications returns all applications a user has. swagger:operation GET /application application getApps

Return all applications.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] responses:

200:
  description: Ok
  schema:
    type: array
    items:
      $ref: "#/definitions/Application"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*ApplicationAPI) UpdateApplication added in v1.2.0

func (a *ApplicationAPI) UpdateApplication(ctx *gin.Context)

UpdateApplication updates an application info by its id. swagger:operation PUT /application/{id} application updateApplication

Update an application.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: body in: body description: the application to update required: true schema: $ref: "#/definitions/Application"
  • name: id in: path description: the application id required: true type: integer

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/Application"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

func (*ApplicationAPI) UploadApplicationImage added in v1.2.0

func (a *ApplicationAPI) UploadApplicationImage(ctx *gin.Context)

UploadApplicationImage uploads an image for an application. swagger:operation POST /application/{id}/image application uploadAppImage

Upload an image for an application.

--- consumes: - multipart/form-data produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: file in: formData description: the application image required: true type: file
  • name: id in: path description: the application id required: true type: integer

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/Application"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"
500:
  description: Server Error
  schema:
      $ref: "#/definitions/Error"

type ApplicationDatabase added in v1.2.0

type ApplicationDatabase interface {
	CreateApplication(application *model.Application) error
	GetApplicationByToken(token string) *model.Application
	GetApplicationByID(id uint) *model.Application
	GetApplicationsByUser(userID uint) []*model.Application
	DeleteApplicationByID(id uint) error
	UpdateApplication(application *model.Application) error
}

The ApplicationDatabase interface for encapsulating database access.

type ClientAPI added in v1.2.0

type ClientAPI struct {
	DB            ClientDatabase
	ImageDir      string
	NotifyDeleted func(uint, string)
}

The ClientAPI provides handlers for managing clients and applications.

func (*ClientAPI) CreateClient added in v1.2.0

func (a *ClientAPI) CreateClient(ctx *gin.Context)

CreateClient creates a client and returns the access token. swagger:operation POST /client client createClient

Create a client.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: body in: body description: the client to add required: true schema: $ref: "#/definitions/Client"

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/Client"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*ClientAPI) DeleteClient added in v1.2.0

func (a *ClientAPI) DeleteClient(ctx *gin.Context)

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

security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] responses:

200:
  description: Ok
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

func (*ClientAPI) GetClients added in v1.2.0

func (a *ClientAPI) GetClients(ctx *gin.Context)

GetClients returns all clients a user has. swagger:operation GET /client client getClients

Return all clients.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] responses:

200:
  description: Ok
  schema:
    type: array
    items:
      $ref: "#/definitions/Client"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

type ClientDatabase added in v1.2.0

type ClientDatabase interface {
	CreateClient(client *model.Client) error
	GetClientByToken(token string) *model.Client
	GetClientByID(id uint) *model.Client
	GetClientsByUser(userID uint) []*model.Client
	DeleteClientByID(id uint) error
}

The ClientDatabase interface for encapsulating database access.

type MessageAPI

type MessageAPI struct {
	DB       MessageDatabase
	Notifier Notifier
}

The MessageAPI provides handlers for managing messages.

func (*MessageAPI) CreateMessage

func (a *MessageAPI) CreateMessage(ctx *gin.Context)

CreateMessage creates a message, authentication via application-token is required. swagger:operation POST /message message createMessage

Create a message.

__NOTE__: This API ONLY accepts an application token as authentication. --- consumes: application/json produces: application/json security: [appTokenHeader: [], appTokenQuery: []] parameters:

  • name: body in: body description: the message to add required: true schema: $ref: "#/definitions/Message"

responses:

200:
  description: Ok
  schema:
    $ref: "#/definitions/Message"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*MessageAPI) DeleteMessage

func (a *MessageAPI) DeleteMessage(ctx *gin.Context)

DeleteMessage deletes a message with an id. swagger:operation DELETE /message/{id} message deleteMessage

Deletes a message with an id.

--- produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: id in: path description: the message id required: true type: integer

responses:

200:
  description: Ok
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

func (*MessageAPI) DeleteMessageWithApplication

func (a *MessageAPI) DeleteMessageWithApplication(ctx *gin.Context)

DeleteMessageWithApplication deletes all messages from a specific application. swagger:operation DELETE /application/{id}/message message deleteAppMessages

Delete all messages from a specific application.

--- produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: id in: path description: the application id required: true type: integer

responses:

200:
  description: Ok
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

func (*MessageAPI) DeleteMessages

func (a *MessageAPI) DeleteMessages(ctx *gin.Context)

DeleteMessages delete all messages from a user. swagger:operation DELETE /message message deleteMessages

Delete all messages.

--- produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] responses:

200:
  description: Ok
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*MessageAPI) GetMessages

func (a *MessageAPI) GetMessages(ctx *gin.Context)

GetMessages returns all messages from a user. swagger:operation GET /message message getMessages

Return all messages.

--- produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: limit in: query description: the maximal amount of messages to return required: false maximum: 200 minimum: 1 default: 100 type: integer
  • name: since in: query description: return all messages with an ID less than this value minimum: 0 required: false type: integer

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/PagedMessages"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*MessageAPI) GetMessagesWithApplication

func (a *MessageAPI) GetMessagesWithApplication(ctx *gin.Context)

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: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: id in: path description: the application id required: true type: integer
  • name: limit in: query description: the maximal amount of messages to return required: false maximum: 200 minimum: 1 default: 100 type: integer
  • name: since in: query description: return all messages with an ID less than this value minimum: 0 required: false type: integer

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/PagedMessages"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

type MessageDatabase

type MessageDatabase interface {
	GetMessagesByApplicationSince(appID uint, limit int, since uint) []*model.Message
	GetApplicationByID(id uint) *model.Application
	GetMessagesByUserSince(userID uint, limit int, since uint) []*model.Message
	DeleteMessageByID(id uint) error
	GetMessageByID(id uint) *model.Message
	DeleteMessagesByUser(userID uint) error
	DeleteMessagesByApplication(applicationID uint) error
	CreateMessage(message *model.Message) error
	GetApplicationByToken(token string) *model.Application
}

The MessageDatabase interface for encapsulating database access.

type Notifier

type Notifier interface {
	Notify(userID uint, message *model.Message)
}

Notifier notifies when a new message was created.

type UserAPI

type UserAPI struct {
	DB               UserDatabase
	PasswordStrength int
	NotifyDeleted    func(uint)
}

The UserAPI provides handlers for managing users.

func (*UserAPI) ChangePassword

func (a *UserAPI) ChangePassword(ctx *gin.Context)

ChangePassword changes the password from the current user swagger:operation POST /current/user/password user updateCurrentUser

Update the password of the current user.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: body in: body description: the user required: true schema: $ref: "#/definitions/UserPass"

responses:

200:
  description: Ok
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*UserAPI) CreateUser

func (a *UserAPI) CreateUser(ctx *gin.Context)

CreateUser creates a user swagger:operation POST /user user createUser

Create a user.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: body in: body description: the user to add required: true schema: $ref: "#/definitions/UserWithPass"

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/User"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*UserAPI) DeleteUserByID

func (a *UserAPI) DeleteUserByID(ctx *gin.Context)

DeleteUserByID deletes the user by id swagger:operation DELETE /user/{id} user deleteUser

Deletes a user.

--- produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: id in: path description: the user id required: true type: integer

responses:

200:
  description: Ok
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

func (*UserAPI) GetCurrentUser

func (a *UserAPI) GetCurrentUser(ctx *gin.Context)

GetCurrentUser returns the current user swagger:operation GET /current/user user currentUser

Return the current user.

--- produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/User"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*UserAPI) GetUserByID

func (a *UserAPI) GetUserByID(ctx *gin.Context)

GetUserByID returns the user by id swagger:operation GET /user/{id} user getUser

Get a user.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: id in: path description: the user id required: true type: integer

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/User"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

func (*UserAPI) GetUsers

func (a *UserAPI) GetUsers(ctx *gin.Context)

GetUsers returns all the users swagger:operation GET /user user getUsers

Return all users.

--- produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] responses:

200:
  description: Ok
  schema:
    type: array
    items:
      $ref: "#/definitions/User"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"

func (*UserAPI) UpdateUserByID

func (a *UserAPI) UpdateUserByID(ctx *gin.Context)

UpdateUserByID updates and user by id swagger:operation POST /user/{id} user updateUser

Update a user.

--- consumes: application/json produces: application/json security: [clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters:

  • name: id in: path description: the user id required: true type: integer
  • name: body in: body description: the updated user required: true schema: $ref: "#/definitions/UserWithPass"

responses:

200:
  description: Ok
  schema:
      $ref: "#/definitions/User"
400:
  description: Bad Request
  schema:
      $ref: "#/definitions/Error"
401:
  description: Unauthorized
  schema:
      $ref: "#/definitions/Error"
403:
  description: Forbidden
  schema:
      $ref: "#/definitions/Error"
404:
  description: Not Found
  schema:
      $ref: "#/definitions/Error"

type UserDatabase

type UserDatabase interface {
	GetUsers() []*model.User
	GetUserByID(id uint) *model.User
	GetUserByName(name string) *model.User
	DeleteUserByID(id uint) error
	UpdateUser(user *model.User)
	CreateUser(user *model.User) error
}

The UserDatabase interface for encapsulating database access.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL