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

Method Update

api/handler/code.go:156–195  ·  view source on GitHub ↗

UpdateCode godoc @Security ApiKey @Summary Update a exists code @Description update a exists code @Tags Code @Accept json @Produce json @Param namespace path string true "namespace" @Param name path string true "name" @Param current_user query stri

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

154// @Failure 500 {object} types.APIInternalServerError "Internal server error"
155// @Router /codes/{namespace}/{name} [put]
156func (h *CodeHandler) Update(ctx *gin.Context) {
157 currentUser := httpbase.GetCurrentUser(ctx)
158 if currentUser == "" {
159 httpbase.UnauthorizedError(ctx, component.ErrUserNotFound)
160 return
161 }
162 var req *types.UpdateCodeReq
163 if err := ctx.ShouldBindJSON(&req); err != nil {
164 slog.Error("Bad request format", "error", err)
165 httpbase.BadRequest(ctx, err.Error())
166 return
167 }
168
169 _, err := h.sc.CheckRequest(ctx, req)
170 if err != nil {
171 slog.Error("failed to check sensitive request", slog.Any("error", err))
172 httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error())
173 return
174 }
175 req.Username = currentUser
176
177 namespace, name, err := common.GetNamespaceAndNameFromContext(ctx)
178 if err != nil {
179 slog.Error("Bad request format", "error", err)
180 httpbase.BadRequest(ctx, err.Error())
181 return
182 }
183 req.Namespace = namespace
184 req.Name = name
185
186 code, err := h.c.Update(ctx, req)
187 if err != nil {
188 slog.Error("Failed to update code", slog.Any("error", err))
189 httpbase.ServerError(ctx, err)
190 return
191 }
192
193 slog.Info("Update code succeed", slog.String("code", code.Name))
194 httpbase.OK(ctx, code)
195}
196
197// DeleteCode godoc
198// @Security ApiKey

Callers

nothing calls this directly

Calls 8

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