mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 11:54:46 +00:00
Use API error helpers and improve response codes (#2366)
This commit is contained in:
@@ -40,10 +40,10 @@ import (
|
||||
func GetUsers(c *gin.Context) {
|
||||
users, err := store.FromContext(c).GetUserList(session.Pagination(c))
|
||||
if err != nil {
|
||||
c.String(500, "Error getting user list. %s", err)
|
||||
c.String(http.StatusInternalServerError, "Error getting user list. %s", err)
|
||||
return
|
||||
}
|
||||
c.JSON(200, users)
|
||||
c.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
||||
// GetUser
|
||||
@@ -59,10 +59,10 @@ func GetUsers(c *gin.Context) {
|
||||
func GetUser(c *gin.Context) {
|
||||
user, err := store.FromContext(c).GetUserLogin(c.Param("login"))
|
||||
if err != nil {
|
||||
handleDbGetError(c, err)
|
||||
handleDbError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(200, user)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
// PatchUser
|
||||
@@ -89,7 +89,7 @@ func PatchUser(c *gin.Context) {
|
||||
|
||||
user, err := _store.GetUserLogin(c.Param("login"))
|
||||
if err != nil {
|
||||
handleDbGetError(c, err)
|
||||
handleDbError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ func PostUser(c *gin.Context) {
|
||||
// @Summary Delete a user
|
||||
// @Description Deletes the given user. Requires admin rights.
|
||||
// @Router /users/{login} [delete]
|
||||
// @Produce json
|
||||
// @Success 200 {object} User
|
||||
// @Produce plain
|
||||
// @Success 204
|
||||
// @Tags Users
|
||||
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
||||
// @Param login path string true "the user's login name"
|
||||
@@ -159,12 +159,12 @@ func DeleteUser(c *gin.Context) {
|
||||
|
||||
user, err := _store.GetUserLogin(c.Param("login"))
|
||||
if err != nil {
|
||||
c.String(404, "Cannot find user. %s", err)
|
||||
handleDbError(c, err)
|
||||
return
|
||||
}
|
||||
if err = _store.DeleteUser(user); err != nil {
|
||||
c.String(500, "Error deleting user. %s", err)
|
||||
handleDbError(c, err)
|
||||
return
|
||||
}
|
||||
c.String(200, "")
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
Reference in New Issue
Block a user