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

Method Create

api/handler/model.go:110–139  ·  view source on GitHub ↗

CreateModel godoc @Security ApiKey @Summary Create a new model @Description create a new model @Tags Model @Accept json @Produce json @Param current_user query string false "current user" @Param body body types.CreateModelReq true "body" @Success 200

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

108// @Failure 500 {object} types.APIInternalServerError "Internal server error"
109// @Router /models [post]
110func (h *ModelHandler) Create(ctx *gin.Context) {
111 currentUser := httpbase.GetCurrentUser(ctx)
112 if currentUser == "" {
113 httpbase.UnauthorizedError(ctx, component.ErrUserNotFound)
114 return
115 }
116 var req *types.CreateModelReq
117 if err := ctx.ShouldBindJSON(&req); err != nil {
118 slog.Error("Bad request format", "error", err)
119 httpbase.BadRequest(ctx, err.Error())
120 return
121 }
122 req.Username = currentUser
123
124 _, err := h.sc.CheckRequest(ctx, req)
125 if err != nil {
126 slog.Error("failed to check sensitive request", slog.Any("error", err))
127 httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error())
128 return
129 }
130
131 model, err := h.c.Create(ctx, req)
132 if err != nil {
133 slog.Error("Failed to create model", slog.Any("error", err))
134 httpbase.ServerError(ctx, err)
135 return
136 }
137 slog.Info("Create model succeed", slog.String("model", model.Name))
138 httpbase.OK(ctx, model)
139}
140
141// UpdateModel godoc
142// @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