add org structure
This commit is contained in:
31
handler/organization.go
Normal file
31
handler/organization.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"astra-users/model"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (h *Handler) CreateOrganization(c echo.Context) (err error) {
|
||||
organization := new(model.Organization)
|
||||
|
||||
if err = c.Bind(organization); err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tx := h.DB.Create(organization)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusCreated, organization)
|
||||
}
|
||||
|
||||
func (h *Handler) GetOrganizations(c echo.Context) error {
|
||||
var organizations []model.Organization
|
||||
|
||||
h.DB.Find(&organizations)
|
||||
|
||||
return c.JSON(http.StatusCreated, organizations)
|
||||
}
|
||||
Reference in New Issue
Block a user