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

Method Create

api/handler/space.go:142–170  ·  view source on GitHub ↗

CreateSpace godoc @Security ApiKey @Summary Create a new space @Description create a new space @Tags Space @Accept json @Produce json @Param current_user query string true "current_user" @Param body body types.CreateSpaceReq true "body" @Success 200

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

140// @Failure 500 {object} types.APIInternalServerError "Internal server error"
141// @Router /spaces [post]
142func (h *SpaceHandler) Create(ctx *gin.Context) {
143 currentUser := httpbase.GetCurrentUser(ctx)
144 if currentUser == "" {
145 httpbase.UnauthorizedError(ctx, component.ErrUserNotFound)
146 return
147 }
148 var req types.CreateSpaceReq
149 if err := ctx.ShouldBindJSON(&req); err != nil {
150 slog.Error("Bad request format", "error", err)
151 httpbase.BadRequest(ctx, err.Error())
152 return
153 }
154 _, err := h.sc.CheckRequest(ctx, &req)
155 if err != nil {
156 slog.Error("failed to check sensitive request", slog.Any("error", err))
157 httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error())
158 return
159 }
160 req.Username = currentUser
161
162 space, err := h.c.Create(ctx, req)
163 if err != nil {
164 slog.Error("Failed to create space", slog.Any("error", err))
165 httpbase.ServerError(ctx, err)
166 return
167 }
168 slog.Info("Create space succeed", slog.String("space", space.Name))
169 httpbase.OK(ctx, space)
170}
171
172// UpdateSpace godoc
173// @Security ApiKey

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected