// EditOrganization modifes an organization record // // PATCH /orgs/:org // func (c *OrganizationsController) EditOrganization(ctx *gin.Context) { var json bindings.UpdateOrganization err := ctx.Bind(&json) if err != nil { helpers.JSONResponseValidationFailed(ctx, err) return } org := getOrganizationFromContext(ctx) orgService, err := services.NewOrganizationService(org, getCurrentUser(ctx)) if err != nil { if c.WriteTrace { c.Logger.Printf("Failed to create OrganizationService for org: %v", org) } helpers.JSONResponseInternalServerError(ctx, err) return } org, err = orgService.UpdateOrganization(json) if err != nil { helpers.JSONResponseInternalServerError(ctx, err) return } helpers.JSONResponseObject(ctx, presenters.OrganizationPresenter(org)) }
// CreateOrganization creates a new Organization and makes the current authenticated user the owner // // POST /orgs // func (c *OrganizationsController) CreateOrganization(ctx *gin.Context) { var json bindings.CreateOrganization err := ctx.Bind(&json) if err != nil { helpers.JSONResponseValidationFailed(ctx, err) return } // creates the organization and set the current user as part of Owners Team org, err := services.CreateOrganization(json, getCurrentUser(ctx)) if err != nil { if err == services.ErrNamespaceAlreadyExists { helpers.JSONErrorf(ctx, http.StatusBadRequest, "Organization name already exists") } else { helpers.JSONResponseInternalServerError(ctx, err) } return } helpers.JSONResponseObject(ctx, presenters.OrganizationPresenter(org)) }
// GetOrganization returns an organization record // // GET /orgs/:org // func (c *OrganizationsController) GetOrganization(ctx *gin.Context) { org := getOrganizationFromContext(ctx) helpers.JSONResponseObject(ctx, presenters.OrganizationPresenter(org)) }