Dump changes
This commit is contained in:
parent
e12550a643
commit
aac2ea1b74
25 changed files with 129 additions and 76 deletions
34
pkg/brainbuffer/domain/task/handlers.go
Normal file
34
pkg/brainbuffer/domain/task/handlers.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package task
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func creationHandler(ctx echo.Context, service Service) error {
|
||||
var model CreationModel
|
||||
if err := json.NewDecoder(ctx.Request().Body).Decode(&model); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid data format.")
|
||||
}
|
||||
|
||||
userId := ctx.Param("userId")
|
||||
|
||||
entity := model.MapModelToEntity(userId)
|
||||
|
||||
if err := service.Create(&entity); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.NoContent(http.StatusCreated)
|
||||
}
|
||||
|
||||
func AddHandlers(e *echo.Echo) {
|
||||
taskService := NewService()
|
||||
|
||||
userTasksGroup := e.Group("/users/:userId/tasks")
|
||||
|
||||
userTasksGroup.POST("", func(ctx echo.Context) error {
|
||||
return creationHandler(ctx, taskService)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue