MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / Create

Method Create

user/handler/organization.go:47–73  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

45// @Failure 500 {object} types.APIInternalServerError "Internal server error"
46// @Router /organizations [post]
47func (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

Callers

nothing calls this directly

Calls 6

GetCurrentUserFunction · 0.92
BadRequestFunction · 0.92
ServerErrorFunction · 0.92
OKFunction · 0.92
ErrorMethod · 0.80
CheckRequestMethod · 0.65

Tested by

no test coverage detected