diff --git a/api/application.go b/api/application.go index 13146c2..ed4ce39 100644 --- a/api/application.go +++ b/api/application.go @@ -31,6 +31,39 @@ type ApplicationAPI struct { } // 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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *ApplicationAPI) CreateApplication(ctx *gin.Context) { app := model.Application{} if err := ctx.Bind(&app); err == nil { @@ -42,6 +75,34 @@ func (a *ApplicationAPI) CreateApplication(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 (a *ApplicationAPI) GetApplications(ctx *gin.Context) { userID := auth.GetUserID(ctx) apps := a.DB.GetApplicationsByUser(userID) @@ -52,6 +113,36 @@ func (a *ApplicationAPI) GetApplications(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 +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *ApplicationAPI) DeleteApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if app := a.DB.GetApplicationByID(id); app != nil && app.UserID == auth.GetUserID(ctx) { @@ -66,6 +157,48 @@ func (a *ApplicationAPI) DeleteApplication(ctx *gin.Context) { } // UpdateApplication updates an application info by its id. +// swagger:operation PUT /application/{id} application updateApplication +// +// Update info for 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" func (a *ApplicationAPI) UpdateApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if app := a.DB.GetApplicationByID(id); app != nil && app.UserID == auth.GetUserID(ctx) { @@ -85,6 +218,43 @@ func (a *ApplicationAPI) UpdateApplication(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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *ApplicationAPI) UploadApplicationImage(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if app := a.DB.GetApplicationByID(id); app != nil && app.UserID == auth.GetUserID(ctx) { diff --git a/api/client.go b/api/client.go index 0d9a229..314d603 100644 --- a/api/client.go +++ b/api/client.go @@ -25,6 +25,39 @@ type ClientAPI struct { } // 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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *ClientAPI) CreateClient(ctx *gin.Context) { client := model.Client{} if err := ctx.Bind(&client); err == nil { @@ -36,6 +69,34 @@ func (a *ClientAPI) CreateClient(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" func (a *ClientAPI) GetClients(ctx *gin.Context) { userID := auth.GetUserID(ctx) clients := a.DB.GetClientsByUser(userID) @@ -43,6 +104,36 @@ func (a *ClientAPI) GetClients(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 +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *ClientAPI) DeleteClient(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if client := a.DB.GetClientByID(id); client != nil && client.UserID == auth.GetUserID(ctx) { diff --git a/api/message.go b/api/message.go index cfa1e07..c7fca84 100644 --- a/api/message.go +++ b/api/message.go @@ -46,6 +46,45 @@ type pagingParams struct { } // 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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) GetMessages(ctx *gin.Context) { userID := auth.GetUserID(ctx) withPaging(ctx, func(params *pagingParams) { @@ -84,6 +123,50 @@ func withPaging(ctx *gin.Context, f func(pagingParams *pagingParams)) { } // 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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) GetMessagesWithApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { withPaging(ctx, func(params *pagingParams) { @@ -99,12 +182,62 @@ func (a *MessageAPI) GetMessagesWithApplication(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 (a *MessageAPI) DeleteMessages(ctx *gin.Context) { userID := auth.GetUserID(ctx) a.DB.DeleteMessagesByUser(userID) } // 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 +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) DeleteMessageWithApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if application := a.DB.GetApplicationByID(id); application != nil && application.UserID == auth.GetUserID(ctx) { @@ -116,6 +249,34 @@ func (a *MessageAPI) DeleteMessageWithApplication(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 +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) DeleteMessage(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if msg := a.DB.GetMessageByID(id); msg != nil && a.DB.GetApplicationByID(msg.ApplicationID).UserID == auth.GetUserID(ctx) { @@ -127,6 +288,31 @@ func (a *MessageAPI) DeleteMessage(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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) CreateMessage(ctx *gin.Context) { message := model.Message{} if err := ctx.Bind(&message); err == nil { diff --git a/api/stream/stream.go b/api/stream/stream.go index 4a46fba..4ce9cb3 100644 --- a/api/stream/stream.go +++ b/api/stream/stream.go @@ -117,6 +117,31 @@ func (a *API) register(client *client) { // Handle handles incoming requests. First it upgrades the protocol to the WebSocket protocol and then starts listening // for read and writes. +// swagger:operation GET /stream message streamMessages +// +// Websocket, return newly created messages. +// +// --- +// schema: ws, wss +// produces: +// - application/json +// security: +// - clientTokenHeader: [] +// - clientTokenQuery: [] +// - basicAuth: [] +// responses: +// 200: +// description: Ok +// schema: +// $ref: "#/definitions/Message" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *API) Handle(ctx *gin.Context) { conn, err := upgrader.Upgrade(ctx.Writer, ctx.Request, nil) if err != nil { diff --git a/api/user.go b/api/user.go index 0da81d2..a2114e0 100644 --- a/api/user.go +++ b/api/user.go @@ -27,6 +27,32 @@ type UserAPI struct { } // 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 (a *UserAPI) GetUsers(ctx *gin.Context) { users := a.DB.GetUsers() @@ -39,12 +65,69 @@ func (a *UserAPI) GetUsers(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 (a *UserAPI) GetCurrentUser(ctx *gin.Context) { user := a.DB.GetUserByID(auth.GetUserID(ctx)) ctx.JSON(200, toExternal(user)) } // 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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) CreateUser(ctx *gin.Context) { user := model.UserExternalWithPass{} if err := ctx.Bind(&user); err == nil { @@ -59,6 +142,38 @@ func (a *UserAPI) CreateUser(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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) GetUserByID(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if user := a.DB.GetUserByID(uint(id)); user != nil { @@ -70,6 +185,34 @@ func (a *UserAPI) GetUserByID(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 +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) DeleteUserByID(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if user := a.DB.GetUserByID(id); user != nil { @@ -82,6 +225,37 @@ func (a *UserAPI) DeleteUserByID(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 +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) ChangePassword(ctx *gin.Context) { pw := model.UserExternalPass{} if err := ctx.Bind(&pw); err == nil { @@ -92,6 +266,44 @@ func (a *UserAPI) ChangePassword(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" +// 401: +// description: Unauthorized +// schema: +// $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) UpdateUserByID(ctx *gin.Context) { withID(ctx, "id", func(id uint) { var user *model.UserExternalWithPass diff --git a/router/router.go b/router/router.go index a77944d..e240386 100644 --- a/router/router.go +++ b/router/router.go @@ -75,36 +75,6 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co ctx.JSON(200, vInfo) }) - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" g.Group("/").Use(authentication.RequireApplicationToken()).POST("/message", messageHandler.CreateMessage) clientAuth := g.Group("") @@ -112,548 +82,51 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co clientAuth.Use(authentication.RequireClient()) app := clientAuth.Group("/application") { - // 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" + app.GET("", applicationHandler.GetApplications) - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" app.POST("", applicationHandler.CreateApplication) - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" app.POST("/:id/image", applicationHandler.UploadApplicationImage) - // swagger:operation PUT /application/{id} application updateApplication - // - // Update info for 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" + app.PUT("/:id", applicationHandler.UpdateApplication) - // 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 - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" app.DELETE("/:id", applicationHandler.DeleteApplication) tokenMessage := app.Group("/:id/message") { - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" + tokenMessage.GET("", messageHandler.GetMessagesWithApplication) - // 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 - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" tokenMessage.DELETE("", messageHandler.DeleteMessageWithApplication) } } client := clientAuth.Group("/client") { - // 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" + client.GET("", clientHandler.GetClients) - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" client.POST("", clientHandler.CreateClient) - // 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 - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" client.DELETE("/:id", clientHandler.DeleteClient) } message := clientAuth.Group("/message") { - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" + message.GET("", messageHandler.GetMessages) - // 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" message.DELETE("", messageHandler.DeleteMessages) - // 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 - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" message.DELETE("/:id", messageHandler.DeleteMessage) } - // swagger:operation GET /stream message streamMessages - // - // Websocket, return newly created messages. - // - // --- - // schema: ws, wss - // produces: - // - application/json - // security: - // - clientTokenHeader: [] - // - clientTokenQuery: [] - // - basicAuth: [] - // responses: - // 200: - // description: Ok - // schema: - // $ref: "#/definitions/Message" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" clientAuth.GET("/stream", streamHandler.Handle) - // 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" clientAuth.GET("current/user", userHandler.GetCurrentUser) - // 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 - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" clientAuth.POST("current/user/password", userHandler.ChangePassword) } @@ -661,171 +134,14 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co { authAdmin.Use(authentication.RequireAdmin()) - // 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" authAdmin.GET("", userHandler.GetUsers) - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" authAdmin.POST("", userHandler.CreateUser) - // 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 - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" authAdmin.DELETE("/:id", userHandler.DeleteUserByID) - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" authAdmin.GET("/:id", userHandler.GetUserByID) - // 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" - // 401: - // description: Unauthorized - // schema: - // $ref: "#/definitions/Error" - // 403: - // description: Forbidden - // schema: - // $ref: "#/definitions/Error" authAdmin.POST("/:id", userHandler.UpdateUserByID) } return g, streamHandler.Close