CreateOrganization godoc @Security ApiKey @Summary Create a new organization @Description create a new organization @Tags Organization @Accept json @Produce json @Param current_user query string false "the op user" @param body body types.CreateOrgReq true "
(ctx *gin.Context)
| 45 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 46 | // @Router /organizations [post] |
| 47 | func (h *OrganizationHandler) Create(ctx *gin.Context) { |
| 48 | currentUser := httpbase.GetCurrentUser(ctx) |
| 49 | var req types.CreateOrgReq |
| 50 | if err := ctx.ShouldBindJSON(&req); err != nil { |
| 51 | slog.Error("Bad request format", "error", err) |
| 52 | httpbase.BadRequest(ctx, err.Error()) |
| 53 | return |
| 54 | } |
| 55 | var err error |
| 56 | _, err = h.sc.CheckRequest(ctx, &req) |
| 57 | if err != nil { |
| 58 | slog.Error("failed to check sensitive request", slog.Any("error", err)) |
| 59 | httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error()) |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | req.Username = currentUser |
| 64 | org, err := h.c.Create(ctx, &req) |
| 65 | if err != nil { |
| 66 | slog.Error("Failed to create organization", slog.Any("error", err)) |
| 67 | httpbase.ServerError(ctx, err) |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | slog.Info("Create organization succeed", slog.String("org_path", org.Name)) |
| 72 | httpbase.OK(ctx, org) |
| 73 | } |
| 74 | |
| 75 | // GetOrganization godoc |
| 76 | // @Security ApiKey |
nothing calls this directly
no test coverage detected