From 4e70486a9bce4242c7b1abe383fd832e94d86af5 Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 29 Aug 2018 14:40:03 +0200 Subject: [PATCH] Cleanup --- public/swagger/swagger.v1.json | 54 +-- routes/api/v1/oldhandlers.go | 638 +++++++++++++++------------------ routes/routes.go | 22 -- 3 files changed, 296 insertions(+), 418 deletions(-) diff --git a/public/swagger/swagger.v1.json b/public/swagger/swagger.v1.json index 2dd74690e..4816b5c63 100644 --- a/public/swagger/swagger.v1.json +++ b/public/swagger/swagger.v1.json @@ -1,24 +1,6 @@ { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "schemes": [ - "http", - "https" - ], "swagger": "2.0", - "info": { - "description": "This documentation describes the List API.", - "title": "List API.", - "license": { - "name": "GPLv3" - }, - "version": "0.1" - }, - "basePath": "/api/v1", + "info": {}, "paths": { "/item/{itemID}": { "put": { @@ -589,7 +571,7 @@ "name": "body", "in": "body", "schema": { - "$ref": "#/definitions/ApiUserPassword" + "$ref": "#/definitions/APIUserPassword" } } ], @@ -608,9 +590,9 @@ } }, "definitions": { - "ApiUserPassword": { + "APIUserPassword": { "type": "object", - "title": "ApiUserPassword represents a user object without timestamps and a json password field.", + "title": "APIUserPassword represents a user object without timestamps and a json password field.", "properties": { "email": { "type": "string", @@ -630,7 +612,7 @@ "x-go-name": "Username" } }, - "x-go-package": "git.kolaente.de/konrad/list/models" + "x-go-package": "code.vikunja.io/api/models" }, "List": { "description": "List represents a list of items", @@ -670,7 +652,7 @@ "x-go-name": "Updated" } }, - "x-go-package": "git.kolaente.de/konrad/list/models" + "x-go-package": "code.vikunja.io/api/models" }, "ListItem": { "description": "ListItem represents an item in a todolist", @@ -722,7 +704,7 @@ "x-go-name": "Updated" } }, - "x-go-package": "git.kolaente.de/konrad/list/models" + "x-go-package": "code.vikunja.io/api/models" }, "Message": { "description": "Message is a standard message", @@ -733,7 +715,7 @@ "x-go-name": "Message" } }, - "x-go-package": "git.kolaente.de/konrad/list/models" + "x-go-package": "code.vikunja.io/api/models" }, "Namespace": { "description": "Namespace holds informations about a namespace", @@ -766,7 +748,7 @@ "x-go-name": "Updated" } }, - "x-go-package": "git.kolaente.de/konrad/list/models" + "x-go-package": "code.vikunja.io/api/models" }, "User": { "description": "User holds information about an user", @@ -786,7 +768,7 @@ "x-go-name": "Username" } }, - "x-go-package": "git.kolaente.de/konrad/list/models" + "x-go-package": "code.vikunja.io/api/models" }, "UserLogin": { "description": "UserLogin Object to recive user credentials in JSON format", @@ -801,7 +783,7 @@ "x-go-name": "Username" } }, - "x-go-package": "git.kolaente.de/konrad/list/models" + "x-go-package": "code.vikunja.io/api/models" } }, "responses": { @@ -857,17 +839,5 @@ "$ref": "#/definitions/Namespace" } } - }, - "securityDefinitions": { - "AuthorizationHeaderToken": { - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - }, - "security": [ - { - "AuthorizationHeaderToken": [] - } - ] + } } \ No newline at end of file diff --git a/routes/api/v1/oldhandlers.go b/routes/api/v1/oldhandlers.go index 803bf7afa..597dee00e 100644 --- a/routes/api/v1/oldhandlers.go +++ b/routes/api/v1/oldhandlers.go @@ -1,368 +1,298 @@ package v1 -import ( - "github.com/labstack/echo" - "net/http" -) +// swagger:operation DELETE /item/{itemID} lists deleteListItem +// --- +// summary: Deletes a list item +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: itemID +// in: path +// description: ID of the list item to delete +// type: string +// required: true +// responses: +// "200": +// "$ref": "#/responses/Message" +// "400": +// "$ref": "#/responses/Message" +// "403": +// "$ref": "#/responses/Message" +// "404": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" -// DeleteListItemByIDtemByID is the web handler to delete a list item -func DeleteListItemByIDtemByID(c echo.Context) error { - // swagger:operation DELETE /item/{itemID} lists deleteListItem - // --- - // summary: Deletes a list item - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: itemID - // in: path - // description: ID of the list item to delete - // type: string - // required: true - // responses: - // "200": - // "$ref": "#/responses/Message" - // "400": - // "$ref": "#/responses/Message" - // "403": - // "$ref": "#/responses/Message" - // "404": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" +// swagger:operation DELETE /lists/{listID} lists deleteList +// --- +// summary: Deletes a list with all items on it +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: listID +// in: path +// description: ID of the list to delete +// type: string +// required: true +// responses: +// "200": +// "$ref": "#/responses/Message" +// "400": +// "$ref": "#/responses/Message" +// "403": +// "$ref": "#/responses/Message" +// "404": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" - return echo.NewHTTPError(http.StatusNotImplemented) -} +// swagger:operation PUT /lists/{listID} lists addListItem +// --- +// summary: Adds an item to a list +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: listID +// in: path +// description: ID of the list to use +// type: string +// required: true +// - name: body +// in: body +// schema: +// "$ref": "#/definitions/ListItem" +// responses: +// "200": +// "$ref": "#/responses/ListItem" +// "400": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" -// DeleteListByID ... -func DeleteListByID(c echo.Context) error { - // swagger:operation DELETE /lists/{listID} lists deleteList - // --- - // summary: Deletes a list with all items on it - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: listID - // in: path - // description: ID of the list to delete - // type: string - // required: true - // responses: - // "200": - // "$ref": "#/responses/Message" - // "400": - // "$ref": "#/responses/Message" - // "403": - // "$ref": "#/responses/Message" - // "404": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" +// swagger:operation PUT /item/{itemID} lists updateListItem +// --- +// summary: Updates a list item +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: itemID +// in: path +// description: ID of the item to update +// type: string +// required: true +// - name: body +// in: body +// schema: +// "$ref": "#/definitions/ListItem" +// responses: +// "200": +// "$ref": "#/responses/ListItem" +// "400": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" - return echo.NewHTTPError(http.StatusNotImplemented) -} +// swagger:operation GET /lists/{listID} lists getList +// --- +// summary: gets one list with all todo items +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: listID +// in: path +// description: ID of the list to show +// type: string +// required: true +// responses: +// "200": +// "$ref": "#/responses/List" +// "400": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" -// AddListItem ... -func AddListItem(c echo.Context) error { - // swagger:operation PUT /lists/{listID} lists addListItem - // --- - // summary: Adds an item to a list - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: listID - // in: path - // description: ID of the list to use - // type: string - // required: true - // - name: body - // in: body - // schema: - // "$ref": "#/definitions/ListItem" - // responses: - // "200": - // "$ref": "#/responses/ListItem" - // "400": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" +// swagger:operation PUT /namespaces/{namespaceID}/lists lists addList +// --- +// summary: Creates a new list owned by the currently logged in user in that namespace +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: namespaceID +// in: path +// description: ID of the namespace that list should belong to +// type: string +// required: true +// - name: body +// in: body +// required: true +// schema: +// "$ref": "#/definitions/List" +// responses: +// "200": +// "$ref": "#/responses/List" +// "400": +// "$ref": "#/responses/Message" +// "403": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" - return echo.NewHTTPError(http.StatusNotImplemented) -} +// swagger:operation POST /lists/{listID} lists upadteList +// --- +// summary: Updates a list +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: listID +// in: path +// description: ID of the list to update +// type: string +// required: true +// - name: body +// in: body +// schema: +// "$ref": "#/definitions/List" +// responses: +// "200": +// "$ref": "#/responses/List" +// "400": +// "$ref": "#/responses/Message" +// "403": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" -// UpdateListItem ... -func UpdateListItem(c echo.Context) error { - // swagger:operation PUT /item/{itemID} lists updateListItem - // --- - // summary: Updates a list item - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: itemID - // in: path - // description: ID of the item to update - // type: string - // required: true - // - name: body - // in: body - // schema: - // "$ref": "#/definitions/ListItem" - // responses: - // "200": - // "$ref": "#/responses/ListItem" - // "400": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" +// swagger:operation GET /lists lists getLists +// --- +// summary: Gets all lists owned by the current user +// consumes: +// - application/json +// produces: +// - application/json +// responses: +// "200": +// "$ref": "#/responses/List" +// "500": +// "$ref": "#/responses/Message" - return echo.NewHTTPError(http.StatusNotImplemented) -} +// swagger:operation PUT /namespaces namespaces addNamespace +// --- +// summary: Creates a new namespace owned by the currently logged in user +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: body +// in: body +// schema: +// "$ref": "#/definitions/Namespace" +// responses: +// "200": +// "$ref": "#/responses/Namespace" +// "400": +// "$ref": "#/responses/Message" +// "403": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" -// GetListByID Adds or updates a new list -func GetListByID(c echo.Context) error { - // swagger:operation GET /lists/{listID} lists getList - // --- - // summary: gets one list with all todo items - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: listID - // in: path - // description: ID of the list to show - // type: string - // required: true - // responses: - // "200": - // "$ref": "#/responses/List" - // "400": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" +// swagger:operation POST /namespaces/{namespaceID} namespaces upadteNamespace +// --- +// summary: Updates a namespace +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: namespaceID +// in: path +// description: ID of the namespace to update +// type: string +// required: true +// - name: body +// in: body +// schema: +// "$ref": "#/definitions/Namespace" +// responses: +// "200": +// "$ref": "#/responses/Namespace" +// "400": +// "$ref": "#/responses/Message" +// "403": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" - return echo.NewHTTPError(http.StatusNotImplemented) -} +// swagger:operation DELETE /namespaces/{namespaceID} namespaces deleteNamespace +// --- +// summary: Deletes a namespace with all lists +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: namespaceID +// in: path +// description: ID of the namespace to delete +// type: string +// required: true +// responses: +// "200": +// "$ref": "#/responses/Message" +// "400": +// "$ref": "#/responses/Message" +// "403": +// "$ref": "#/responses/Message" +// "404": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" -// AddList ... -func AddList(c echo.Context) error { - // swagger:operation PUT /namespaces/{namespaceID}/lists lists addList - // --- - // summary: Creates a new list owned by the currently logged in user in that namespace - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: namespaceID - // in: path - // description: ID of the namespace that list should belong to - // type: string - // required: true - // - name: body - // in: body - // required: true - // schema: - // "$ref": "#/definitions/List" - // responses: - // "200": - // "$ref": "#/responses/List" - // "400": - // "$ref": "#/responses/Message" - // "403": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" +// swagger:operation GET /namespaces/{namespaceID} namespaces getNamespace +// --- +// summary: gets one namespace with all todo items +// consumes: +// - application/json +// produces: +// - application/json +// parameters: +// - name: namespaceID +// in: path +// description: ID of the namespace to show +// type: string +// required: true +// responses: +// "200": +// "$ref": "#/responses/Namespace" +// "400": +// "$ref": "#/responses/Message" +// "500": +// "$ref": "#/responses/Message" - return echo.NewHTTPError(http.StatusNotImplemented) -} - -// UpdateList ... -func UpdateList(c echo.Context) error { - // swagger:operation POST /lists/{listID} lists upadteList - // --- - // summary: Updates a list - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: listID - // in: path - // description: ID of the list to update - // type: string - // required: true - // - name: body - // in: body - // schema: - // "$ref": "#/definitions/List" - // responses: - // "200": - // "$ref": "#/responses/List" - // "400": - // "$ref": "#/responses/Message" - // "403": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" - - return echo.NewHTTPError(http.StatusNotImplemented) -} - -// GetListsByUser gets all lists a user owns -func GetListsByUser(c echo.Context) error { - // swagger:operation GET /lists lists getLists - // --- - // summary: Gets all lists owned by the current user - // consumes: - // - application/json - // produces: - // - application/json - // responses: - // "200": - // "$ref": "#/responses/List" - // "500": - // "$ref": "#/responses/Message" - - return echo.NewHTTPError(http.StatusNotImplemented) -} - -// AddNamespace ... -func AddNamespace(c echo.Context) error { - // swagger:operation PUT /namespaces namespaces addNamespace - // --- - // summary: Creates a new namespace owned by the currently logged in user - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: body - // in: body - // schema: - // "$ref": "#/definitions/Namespace" - // responses: - // "200": - // "$ref": "#/responses/Namespace" - // "400": - // "$ref": "#/responses/Message" - // "403": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" - - return echo.NewHTTPError(http.StatusNotImplemented) -} - -// UpdateNamespace ... -func UpdateNamespace(c echo.Context) error { - // swagger:operation POST /namespaces/{namespaceID} namespaces upadteNamespace - // --- - // summary: Updates a namespace - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: namespaceID - // in: path - // description: ID of the namespace to update - // type: string - // required: true - // - name: body - // in: body - // schema: - // "$ref": "#/definitions/Namespace" - // responses: - // "200": - // "$ref": "#/responses/Namespace" - // "400": - // "$ref": "#/responses/Message" - // "403": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" - - return echo.NewHTTPError(http.StatusNotImplemented) -} - -// DeleteNamespaceByID ... -func DeleteNamespaceByID(c echo.Context) error { - // swagger:operation DELETE /namespaces/{namespaceID} namespaces deleteNamespace - // --- - // summary: Deletes a namespace with all lists - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: namespaceID - // in: path - // description: ID of the namespace to delete - // type: string - // required: true - // responses: - // "200": - // "$ref": "#/responses/Message" - // "400": - // "$ref": "#/responses/Message" - // "403": - // "$ref": "#/responses/Message" - // "404": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" - - return echo.NewHTTPError(http.StatusNotImplemented) -} - -// ShowNamespace ... -func ShowNamespace(c echo.Context) error { - // swagger:operation GET /namespaces/{namespaceID} namespaces getNamespace - // --- - // summary: gets one namespace with all todo items - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: namespaceID - // in: path - // description: ID of the namespace to show - // type: string - // required: true - // responses: - // "200": - // "$ref": "#/responses/Namespace" - // "400": - // "$ref": "#/responses/Message" - // "500": - // "$ref": "#/responses/Message" - - return echo.NewHTTPError(http.StatusNotImplemented) -} - -// GetAllNamespacesByCurrentUser ... -func GetAllNamespacesByCurrentUser(c echo.Context) error { - // swagger:operation GET /namespaces namespaces getNamespaces - // --- - // summary: Get all namespaces the currently logged in user has at least read access - // consumes: - // - application/json - // produces: - // - application/json - // responses: - // "200": - // "$ref": "#/responses/Namespace" - // "500": - // "$ref": "#/responses/Message" - - return echo.NewHTTPError(http.StatusNotImplemented) -} +// swagger:operation GET /namespaces namespaces getNamespaces +// --- +// summary: Get all namespaces the currently logged in user has at least read access +// consumes: +// - application/json +// produces: +// - application/json +// responses: +// "200": +// "$ref": "#/responses/Namespace" +// "500": +// "$ref": "#/responses/Message" diff --git a/routes/routes.go b/routes/routes.go index 9a1de9b74..8eda32b62 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -34,7 +34,6 @@ import ( apiv1 "code.vikunja.io/api/routes/api/v1" _ "code.vikunja.io/api/routes/api/v1/swagger" // for docs generation "code.vikunja.io/api/routes/crud" - "net/http" ) // NewEcho registers a new Echo instance @@ -83,27 +82,6 @@ func RegisterRoutes(e *echo.Echo) { a.POST("/login", apiv1.Login) a.POST("/register", apiv1.RegisterUser) - a.POST("/test/:infi/:Käsebrot/blub/:gedöns", func(c echo.Context) error { - - type testStruct struct { - Integ int64 `param:"infi" form:"infi"` - Cheese string `param:"Käsebrot"` - Kram string `param:"gedöns"` - Other string - Whooo int64 - Blub float64 - Test string `form:"test"` - } - - t := testStruct{} - - if err := crud.ParamBinder(&t, c); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.") - } - - return c.JSON(http.StatusOK, &t) - }) - // ===== Routes with Authetification ===== // Authetification a.Use(middleware.JWT(models.Config.JWTLoginSecret))