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)
| 108 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 109 | // @Router /models [post] |
| 110 | func (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 |
nothing calls this directly
no test coverage detected