add postgres and refactor code
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"astra-users/model"
|
||||
"astra-users/pkg/utils"
|
||||
"errors"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
@@ -37,17 +38,19 @@ func (h *Handler) GetPosition(id int) (*model.Position, error) {
|
||||
}
|
||||
|
||||
func (h *Handler) CreatePosition(c echo.Context) (err error) {
|
||||
position := new(model.Position)
|
||||
position := new(model.PositionApi)
|
||||
|
||||
if err = c.Bind(position); err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tx := h.DB.Create(position)
|
||||
newPosition, err := utils.TypeConverter[model.Position](position)
|
||||
|
||||
tx := h.DB.Create(&newPosition)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusCreated, position)
|
||||
return c.JSON(http.StatusCreated, newPosition)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user