mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Swagger info corrections (#9441)
* use numbers and not http.Status___ enum
* fix test
* add many missing swagger responses
* code format
* Deletion Sould return 204 ...
* error handling improvements
* if special error type ... then add it to swagger too
* one smal nit
* invalidTopicsError is []string
* valid swagger specification 2.0
- if you add responses swagger can tell you if you do it right 👍
* use ctx.InternalServerError
* Revert "use numbers and not http.Status___ enum"
This reverts commit b1ff386e24
.
* use http.Status* enum everywhere
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
@@ -45,6 +47,9 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/TrackedTimeList"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||
ctx.NotFound("Timetracker is disabled")
|
||||
return
|
||||
@@ -54,18 +59,18 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
} else {
|
||||
ctx.Error(500, "GetIssueByIndex", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{IssueID: issue.ID})
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetTrackedTimesByIssue", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByIssue", err)
|
||||
return
|
||||
}
|
||||
apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes)
|
||||
ctx.JSON(200, &apiTrackedTimes)
|
||||
ctx.JSON(http.StatusOK, &apiTrackedTimes)
|
||||
}
|
||||
|
||||
// AddTime adds time manual to the given issue
|
||||
@@ -104,31 +109,32 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) {
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
// "403":
|
||||
// "$ref": "#/responses/error"
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
} else {
|
||||
ctx.Error(500, "GetIssueByIndex", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||
ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"})
|
||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
||||
return
|
||||
}
|
||||
ctx.Status(403)
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
trackedTime, err := models.AddTime(ctx.User, issue, form.Time)
|
||||
if err != nil {
|
||||
ctx.Error(500, "AddTime", err)
|
||||
ctx.Error(http.StatusInternalServerError, "AddTime", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, trackedTime.APIFormat())
|
||||
ctx.JSON(http.StatusOK, trackedTime.APIFormat())
|
||||
}
|
||||
|
||||
// ListTrackedTimesByUser lists all tracked times of the user
|
||||
@@ -157,8 +163,11 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/TrackedTimeList"
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||
ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"})
|
||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
||||
return
|
||||
}
|
||||
user, err := models.GetUserByName(ctx.Params(":timetrackingusername"))
|
||||
@@ -166,7 +175,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
} else {
|
||||
ctx.Error(500, "GetUserByName", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -178,11 +187,11 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
||||
UserID: user.ID,
|
||||
RepositoryID: ctx.Repo.Repository.ID})
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetTrackedTimesByUser", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
|
||||
return
|
||||
}
|
||||
apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes)
|
||||
ctx.JSON(200, &apiTrackedTimes)
|
||||
ctx.JSON(http.StatusOK, &apiTrackedTimes)
|
||||
}
|
||||
|
||||
// ListTrackedTimesByRepository lists all tracked times of the repository
|
||||
@@ -206,18 +215,21 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/TrackedTimeList"
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||
ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"})
|
||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
||||
return
|
||||
}
|
||||
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{
|
||||
RepositoryID: ctx.Repo.Repository.ID})
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetTrackedTimesByUser", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
|
||||
return
|
||||
}
|
||||
apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes)
|
||||
ctx.JSON(200, &apiTrackedTimes)
|
||||
ctx.JSON(http.StatusOK, &apiTrackedTimes)
|
||||
}
|
||||
|
||||
// ListMyTrackedTimes lists all tracked times of the current user
|
||||
@@ -230,11 +242,12 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/TrackedTimeList"
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{UserID: ctx.User.ID})
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetTrackedTimesByUser", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
|
||||
return
|
||||
}
|
||||
apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes)
|
||||
ctx.JSON(200, &apiTrackedTimes)
|
||||
ctx.JSON(http.StatusOK, &apiTrackedTimes)
|
||||
}
|
||||
|
Reference in New Issue
Block a user