convert task service http endpoints into constants

pull/10616/head
Jade McGough 2018-10-09 11:23:42 -07:00
parent 35383074f3
commit bf29ff7ca3
1 changed files with 20 additions and 10 deletions

View File

@ -23,6 +23,16 @@ type TaskHandler struct {
OrganizationService platform.OrganizationService
}
const (
tasksPath = "/api/v2/tasks"
tasksIDPath = "/api/v2/tasks/:tid"
tasksIDLogsPath = "/api/v2/tasks/:tid/logs"
tasksIDRunsPath = "/api/v2/tasks/:tid/runs"
tasksIDRunsIDPath = "/api/v2/tasks/:tid/runs/:rid"
tasksIDRunsIDLogsPath = "/api/v2/tasks/:tid/runs/:rid/logs"
tasksIDRunsIDRetryPath = "/api/v2/tasks/:tid/runs/:rid/retry"
)
// NewTaskHandler returns a new instance of TaskHandler.
func NewTaskHandler(logger *zap.Logger) *TaskHandler {
h := &TaskHandler{
@ -30,19 +40,19 @@ func NewTaskHandler(logger *zap.Logger) *TaskHandler {
Router: httprouter.New(),
}
h.HandlerFunc("GET", "/api/v2/tasks", h.handleGetTasks)
h.HandlerFunc("POST", "/api/v2/tasks", h.handlePostTask)
h.HandlerFunc("GET", tasksPath, h.handleGetTasks)
h.HandlerFunc("POST", tasksPath, h.handlePostTask)
h.HandlerFunc("GET", "/api/v2/tasks/:tid", h.handleGetTask)
h.HandlerFunc("PATCH", "/api/v2/tasks/:tid", h.handleUpdateTask)
h.HandlerFunc("DELETE", "/api/v2/tasks/:tid", h.handleDeleteTask)
h.HandlerFunc("GET", tasksIDPath, h.handleGetTask)
h.HandlerFunc("PATCH", tasksIDPath, h.handleUpdateTask)
h.HandlerFunc("DELETE", tasksIDPath, h.handleDeleteTask)
h.HandlerFunc("GET", "/api/v2/tasks/:tid/logs", h.handleGetLogs)
h.HandlerFunc("GET", "/api/v2/tasks/:tid/runs/:rid/logs", h.handleGetLogs)
h.HandlerFunc("GET", tasksIDLogsPath, h.handleGetLogs)
h.HandlerFunc("GET", tasksIDRunsIDLogsPath, h.handleGetLogs)
h.HandlerFunc("GET", "/api/v2/tasks/:tid/runs", h.handleGetRuns)
h.HandlerFunc("GET", "/api/v2/tasks/:tid/runs/:rid", h.handleGetRun)
h.HandlerFunc("POST", "/api/v2/tasks/:tid/runs/:rid/retry", h.handleRetryRun)
h.HandlerFunc("GET", tasksIDRunsPath, h.handleGetRuns)
h.HandlerFunc("GET", tasksIDRunsIDPath, h.handleGetRun)
h.HandlerFunc("POST", tasksIDRunsIDRetryPath, h.handleRetryRun)
return h
}