Add existing codebase

This commit is contained in:
Andrey Chervyakov 2021-04-12 17:01:00 +06:00
commit e12550a643
25 changed files with 1409 additions and 0 deletions

View 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)
})
}