This commit is contained in:
konrad 2018-08-29 14:40:03 +02:00 committed by kolaente
parent bdff353e78
commit 4e70486a9b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 296 additions and 418 deletions

View File

@ -1,24 +1,6 @@
{ {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http",
"https"
],
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {},
"description": "This documentation describes the List API.",
"title": "List API.",
"license": {
"name": "GPLv3"
},
"version": "0.1"
},
"basePath": "/api/v1",
"paths": { "paths": {
"/item/{itemID}": { "/item/{itemID}": {
"put": { "put": {
@ -589,7 +571,7 @@
"name": "body", "name": "body",
"in": "body", "in": "body",
"schema": { "schema": {
"$ref": "#/definitions/ApiUserPassword" "$ref": "#/definitions/APIUserPassword"
} }
} }
], ],
@ -608,9 +590,9 @@
} }
}, },
"definitions": { "definitions": {
"ApiUserPassword": { "APIUserPassword": {
"type": "object", "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": { "properties": {
"email": { "email": {
"type": "string", "type": "string",
@ -630,7 +612,7 @@
"x-go-name": "Username" "x-go-name": "Username"
} }
}, },
"x-go-package": "git.kolaente.de/konrad/list/models" "x-go-package": "code.vikunja.io/api/models"
}, },
"List": { "List": {
"description": "List represents a list of items", "description": "List represents a list of items",
@ -670,7 +652,7 @@
"x-go-name": "Updated" "x-go-name": "Updated"
} }
}, },
"x-go-package": "git.kolaente.de/konrad/list/models" "x-go-package": "code.vikunja.io/api/models"
}, },
"ListItem": { "ListItem": {
"description": "ListItem represents an item in a todolist", "description": "ListItem represents an item in a todolist",
@ -722,7 +704,7 @@
"x-go-name": "Updated" "x-go-name": "Updated"
} }
}, },
"x-go-package": "git.kolaente.de/konrad/list/models" "x-go-package": "code.vikunja.io/api/models"
}, },
"Message": { "Message": {
"description": "Message is a standard message", "description": "Message is a standard message",
@ -733,7 +715,7 @@
"x-go-name": "Message" "x-go-name": "Message"
} }
}, },
"x-go-package": "git.kolaente.de/konrad/list/models" "x-go-package": "code.vikunja.io/api/models"
}, },
"Namespace": { "Namespace": {
"description": "Namespace holds informations about a namespace", "description": "Namespace holds informations about a namespace",
@ -766,7 +748,7 @@
"x-go-name": "Updated" "x-go-name": "Updated"
} }
}, },
"x-go-package": "git.kolaente.de/konrad/list/models" "x-go-package": "code.vikunja.io/api/models"
}, },
"User": { "User": {
"description": "User holds information about an user", "description": "User holds information about an user",
@ -786,7 +768,7 @@
"x-go-name": "Username" "x-go-name": "Username"
} }
}, },
"x-go-package": "git.kolaente.de/konrad/list/models" "x-go-package": "code.vikunja.io/api/models"
}, },
"UserLogin": { "UserLogin": {
"description": "UserLogin Object to recive user credentials in JSON format", "description": "UserLogin Object to recive user credentials in JSON format",
@ -801,7 +783,7 @@
"x-go-name": "Username" "x-go-name": "Username"
} }
}, },
"x-go-package": "git.kolaente.de/konrad/list/models" "x-go-package": "code.vikunja.io/api/models"
} }
}, },
"responses": { "responses": {
@ -857,17 +839,5 @@
"$ref": "#/definitions/Namespace" "$ref": "#/definitions/Namespace"
} }
} }
}, }
"securityDefinitions": {
"AuthorizationHeaderToken": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
},
"security": [
{
"AuthorizationHeaderToken": []
}
]
} }

View File

