UpdateSpace godoc @Security ApiKey @Summary Update a exists space @Description update a exists space @Tags Space @Accept json @Produce json @Param namespace path string true "namespace" @Param name path string true "name" @Param current_user query
(ctx *gin.Context)
| 185 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 186 | // @Router /spaces/{namespace}/{name} [put] |
| 187 | func (h *SpaceHandler) Update(ctx *gin.Context) { |
| 188 | currentUser := httpbase.GetCurrentUser(ctx) |
| 189 | if currentUser == "" { |
| 190 | httpbase.UnauthorizedError(ctx, component.ErrUserNotFound) |
| 191 | return |
| 192 | } |
| 193 | var req *types.UpdateSpaceReq |
| 194 | if err := ctx.ShouldBindJSON(&req); err != nil { |
| 195 | slog.Error("Bad request format", "error", err) |
| 196 | httpbase.BadRequest(ctx, err.Error()) |
| 197 | return |
| 198 | } |
| 199 | _, err := h.sc.CheckRequest(ctx, req) |
| 200 | if err != nil { |
| 201 | slog.Error("failed to check sensitive request", slog.Any("error", err)) |
| 202 | httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error()) |
| 203 | return |
| 204 | } |
| 205 | req.Username = currentUser |
| 206 | |
| 207 | namespace, name, err := common.GetNamespaceAndNameFromContext(ctx) |
| 208 | if err != nil { |
| 209 | slog.Error("Bad request format", "error", err) |
| 210 | httpbase.BadRequest(ctx, err.Error()) |
| 211 | return |
| 212 | } |
| 213 | req.Namespace = namespace |
| 214 | req.Name = name |
| 215 | |
| 216 | space, err := h.c.Update(ctx, req) |
| 217 | if err != nil { |
| 218 | slog.Error("Failed to update space", slog.Any("error", err)) |
| 219 | httpbase.ServerError(ctx, err) |
| 220 | return |
| 221 | } |
| 222 | |
| 223 | slog.Info("Update space succeed", slog.String("space", space.Name)) |
| 224 | httpbase.OK(ctx, space) |
| 225 | } |
| 226 | |
| 227 | // DeleteSpace godoc |
| 228 | // @Security ApiKey |
nothing calls this directly
no test coverage detected