1
0

Migrate to new swagger docs generation (#18)

This commit is contained in:
konrad
2018-11-12 15:46:35 +00:00
committed by Gitea
parent d3de658882
commit 373bbd2202
153 changed files with 32114 additions and 1416 deletions

View File

@ -10,19 +10,16 @@ import (
)
// Caldav returns a caldav-readable format with all tasks
// @Summary CalDAV-readable format with all tasks as calendar events.
// @Description Returns a calDAV-parsable format with all tasks as calendar events. Only returns tasks with a due date. Also creates reminders when the task has one.
// @tags task
// @Produce text/plain
// @Security BasicAuth
// @Success 200 {string} string "The caldav events."
// @Failure 403 {string} string "Unauthorized."
// @Router /tasks/caldav [get]
func Caldav(c echo.Context) error {
// swagger:operation GET /tasks/caldav list caldavTasks
// ---
// summary: Get all tasks as caldav
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// Request basic auth
user, pass, ok := c.Request().BasicAuth()

View File

@ -8,28 +8,20 @@ import (
)
// GetListsByNamespaceID is the web handler to delete a namespace
// TODO: depricate this in favour of namespace.ReadOne() <-- should also return the lists
// @Summary Get all lists in a namespace
// @Description Returns all lists inside of a namespace.
// @tags namespace
// @Accept json
// @Produce json
// @Param id path int true "Namespace ID"
// @Security ApiKeyAuth
// @Success 200 {array} models.List "The lists."
// @Failure 403 {object} models.Message "No access to that namespace."
// @Failure 404 {object} models.Message "The namespace does not exist."
// @Failure 500 {object} models.Message "Internal error"
// @Router /namespaces/{id}/lists [get]
func GetListsByNamespaceID(c echo.Context) error {
// swagger:operation GET /namespaces/{namespaceID}/lists namespaces getListsByNamespace
// ---
// summary: gets all lists belonging to that namespace
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: namespaceID
// in: path
// description: ID of the namespace
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Namespace"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// Get our namespace
namespace, err := getNamespace(c)
if err != nil {

View File

@ -12,28 +12,23 @@ import (
"time"
)
// Login is the login handler
func Login(c echo.Context) error {
// swagger:operation POST /login user login
// ---
// summary: Logs a user in. Returns a JWT-Token to authenticate requests
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/UserLogin"
// responses:
// "200":
// "$ref": "#/responses/Token"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// Token represents an authentification token
type Token struct {
Token string `json:"token"`
}
// Login is the login handler
// @Summary Login
// @Description Logs a user in. Returns a JWT-Token to authenticate further requests.
// @tags user
// @Accept json
// @Produce json
// @Param credentials body models.UserLogin true "The login credentials"
// @Success 200 {object} v1.Token
// @Failure 400 {object} models.Message "Invalid user password model."
// @Failure 403 {object} models.Message "Invalid username or password."
// @Router /login [post]
func Login(c echo.Context) error {
u := models.UserLogin{}
if err := c.Bind(&u); err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Please provide a username and password."})
@ -64,7 +59,5 @@ func Login(c echo.Context) error {
return err
}
return c.JSON(http.StatusOK, map[string]string{
"token": t,
})
return c.JSON(http.StatusOK, Token{Token: t})
}

View File

@ -1,54 +0,0 @@
package swagger
import (
"code.vikunja.io/api/pkg/models"
)
// not actually a response, just a hack to get go-swagger to include definitions
// of the various XYZOption structs
// parameterBodies
// swagger:response parameterBodies
type swaggerParameterBodies struct {
// in:body
UserLogin models.UserLogin
// in:body
APIUserPassword models.APIUserPassword
// in:body
List models.List
// in:body
ListTask models.ListTask
// in:body
Namespace models.Namespace
// in:body
Team models.Team
// in:body
TeamMember models.TeamMember
// in:body
TeamList models.TeamList
// in:body
TeamNamespace models.TeamNamespace
// in:body
ListUser models.ListUser
// in:body
NamespaceUser models.NamespaceUser
// in:body
PasswordReset models.PasswordReset
// in:body
PasswordTokenRequest models.PasswordTokenRequest
// in:body
EmailConfirm models.EmailConfirm
}

View File

@ -1,111 +0,0 @@
package swagger
import (
"code.vikunja.io/api/pkg/models"
)
// Message
// swagger:response Message
type swaggerResponseMessage struct {
// in:body
Body models.Message `json:"body"`
}
// ================
// User definitions
// ================
// User Object
// swagger:response User
type swaggerResponseUser struct {
// in:body
Body models.User `json:"body"`
}
// Token
// swagger:response Token
type swaggerResponseToken struct {
// The body message
// in:body
Body struct {
// The token
//
// Required: true
Token string `json:"token"`
} `json:"body"`
}
// ================
// List definitions
// ================
// List
// swagger:response List
type swaggerResponseLIst struct {
// in:body
Body models.List `json:"body"`
}
// ListTask
// swagger:response ListTask
type swaggerResponseLIstTask struct {
// in:body
Body models.ListTask `json:"body"`
}
// ================
// Namespace definitions
// ================
// Namespace
// swagger:response Namespace
type swaggerResponseNamespace struct {
// in:body
Body models.Namespace `json:"body"`
}
// ================
// Team definitions
// ================
// Team
// swagger:response Team
type swaggerResponseTeam struct {
// in:body
Body models.Team `json:"body"`
}
// TeamMember
// swagger:response TeamMember
type swaggerResponseTeamMember struct {
// in:body
Body models.TeamMember `json:"body"`
}
// TeamList
// swagger:response TeamList
type swaggerResponseTeamList struct {
// in:body
Body models.TeamList `json:"body"`
}
// TeamNamespace
// swagger:response TeamNamespace
type swaggerResponseTeamNamespace struct {
// in:body
Body models.TeamNamespace `json:"body"`
}
// UserList
// swagger:response UserList
type swaggerResponseUserList struct {
// in:body
Body models.ListUser `json:"body"`
}
// UserNamespace
// swagger:response UserNamespace
type swaggerResponseUserNamespace struct {
// in:body
Body models.NamespaceUser `json:"body"`
}

View File

@ -1,930 +0,0 @@
package v1
// swagger:operation DELETE /tasks/{taskID} lists deleteListTask
// ---
// summary: Deletes a list task
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: taskID
// in: path
// description: ID of the list task 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 tasks 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 /lists/{listID} lists addListTask
// ---
// summary: Adds an task 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/ListTask"
// responses:
// "200":
// "$ref": "#/responses/ListTask"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation POST /tasks/{taskID} lists updateListTask
// ---
// summary: Updates a list task
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: taskID
// in: path
// description: ID of the task to update
// type: string
// required: true
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/ListTask"
// responses:
// "200":
// "$ref": "#/responses/ListTask"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation GET /lists/{listID} lists getList
// ---
// summary: gets one list with all todo tasks
// 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 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 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"
// 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"
// 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"
// 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"
// 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"
// swagger:operation GET /namespaces/{namespaceID} namespaces getNamespace
// ---
// summary: gets one namespace with all todo tasks
// 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"
// swagger:operation GET /namespaces/{namespaceID}/lists lists getNamespaceLists
// ---
// summary: gets all lists in that namespace
// 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/List"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// 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"
// swagger:operation GET /teams teams getTeams
// ---
// summary: gets all teams the current user is part of
// consumes:
// - application/json
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/Team"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation GET /teams/{teamID} teams getTeamByID
// ---
// summary: gets infos about the team
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: teamID
// in: path
// description: ID of the team
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Team"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation PUT /teams teams createTeam
// ---
// summary: Creates a team
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/Team"
// responses:
// "200":
// "$ref": "#/responses/Team"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation POST /teams/{teamID} teams updateTeam
// ---
// summary: Updates a team
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: teamID
// in: path
// description: ID of the team you want to update
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/Team"
// responses:
// "200":
// "$ref": "#/responses/Team"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation DELETE /teams/{teamID} teams deleteTeam
// ---
// summary: Deletes a team
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: teamID
// in: path
// description: ID of the team you want to delete
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation PUT /teams/{teamID}/members teams addTeamMember
// ---
// summary: Adds a member to a team
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: teamID
// in: path
// description: ID of the team you want to add a member to
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/TeamMember"
// responses:
// "200":
// "$ref": "#/responses/TeamMember"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation DELETE /teams/{teamID}/members/{userID} teams removeTeamMember
// ---
// summary: Removes a member from a team
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: teamID
// in: path
// description: ID of the team you want to delete a member
// type: string
// required: true
// - name: userID
// in: path
// description: ID of the user you want to remove from the team
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation GET /namespaces/{namespaceID}/teams sharing getNamespaceTeams
// ---
// summary: gets all teams which have access to that namespace
// 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/Team"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation GET /lists/{listID}/teams sharing getTeamsByList
// ---
// summary: gets all teams which have access to the list
// 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/Team"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation PUT /lists/{listID}/teams sharing addTeamToList
// ---
// summary: adds a team 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/TeamList"
// responses:
// "200":
// "$ref": "#/responses/TeamList"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation DELETE /lists/{listID}/teams/{teamID} sharing deleteTeamFromList
// ---
// summary: removes a team from 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: teamID
// in: path
// description: ID of the team to remove
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation PUT /namespaces/{namespaceID}/teams sharing giveTeamAccessToNamespace
// ---
// summary: Gives a team access to a namespace
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: namespaceID
// in: path
// description: ID of the namespace to use
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/TeamNamespace"
// responses:
// "200":
// "$ref": "#/responses/TeamNamespace"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation DELETE /namespaces/{namespaceID}/teams/{teamID} sharing removeTeamFromNamespace
// ---
// summary: Removes a team from a namespace
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: namespaceID
// in: path
// description: ID of the namespace to use
// type: string
// required: true
// - name: teamID
// in: path
// description: ID of the team you want to remove
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation GET /lists/{listID}/users sharing getUsersByList
// ---
// summary: gets all users which have access to the list
// 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/User"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation PUT /lists/{listID}/users sharing addUserToList
// ---
// summary: adds a user 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/UserList"
// responses:
// "200":
// "$ref": "#/responses/UserList"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation DELETE /lists/{listID}/users/{userID} sharing deleteUserFromList
// ---
// summary: removes a user from 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: userID
// in: path
// description: ID of the user to remove
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation GET /namespaces/{namespaceID}/users sharing getNamespaceUsers
// ---
// summary: gets all users which have access to that namespace
// 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/User"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation PUT /namespaces/{namespaceID}/users sharing giveUserAccessToNamespace
// ---
// summary: Gives a user access to a namespace
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: namespaceID
// in: path
// description: ID of the namespace to use
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/UserNamespace"
// responses:
// "200":
// "$ref": "#/responses/UserNamespace"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation DELETE /namespaces/{namespaceID}/users/{userID} sharing removeUserFromNamespace
// ---
// summary: Removes a user from a namespace
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: namespaceID
// in: path
// description: ID of the namespace to use
// type: string
// required: true
// - name: userID
// in: path
// description: ID of the user you want to remove
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation POST /namespaces/{namespaceID}/users/{userID} sharing updateUserAccessToNamespace
// ---
// summary: Updates a users access to a namespace
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: namespaceID
// in: path
// description: ID of the namespace to use
// type: string
// required: true
// - name: userID
// in: path
// description: ID of the user to use
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/NamespaceUser"
// responses:
// "200":
// "$ref": "#/responses/NamespaceUser"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation POST /namespaces/{namespaceID}/teams/{teamID} sharing updateTeamAccessToNamespace
// ---
// summary: Updates a teams access to a namespace
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: namespaceID
// in: path
// description: ID of the namespace to use
// type: string
// required: true
// - name: teamID
// in: path
// description: ID of the team to use
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/TeamNamespace"
// responses:
// "200":
// "$ref": "#/responses/TeamNamespace"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation POST /lists/{listID}/users/{userID} sharing updateUserAccessToList
// ---
// summary: Updates a users access 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: userID
// in: path
// description: ID of the user to use
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/UserList"
// responses:
// "200":
// "$ref": "#/responses/UserList"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation POST /lists/{listID}/teams/{teamID} sharing updateTeamAccessToList
// ---
// summary: Updates a teams access 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: teamID
// in: path
// description: ID of the team to use
// type: string
// required: true
// - name: body
// in: body
// required: true
// schema:
// "$ref": "#/definitions/TeamList"
// responses:
// "200":
// "$ref": "#/responses/TeamList"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// swagger:operation GET /tasks lists getPendingTasks
// ---
// summary: gets all tasks for the currently authenticated user
// consumes:
// - application/json
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/ListTask"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"

View File

@ -5,78 +5,28 @@ import (
"code.vikunja.io/api/pkg/routes/crud"
"github.com/labstack/echo"
"net/http"
"strconv"
)
// RegisterUser ...
// RegisterUser is the register handler
// @Summary Register
// @Description Creates a new user account.
// @tags user
// @Accept json
// @Produce json
// @Param credentials body models.APIUserPassword true "The user credentials"
// @Success 200 {object} models.User
// @Failure 400 {object} models.HTTPError "No or invalid user register object provided / User already exists."
// @Failure 500 {object} models.Message "Internal error"
// @Router /register [post]
func RegisterUser(c echo.Context) error {
// swagger:operation POST /register user register
// ---
// summary: Creates a new user account
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/APIUserPassword"
// responses:
// "200":
// "$ref": "#/responses/User"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
return userAddOrUpdate(c)
}
// userAddOrUpdate is the handler to add a user
func userAddOrUpdate(c echo.Context) error {
// TODO: prevent everyone from updating users
// Check for Request Content
var datUser *models.APIUserPassword
if err := c.Bind(&datUser); err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"No user model provided."})
}
// Check if we have an ID other than the one in the struct
id := c.Param("id")
if id != "" {
// Make int
userID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
}
datUser.ID = userID
}
// Check if the user exists
var exists = true
_, err := models.GetUserByID(datUser.ID)
if err != nil {
if models.IsErrUserDoesNotExist(err) {
exists = false
} else {
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the user exists."})
}
}
// Insert or update the user
var newUser models.User
if exists {
newUser, err = models.UpdateUser(datUser.APIFormat())
} else {
newUser, err = models.CreateUser(datUser.APIFormat())
return c.JSON(http.StatusBadRequest, models.Message{"No or invalid user model provided."})
}
// Insert the user
newUser, err := models.CreateUser(datUser.APIFormat())
if err != nil {
return crud.HandleHTTPError(err)
}

View File

@ -8,29 +8,17 @@ import (
)
// UserConfirmEmail is the handler to confirm a user email
// @Summary Confirm the email of a new user
// @Description Confirms the email of a newly registered user.
// @tags user
// @Accept json
// @Produce json
// @Param credentials body models.EmailConfirm true "The token."
// @Success 200 {object} models.Message
// @Failure 412 {object} models.HTTPError "Bad token provided."
// @Failure 500 {object} models.Message "Internal error"
// @Router /user/confirm [post]
func UserConfirmEmail(c echo.Context) error {
// swagger:operation POST /user/confirm user confirmEmail
// ---
// summary: Confirms a users email address
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/EmailConfirm"
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "404":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// Check for Request Content
var emailConfirm models.EmailConfirm
if err := c.Bind(&emailConfirm); err != nil {

View File

@ -8,27 +8,18 @@ import (
)
// UserList gets all information about a user
// @Summary Get users
// @Description Lists all users (without emailadresses). Also possible to search for a specific user.
// @tags user
// @Accept json
// @Produce json
// @Param s query string false "Search for a user by its name."
// @Security ApiKeyAuth
// @Success 200 {array} models.User "All (found) users."
// @Failure 400 {object} models.HTTPError "Something's invalid."
// @Failure 500 {object} models.Message "Internal server error."
// @Router /users [get]
func UserList(c echo.Context) error {
// swagger:operation GET /users user list
// ---
// summary: Lists all users
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: s
// description: A searchterm to search for a user by its username
// in: query
// responses:
// "200":
// "$ref": "#/responses/User"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
s := c.QueryParam("s")
users, err := models.ListUsers(s)
if err != nil {

View File

@ -8,29 +8,17 @@ import (
)
// UserResetPassword is the handler to change a users password
// @Summary Resets a password
// @Description Resets a user email with a previously reset token.
// @tags user
// @Accept json
// @Produce json
// @Param credentials body models.PasswordReset true "The token with the new password."
// @Success 200 {object} models.Message
// @Failure 400 {object} models.HTTPError "Bad token provided."
// @Failure 500 {object} models.Message "Internal error"
// @Router /user/password/reset [post]
func UserResetPassword(c echo.Context) error {
// swagger:operation POST /user/password/reset user updatePassword
// ---
// summary: Resets a users password
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/PasswordReset"
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "404":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// Check for Request Content
var pwReset models.PasswordReset
if err := c.Bind(&pwReset); err != nil {
@ -46,33 +34,21 @@ func UserResetPassword(c echo.Context) error {
}
// UserRequestResetPasswordToken is the handler to change a users password
// @Summary Request password reset token
// @Description Requests a token to reset a users password. The token is sent via email.
// @tags user
// @Accept json
// @Produce json
// @Param credentials body models.PasswordTokenRequest true "The username of the user to request a token for."
// @Success 200 {object} models.Message
// @Failure 404 {object} models.HTTPError "The user does not exist."
// @Failure 500 {object} models.Message "Internal error"
// @Router /user/password/token [post]
func UserRequestResetPasswordToken(c echo.Context) error {
// swagger:operation POST /user/password/token user requestUpdatePasswordToken
// ---
// summary: Requests a token to reset a users password
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/PasswordTokenRequest"
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "404":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// Check for Request Content
var pwTokenReset models.PasswordTokenRequest
if err := c.Bind(&pwTokenReset); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "No user ID provided.")
return echo.NewHTTPError(http.StatusBadRequest, "No username provided.")
}
err := models.RequestUserPasswordResetToken(&pwTokenReset)

View File

@ -8,22 +8,17 @@ import (
)
// UserShow gets all informations about the current user
// @Summary Get user information
// @Description Returns the current user object.
// @tags user
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {object} models.User
// @Failure 404 {object} models.HTTPError "User does not exist."
// @Failure 500 {object} models.Message "Internal server error."
// @Router /user [get]
func UserShow(c echo.Context) error {
// swagger:operation GET /user user showUser
// ---
// summary: Shows the current user
// consumes:
// - application/json
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/User"
// "400":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
userInfos, err := models.GetCurrentUser(c)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting current user.")

View File

@ -14,29 +14,19 @@ type UserPassword struct {
}
// UserChangePassword is the handler to change a users password
// @Summary Change password
// @Description Lets the current user change its password.
// @tags user
// @Accept json
// @Produce json
// @Param userPassword body v1.UserPassword true "The current and new password."
// @Security ApiKeyAuth
// @Success 200 {object} models.Message
// @Failure 400 {object} models.HTTPError "Something's invalid."
// @Failure 404 {object} models.HTTPError "User does not exist."
// @Failure 500 {object} models.Message "Internal server error."
// @Router /user/password [post]
func UserChangePassword(c echo.Context) error {
// swagger:operation POST /user/password user updatePassword
// ---
// summary: Shows the current user
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/Password"
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "404":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
// Check if the user is itself
doer, err := models.GetCurrentUser(c)
if err != nil {

View File

@ -1,28 +1,12 @@
// Package v1 List API.
//
// This documentation describes the List API.
//
// Schemes: http, https
// BasePath: /api/v1
// Version: 0.1
// License: GPLv3
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// - AuthorizationHeaderToken :
//
// SecurityDefinitions:
// AuthorizationHeaderToken:
// type: apiKey
// name: Authorization
// in: header
//
// swagger:meta
// @title Vikunja API
// @license.name GPLv3
// @BasePath /api/v1
// @securityDefinitions.basic BasicAuth
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
package routes
@ -30,9 +14,10 @@ import (
"code.vikunja.io/api/pkg/models"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/swaggo/echo-swagger"
_ "code.vikunja.io/api/docs" // To generate swagger docs
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
_ "code.vikunja.io/api/pkg/routes/api/v1/swagger" // for docs generation
"code.vikunja.io/api/pkg/routes/crud"
"github.com/spf13/viper"
)
@ -63,7 +48,7 @@ func RegisterRoutes(e *echo.Echo) {
a := e.Group("/api/v1")
// Swagger UI
a.Static("/swagger", viper.GetString("service.rootpath")+"/public/swagger")
a.GET("/swagger/*", echoSwagger.WrapHandler)
a.POST("/login", apiv1.Login)
a.POST("/register", apiv1.RegisterUser)
@ -101,16 +86,10 @@ func RegisterRoutes(e *echo.Echo) {
},
}
a.PUT("/lists/:list", taskHandler.CreateWeb)
a.GET("/tasks", taskHandler.ReadAllWeb)
a.DELETE("/tasks/:listtask", taskHandler.DeleteWeb)
a.POST("/tasks/:listtask", taskHandler.UpdateWeb)
listTaskHandler := &crud.WebHandler{
EmptyStruct: func() crud.CObject {
return &models.ListTasksDummy{}
},
}
a.GET("/tasks", listTaskHandler.ReadAllWeb)
listTeamHandler := &crud.WebHandler{
EmptyStruct: func() crud.CObject {
return &models.TeamList{}