@ -1,368 +1,298 @@
package v1 package v1
import ( // swagger:operation DELETE /item/{itemID} lists deleteListItem
"github.com/labstack/echo" // ---
"net/http" // 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 // swagger:operation DELETE /lists/{listID} lists deleteList
func DeleteListItemByIDtemByID(c echo.Context) error { // ---
// swagger:operation DELETE /item/{itemID} lists deleteListItem // summary: Deletes a list with all items on it
// --- // consumes:
// summary: Deletes a list item // - application/json
// consumes: // produces:
// - application/json // - application/json
// produces: // parameters:
// - application/json // - name: listID
// parameters: // in: path
// - name: itemID // description: ID of the list to delete
// in: path // type: string
// description: ID of the list item to delete // required: true
// type: string // responses:
// required: true // "200":
// responses: // "$ref": "#/responses/Message"
// "200": // "400":
// "$ref": "#/responses/Message" // "$ref": "#/responses/Message"
// "400": // "403":
// "$ref": "#/responses/Message" // "$ref": "#/responses/Message"
// "403": // "404":
// "$ref": "#/responses/Message" // "$ref": "#/responses/Message"
// "404": // "500":
// "$ref": "#/responses/Message" // "$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 ... // swagger:operation PUT /item/{itemID} lists updateListItem
func DeleteListByID(c echo.Context) error { // ---
// swagger:operation DELETE /lists/{listID} lists deleteList // summary: Updates a list item
// --- // consumes:
// summary: Deletes a list with all items on it // - application/json
// consumes: // produces:
// - application/json // - application/json
// produces: // parameters:
// - application/json // - name: itemID
// parameters: // in: path
// - name: listID // description: ID of the item to update
// in: path // type: string
// description: ID of the list to delete // required: true
// type: string // - name: body
// required: true // in: body
// responses: // schema:
// "200": // "$ref": "#/definitions/ListItem"
// "$ref": "#/responses/Message" // responses:
// "400": // "200":
// "$ref": "#/responses/Message" // "$ref": "#/responses/ListItem"
// "403": // "400":
// "$ref": "#/responses/Message" // "$ref": "#/responses/Message"
// "404": // "500":
// "$ref": "#/responses/Message" // "$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 ... // swagger:operation PUT /namespaces/{namespaceID}/lists lists addList
func AddListItem(c echo.Context) error { // ---
// swagger:operation PUT /lists/{listID} lists addListItem // summary: Creates a new list owned by the currently logged in user in that namespace
// --- // consumes:
// summary: Adds an item to a list // - application/json
// consumes: // produces:
// - application/json // - application/json
// produces: // parameters:
// - application/json // - name: namespaceID
// parameters: // in: path
// - name: listID // description: ID of the namespace that list should belong to
// in: path // type: string
// description: ID of the list to use // required: true
// type: string // - name: body
// required: true // in: body
// - name: body // required: true
// in: body // schema:
// schema: // "$ref": "#/definitions/List"
// "$ref": "#/definitions/ListItem" // responses:
// responses: // "200":
// "200": // "$ref": "#/responses/List"
// "$ref": "#/responses/ListItem" // "400":
// "400": // "$ref": "#/responses/Message"
// "$ref": "#/responses/Message" // "403":
// "500": // "$ref": "#/responses/Message"
// "$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 ... // swagger:operation GET /lists lists getLists
func UpdateListItem(c echo.Context) error { // ---
// swagger:operation PUT /item/{itemID} lists updateListItem // summary: Gets all lists owned by the current user
// --- // consumes:
// summary: Updates a list item // - application/json
// consumes: // produces:
// - application/json // - application/json
// produces: // responses:
// - application/json // "200":
// parameters: // "$ref": "#/responses/List"
// - name: itemID // "500":
// in: path // "$ref": "#/responses/Message"
// 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 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 // swagger:operation POST /namespaces/{namespaceID} namespaces upadteNamespace
func GetListByID(c echo.Context) error { // ---
// swagger:operation GET /lists/{listID} lists getList // summary: Updates a namespace
// --- // consumes:
// summary: gets one list with all todo items // - application/json
// consumes: // produces:
// - application/json // - application/json
// produces: // parameters:
// - application/json // - name: namespaceID
// parameters: // in: path
// - name: listID // description: ID of the namespace to update
// in: path // type: string
// description: ID of the list to show // required: true
// type: string // - name: body
// required: true // in: body
// responses: // schema:
// "200": // "$ref": "#/definitions/Namespace"
// "$ref": "#/responses/List" // responses:
// "400": // "200":
// "$ref": "#/responses/Message" // "$ref": "#/responses/Namespace"
// "500": // "400":
// "$ref": "#/responses/Message" // "$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 ... // swagger:operation GET /namespaces/{namespaceID} namespaces getNamespace
func AddList(c echo.Context) error { // ---
// swagger:operation PUT /namespaces/{namespaceID}/lists lists addList // summary: gets one namespace with all todo items
// --- // consumes:
// summary: Creates a new list owned by the currently logged in user in that namespace // - application/json
// consumes: // produces:
// - application/json // - application/json
// produces: // parameters:
// - application/json // - name: namespaceID
// parameters: // in: path
// - name: namespaceID // description: ID of the namespace to show
// in: path // type: string
// description: ID of the namespace that list should belong to // required: true
// type: string // responses:
// required: true // "200":
// - name: body // "$ref": "#/responses/Namespace"
// in: body // "400":
// required: true // "$ref": "#/responses/Message"
// schema: // "500":
// "$ref": "#/definitions/List" // "$ref": "#/responses/Message"
// responses:
// "200":
// "$ref": "#/responses/List"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "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
// UpdateList ... // consumes:
func UpdateList(c echo.Context) error { // - application/json
// swagger:operation POST /lists/{listID} lists upadteList // produces:
// --- // - application/json
// summary: Updates a list // responses:
// consumes: // "200":
// - application/json // "$ref": "#/responses/Namespace"
// produces: // "500":
// - application/json // "$ref": "#/responses/Message"
// 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)
}

View File

@ -34,7 +34,6 @@ import (
apiv1 "code.vikunja.io/api/routes/api/v1" apiv1 "code.vikunja.io/api/routes/api/v1"
_ "code.vikunja.io/api/routes/api/v1/swagger" // for docs generation _ "code.vikunja.io/api/routes/api/v1/swagger" // for docs generation
"code.vikunja.io/api/routes/crud" "code.vikunja.io/api/routes/crud"
"net/http"
) )
// NewEcho registers a new Echo instance // NewEcho registers a new Echo instance
@ -83,27 +82,6 @@ func RegisterRoutes(e *echo.Echo) {
a.POST("/login", apiv1.Login) a.POST("/login", apiv1.Login)
a.POST("/register", apiv1.RegisterUser) 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 ===== // ===== Routes with Authetification =====
// Authetification // Authetification
a.Use(middleware.JWT(models.Config.JWTLoginSecret)) a.Use(middleware.JWT(models.Config.JWTLoginSecret))