Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ const docTemplate = `{
"$ref": "#/definitions/model.Task"
}
},
"404": {
"description": "Not Found",
"500": {
"description": "Internal Server Error",
"schema": {}
}
}
Expand Down Expand Up @@ -178,12 +178,8 @@ const docTemplate = `{
"$ref": "#/definitions/model.Task"
}
},
"400": {
"description": "Bad Request",
"schema": {}
},
"404": {
"description": "Not Found",
"500": {
"description": "Internal Server Error",
"schema": {}
}
}
Expand Down
12 changes: 4 additions & 8 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
"$ref": "#/definitions/model.Task"
}
},
"404": {
"description": "Not Found",
"500": {
"description": "Internal Server Error",
"schema": {}
}
}
Expand Down Expand Up @@ -167,12 +167,8 @@
"$ref": "#/definitions/model.Task"
}
},
"400": {
"description": "Bad Request",
"schema": {}
},
"404": {
"description": "Not Found",
"500": {
"description": "Internal Server Error",
"schema": {}
}
}
Expand Down
11 changes: 4 additions & 7 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ paths:
description: OK
schema:
$ref: '#/definitions/model.Task'
"404":
description: Not Found
"500":
description: Internal Server Error
schema: {}
summary: Delete a task
tags:
Expand Down Expand Up @@ -153,11 +153,8 @@ paths:
description: OK
schema:
$ref: '#/definitions/model.Task'
"400":
description: Bad Request
schema: {}
"404":
description: Not Found
"500":
description: Internal Server Error
schema: {}
summary: Update a task
tags:
Expand Down
15 changes: 7 additions & 8 deletions internal/handler/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (th *TaskHandler) CreateTask(c *fiber.Ctx) error {
t, err := th.s.CreateTask(ctr.Title, ctr.Description)
if err != nil {
utils.ErrorLogger.Println("Failed to create a new task:\n", err)
return c.JSON(err)
return c.Status(fiber.StatusInternalServerError).JSON(err)
}
return c.JSON(t)
}
Expand All @@ -66,7 +66,7 @@ func (th *TaskHandler) GetAllTasks(c *fiber.Ctx) error {
tasks, err := th.s.GetAllTasks()
if err != nil {
utils.ErrorLogger.Println("Failed to get all tasks:\n", err)
return c.JSON(err)
return c.Status(fiber.StatusInternalServerError).JSON(err)
}
return c.JSON(tasks)
}
Expand All @@ -85,7 +85,7 @@ func (th *TaskHandler) GetTaskByID(c *fiber.Ctx) error {
t, err := th.s.GetTaskByID(id)
if err != nil {
utils.ErrorLogger.Printf("Failed to get task with id %s:\n%s", id, err)
return c.JSON(err)
return c.Status(fiber.StatusNotFound).JSON(err)
}
return c.JSON(t)
}
Expand All @@ -99,8 +99,7 @@ func (th *TaskHandler) GetTaskByID(c *fiber.Ctx) error {
// @Param id path string true "Task ID"
// @Param request body model.UpdateTaskRequest true "Update Task Body"
// @Success 200 {object} model.Task
// @Failure 400 {object} error
// @Failure 404 {object} error
// @Failure 500 {object} error
// @Router /api/task/{id} [patch]
func (th *TaskHandler) UpdateTask(c *fiber.Ctx) error {
id := c.Params("id")
Expand All @@ -117,7 +116,7 @@ func (th *TaskHandler) UpdateTask(c *fiber.Ctx) error {
)
if err != nil {
utils.ErrorLogger.Printf("Failed to update task with id %s:\n%s", id, err)
return c.JSON(err)
return c.Status(fiber.StatusInternalServerError).JSON(err)
}
return c.JSON(t)
}
Expand All @@ -129,14 +128,14 @@ func (th *TaskHandler) UpdateTask(c *fiber.Ctx) error {
// @Produce json
// @Param id path string true "Task ID"
// @Success 200 {object} model.Task
// @Failure 404 {object} error
// @Failure 500 {object} error
// @Router /api/task/{id} [delete]
func (th *TaskHandler) DeleteTask(c *fiber.Ctx) error {
id := c.Params("id")
t, err := th.s.DeleteTask(id)
if err != nil {
utils.ErrorLogger.Printf("Failed to delete task with id %s:\n%s", id, err)
return c.JSON(err)
return c.Status(fiber.StatusInternalServerError).JSON(err)
}
return c.JSON(t)
}