add postgres and refactor code
This commit is contained in:
@@ -2,24 +2,27 @@ package handler
|
||||
|
||||
import (
|
||||
"astra-users/model"
|
||||
"astra-users/pkg/utils"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (h *Handler) CreateOrganization(c echo.Context) (err error) {
|
||||
organization := new(model.Organization)
|
||||
organization := new(model.OrganizationApi)
|
||||
|
||||
if err = c.Bind(organization); err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tx := h.DB.Create(organization)
|
||||
newOrg, err := utils.TypeConverter[model.Organization](organization)
|
||||
|
||||
tx := h.DB.Create(&newOrg)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusCreated, organization)
|
||||
return c.JSON(http.StatusCreated, newOrg)
|
||||
}
|
||||
|
||||
func (h *Handler) GetOrganizations(c echo.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user