Skip to content

Commit

Permalink
handle other fields in create
Browse files Browse the repository at this point in the history
  • Loading branch information
ragoncsa committed Mar 4, 2022
1 parent e40f9d7 commit f714ebb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
13 changes: 12 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.Task"
"$ref": "#/definitions/http.CreateTaskRequest"
}
}
],
Expand Down Expand Up @@ -169,6 +169,17 @@ const docTemplate = `{
"type": "string"
}
}
},
"http.CreateTaskRequest": {
"type": "object",
"required": [
"task"
],
"properties": {
"task": {
"$ref": "#/definitions/domain.Task"
}
}
}
}
}`
Expand Down
13 changes: 12 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.Task"
"$ref": "#/definitions/http.CreateTaskRequest"
}
}
],
Expand Down Expand Up @@ -157,6 +157,17 @@
"type": "string"
}
}
},
"http.CreateTaskRequest": {
"type": "object",
"required": [
"task"
],
"properties": {
"task": {
"$ref": "#/definitions/domain.Task"
}
}
}
}
}
9 changes: 8 additions & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ definitions:
userId:
type: string
type: object
http.CreateTaskRequest:
properties:
task:
$ref: '#/definitions/domain.Task'
required:
- task
type: object
info:
contact: {}
paths:
Expand Down Expand Up @@ -56,7 +63,7 @@ paths:
name: task
required: true
schema:
$ref: '#/definitions/domain.Task'
$ref: '#/definitions/http.CreateTaskRequest'
produces:
- application/json
responses:
Expand Down
13 changes: 6 additions & 7 deletions http/taskservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type CreateTaskRequest struct {
Name string `json:"name" binding:"required"`
Task *domain.Task `json:"task" binding:"required"`
}

type TaskService struct {
Expand All @@ -37,7 +37,7 @@ func (t *TaskService) GetTasks(c *gin.Context) {
c.IndentedJSON(http.StatusOK, tasks)
}

// GetTasks godoc
// GetTask godoc
// @Summary Get task
// @Schemes
// @Description Reads a single task and returns it.
Expand Down Expand Up @@ -70,7 +70,7 @@ func (t *TaskService) GetTask(c *gin.Context) {
// @Tags write
// @Accept json
// @Produce json
// @Param task body domain.Task true "New task"
// @Param task body CreateTaskRequest true "New task"
// @Success 200
// @Router /tasks/ [post]
func (t *TaskService) CreateTask(c *gin.Context) {
Expand All @@ -79,9 +79,8 @@ func (t *TaskService) CreateTask(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
task := &domain.Task{Name: request.Name}
t.Service.CreateTask(task)
c.IndentedJSON(http.StatusCreated, task)
t.Service.CreateTask(request.Task)
c.IndentedJSON(http.StatusCreated, request.Task)
}

// DeleteTasks godoc
Expand Down Expand Up @@ -110,7 +109,7 @@ func (t *TaskService) DeleteTask(c *gin.Context) {
c.IndentedJSON(http.StatusOK, struct{}{})
}

// GetTasks godoc
// DeleteTask godoc
// @Summary Delete all tasks
// @Schemes
// @Description Deletes all the tasks.
Expand Down

0 comments on commit f714ebb

Please sign in to comment.