chore(repo): reinitialize repository
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
tasksapp "inbox/internal/app/tasks"
|
||||
"inbox/internal/base/httpx"
|
||||
"inbox/internal/domain/task"
|
||||
)
|
||||
|
||||
func (h *Handler) listTasks(w http.ResponseWriter, r *http.Request) {
|
||||
items, err := h.Tasks.ListByTopic(r.Context(), r.PathValue("topicID"))
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"tasks": items})
|
||||
}
|
||||
|
||||
func (h *Handler) createTask(w http.ResponseWriter, r *http.Request) {
|
||||
type dependency struct {
|
||||
DependsOnTaskID string `json:"depends_on_task_id"`
|
||||
}
|
||||
type request struct {
|
||||
WorkspaceID string `json:"workspace_id"`
|
||||
LaneID string `json:"lane_id"`
|
||||
Title string `json:"title"`
|
||||
BodyMarkdown string `json:"body_markdown"`
|
||||
AcceptanceMarkdown string `json:"acceptance_markdown"`
|
||||
Kind string `json:"kind"`
|
||||
Deliverables []string `json:"deliverables"`
|
||||
BatchKey string `json:"batch_key"`
|
||||
Status string `json:"status"`
|
||||
Priority int `json:"priority"`
|
||||
TaskOrder int `json:"task_order"`
|
||||
CreatedByRoleName string `json:"created_by_role_name"`
|
||||
Dependencies []dependency `json:"dependencies"`
|
||||
}
|
||||
var req request
|
||||
if err := httpx.DecodeJSON(r, &req); err != nil {
|
||||
httpx.WriteError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
deps := make([]task.Dependency, 0, len(req.Dependencies))
|
||||
for _, dep := range req.Dependencies {
|
||||
deps = append(deps, task.Dependency{
|
||||
DependsOnTaskID: dep.DependsOnTaskID,
|
||||
})
|
||||
}
|
||||
item, err := h.Tasks.Create(r.Context(), tasksapp.CreateInput{
|
||||
Task: task.Record{
|
||||
WorkspaceID: req.WorkspaceID,
|
||||
TopicID: r.PathValue("topicID"),
|
||||
LaneID: req.LaneID,
|
||||
Title: req.Title,
|
||||
BodyMarkdown: req.BodyMarkdown,
|
||||
AcceptanceMarkdown: req.AcceptanceMarkdown,
|
||||
Kind: task.Kind(req.Kind),
|
||||
Deliverables: req.Deliverables,
|
||||
BatchKey: req.BatchKey,
|
||||
Status: task.Status(req.Status),
|
||||
Priority: req.Priority,
|
||||
TaskOrder: req.TaskOrder,
|
||||
CreatedByRoleName: req.CreatedByRoleName,
|
||||
},
|
||||
Dependencies: deps,
|
||||
})
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusCreated, item)
|
||||
}
|
||||
|
||||
func (h *Handler) listLaneTasks(w http.ResponseWriter, r *http.Request) {
|
||||
items, err := h.Tasks.ListByLane(r.Context(), r.PathValue("laneID"))
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"tasks": items})
|
||||
}
|
||||
|
||||
func (h *Handler) getTask(w http.ResponseWriter, r *http.Request) {
|
||||
item, err := h.Tasks.Get(r.Context(), r.PathValue("taskID"))
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (h *Handler) patchTask(w http.ResponseWriter, r *http.Request) {
|
||||
type dependency struct {
|
||||
DependsOnTaskID string `json:"depends_on_task_id"`
|
||||
}
|
||||
type request struct {
|
||||
Title *string `json:"title"`
|
||||
BodyMarkdown *string `json:"body_markdown"`
|
||||
AcceptanceMarkdown *string `json:"acceptance_markdown"`
|
||||
Kind *task.Kind `json:"kind"`
|
||||
Deliverables *[]string `json:"deliverables"`
|
||||
BatchKey *string `json:"batch_key"`
|
||||
Status *task.Status `json:"status"`
|
||||
Priority *int `json:"priority"`
|
||||
TaskOrder *int `json:"task_order"`
|
||||
BlockingReasonMarkdown *string `json:"blocking_reason_markdown"`
|
||||
ResultSummaryMarkdown *string `json:"result_summary_markdown"`
|
||||
AssignedRunID *string `json:"assigned_run_id"`
|
||||
StartedAt *string `json:"started_at"`
|
||||
CompletedAt *string `json:"completed_at"`
|
||||
Dependencies *[]dependency `json:"dependencies"`
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
}
|
||||
var req request
|
||||
if err := httpx.DecodeJSON(r, &req); err != nil {
|
||||
httpx.WriteError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
var deps *[]task.Dependency
|
||||
if req.Dependencies != nil {
|
||||
items := make([]task.Dependency, 0, len(*req.Dependencies))
|
||||
for _, dep := range *req.Dependencies {
|
||||
items = append(items, task.Dependency{
|
||||
TaskID: r.PathValue("taskID"),
|
||||
DependsOnTaskID: dep.DependsOnTaskID,
|
||||
})
|
||||
}
|
||||
deps = &items
|
||||
}
|
||||
item, err := h.Tasks.Patch(r.Context(), r.PathValue("taskID"), tasksapp.Patch{
|
||||
Title: req.Title,
|
||||
BodyMarkdown: req.BodyMarkdown,
|
||||
AcceptanceMarkdown: req.AcceptanceMarkdown,
|
||||
Kind: req.Kind,
|
||||
Deliverables: req.Deliverables,
|
||||
BatchKey: req.BatchKey,
|
||||
Status: req.Status,
|
||||
Priority: req.Priority,
|
||||
TaskOrder: req.TaskOrder,
|
||||
BlockingReasonMarkdown: req.BlockingReasonMarkdown,
|
||||
ResultSummaryMarkdown: req.ResultSummaryMarkdown,
|
||||
AssignedRunID: req.AssignedRunID,
|
||||
StartedAt: req.StartedAt,
|
||||
CompletedAt: req.CompletedAt,
|
||||
Dependencies: deps,
|
||||
}, req.UpdatedBy)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (h *Handler) listTaskDependencies(w http.ResponseWriter, r *http.Request) {
|
||||
items, err := h.Tasks.Dependencies(r.Context(), r.PathValue("taskID"))
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"dependencies": items})
|
||||
}
|
||||
|
||||
func (h *Handler) listTaskEvents(w http.ResponseWriter, r *http.Request) {
|
||||
items, err := h.Tasks.Events(r.Context(), r.PathValue("taskID"))
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"events": items})
|
||||
}
|
||||
|
||||
func (h *Handler) appendTaskEvent(w http.ResponseWriter, r *http.Request) {
|
||||
type request struct {
|
||||
EventType string `json:"event_type"`
|
||||
BodyMarkdown string `json:"body_markdown"`
|
||||
CreatedByRoleName string `json:"created_by_role_name"`
|
||||
}
|
||||
var req request
|
||||
if err := httpx.DecodeJSON(r, &req); err != nil {
|
||||
httpx.WriteError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
item, err := h.Tasks.AppendEvent(r.Context(), task.Event{
|
||||
TaskID: r.PathValue("taskID"),
|
||||
EventType: req.EventType,
|
||||
BodyMarkdown: req.BodyMarkdown,
|
||||
CreatedByRoleName: req.CreatedByRoleName,
|
||||
})
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusCreated, item)
|
||||
}
|
||||
Reference in New Issue
Block a user