add new methods and update current
This commit is contained in:
@@ -32,3 +32,47 @@ func (h *Handler) GetOrganizations(c echo.Context) error {
|
||||
|
||||
return c.JSON(http.StatusOK, organizations)
|
||||
}
|
||||
|
||||
func (h *Handler) DeleteOrganization(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
tx := h.DB.Model(model.Organization{}).Delete(id)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusNotFound)
|
||||
}
|
||||
|
||||
return c.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateOrganization(c echo.Context) (err error) {
|
||||
id := c.Param("id")
|
||||
organization := new(model.OrganizationApi)
|
||||
var newOrganization model.Organization
|
||||
|
||||
if err = c.Bind(organization); err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tx := h.DB.Find(&newOrganization, id)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusNotFound)
|
||||
}
|
||||
|
||||
if organization.Name != "" {
|
||||
newOrganization.Name = organization.Name
|
||||
}
|
||||
|
||||
if organization.ParentID.ID() != 0 {
|
||||
newOrganization.ParentID = organization.ParentID
|
||||
}
|
||||
|
||||
tx = tx.Save(&newOrganization)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user