jimmyyem 5 сар өмнө
parent
commit
d397701025

+ 0 - 6
ent/agent/agent.go

@@ -92,20 +92,14 @@ var (
 	UpdateDefaultUpdatedAt func() time.Time
 	// NameValidator is a validator for the "name" field. It is called by the builders before save.
 	NameValidator func(string) error
-	// RoleValidator is a validator for the "role" field. It is called by the builders before save.
-	RoleValidator func(string) error
 	// DefaultStatus holds the default value on creation for the "status" field.
 	DefaultStatus int
 	// StatusValidator is a validator for the "status" field. It is called by the builders before save.
 	StatusValidator func(int) error
 	// DefaultBackground holds the default value on creation for the "background" field.
 	DefaultBackground string
-	// BackgroundValidator is a validator for the "background" field. It is called by the builders before save.
-	BackgroundValidator func(string) error
 	// DefaultExamples holds the default value on creation for the "examples" field.
 	DefaultExamples string
-	// ExamplesValidator is a validator for the "examples" field. It is called by the builders before save.
-	ExamplesValidator func(string) error
 	// OrganizationIDValidator is a validator for the "organization_id" field. It is called by the builders before save.
 	OrganizationIDValidator func(uint64) error
 	// DefaultDatasetID holds the default value on creation for the "dataset_id" field.

+ 0 - 15
ent/agent_create.go

@@ -267,26 +267,11 @@ func (ac *AgentCreate) check() error {
 	if _, ok := ac.mutation.Role(); !ok {
 		return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "Agent.role"`)}
 	}
-	if v, ok := ac.mutation.Role(); ok {
-		if err := agent.RoleValidator(v); err != nil {
-			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "Agent.role": %w`, err)}
-		}
-	}
 	if v, ok := ac.mutation.Status(); ok {
 		if err := agent.StatusValidator(v); err != nil {
 			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
 		}
 	}
-	if v, ok := ac.mutation.Background(); ok {
-		if err := agent.BackgroundValidator(v); err != nil {
-			return &ValidationError{Name: "background", err: fmt.Errorf(`ent: validator failed for field "Agent.background": %w`, err)}
-		}
-	}
-	if v, ok := ac.mutation.Examples(); ok {
-		if err := agent.ExamplesValidator(v); err != nil {
-			return &ValidationError{Name: "examples", err: fmt.Errorf(`ent: validator failed for field "Agent.examples": %w`, err)}
-		}
-	}
 	if _, ok := ac.mutation.OrganizationID(); !ok {
 		return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Agent.organization_id"`)}
 	}

+ 0 - 30
ent/agent_update.go

@@ -289,26 +289,11 @@ func (au *AgentUpdate) check() error {
 			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
 		}
 	}
-	if v, ok := au.mutation.Role(); ok {
-		if err := agent.RoleValidator(v); err != nil {
-			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "Agent.role": %w`, err)}
-		}
-	}
 	if v, ok := au.mutation.Status(); ok {
 		if err := agent.StatusValidator(v); err != nil {
 			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
 		}
 	}
-	if v, ok := au.mutation.Background(); ok {
-		if err := agent.BackgroundValidator(v); err != nil {
-			return &ValidationError{Name: "background", err: fmt.Errorf(`ent: validator failed for field "Agent.background": %w`, err)}
-		}
-	}
-	if v, ok := au.mutation.Examples(); ok {
-		if err := agent.ExamplesValidator(v); err != nil {
-			return &ValidationError{Name: "examples", err: fmt.Errorf(`ent: validator failed for field "Agent.examples": %w`, err)}
-		}
-	}
 	if v, ok := au.mutation.OrganizationID(); ok {
 		if err := agent.OrganizationIDValidator(v); err != nil {
 			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
@@ -725,26 +710,11 @@ func (auo *AgentUpdateOne) check() error {
 			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
 		}
 	}
-	if v, ok := auo.mutation.Role(); ok {
-		if err := agent.RoleValidator(v); err != nil {
-			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "Agent.role": %w`, err)}
-		}
-	}
 	if v, ok := auo.mutation.Status(); ok {
 		if err := agent.StatusValidator(v); err != nil {
 			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
 		}
 	}
-	if v, ok := auo.mutation.Background(); ok {
-		if err := agent.BackgroundValidator(v); err != nil {
-			return &ValidationError{Name: "background", err: fmt.Errorf(`ent: validator failed for field "Agent.background": %w`, err)}
-		}
-	}
-	if v, ok := auo.mutation.Examples(); ok {
-		if err := agent.ExamplesValidator(v); err != nil {
-			return &ValidationError{Name: "examples", err: fmt.Errorf(`ent: validator failed for field "Agent.examples": %w`, err)}
-		}
-	}
 	if v, ok := auo.mutation.OrganizationID(); ok {
 		if err := agent.OrganizationIDValidator(v); err != nil {
 			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}

+ 3 - 3
ent/migrate/schema.go

@@ -16,10 +16,10 @@ var (
 		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
 		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
 		{Name: "name", Type: field.TypeString, Size: 255, Comment: "name | 角色名称"},
-		{Name: "role", Type: field.TypeString, Size: 1000, Comment: "role | 角色设定"},
+		{Name: "role", Type: field.TypeString, Comment: "role | 角色设定"},
 		{Name: "status", Type: field.TypeInt, Nullable: true, Comment: "status | 状态 1-正常 2-禁用", Default: 1},
-		{Name: "background", Type: field.TypeString, Nullable: true, Size: 1000, Comment: "background | 背景介绍", Default: ""},
-		{Name: "examples", Type: field.TypeString, Nullable: true, Size: 5000, Comment: "examples | 对话案例", Default: ""},
+		{Name: "background", Type: field.TypeString, Nullable: true, Comment: "background | 背景介绍", Default: ""},
+		{Name: "examples", Type: field.TypeString, Nullable: true, Comment: "examples | 对话案例", Default: ""},
 		{Name: "organization_id", Type: field.TypeUint64, Comment: "organization_id | 租户ID"},
 		{Name: "dataset_id", Type: field.TypeString, Size: 255, Comment: "dataset_id | 知识库ID", Default: ""},
 		{Name: "collection_id", Type: field.TypeString, Size: 255, Comment: "collection_id | 集合ID", Default: ""},

+ 0 - 8
ent/runtime/runtime.go

@@ -60,10 +60,6 @@ func init() {
 	agentDescName := agentFields[0].Descriptor()
 	// agent.NameValidator is a validator for the "name" field. It is called by the builders before save.
 	agent.NameValidator = agentDescName.Validators[0].(func(string) error)
-	// agentDescRole is the schema descriptor for role field.
-	agentDescRole := agentFields[1].Descriptor()
-	// agent.RoleValidator is a validator for the "role" field. It is called by the builders before save.
-	agent.RoleValidator = agentDescRole.Validators[0].(func(string) error)
 	// agentDescStatus is the schema descriptor for status field.
 	agentDescStatus := agentFields[2].Descriptor()
 	// agent.DefaultStatus holds the default value on creation for the status field.
@@ -74,14 +70,10 @@ func init() {
 	agentDescBackground := agentFields[3].Descriptor()
 	// agent.DefaultBackground holds the default value on creation for the background field.
 	agent.DefaultBackground = agentDescBackground.Default.(string)
-	// agent.BackgroundValidator is a validator for the "background" field. It is called by the builders before save.
-	agent.BackgroundValidator = agentDescBackground.Validators[0].(func(string) error)
 	// agentDescExamples is the schema descriptor for examples field.
 	agentDescExamples := agentFields[4].Descriptor()
 	// agent.DefaultExamples holds the default value on creation for the examples field.
 	agent.DefaultExamples = agentDescExamples.Default.(string)
-	// agent.ExamplesValidator is a validator for the "examples" field. It is called by the builders before save.
-	agent.ExamplesValidator = agentDescExamples.Validators[0].(func(string) error)
 	// agentDescOrganizationID is the schema descriptor for organization_id field.
 	agentDescOrganizationID := agentFields[5].Descriptor()
 	// agent.OrganizationIDValidator is a validator for the "organization_id" field. It is called by the builders before save.

+ 41 - 37
internal/handler/routes.go

@@ -519,43 +519,47 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]rest.Route{
-			{
-				Method:  http.MethodPost,
-				Path:    "/sop_stage/create",
-				Handler: sop_stage.CreateSopStageHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/sop_stage/update",
-				Handler: sop_stage.UpdateSopStageHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/sop_stage/delete",
-				Handler: sop_stage.DeleteSopStageHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/sop_stage/list",
-				Handler: sop_stage.GetSopStageListHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/sop_stage",
-				Handler: sop_stage.GetSopStageByIdHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/sop_stage/detail",
-				Handler: sop_stage.GetSopStageDetailHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/sop_stage/move",
-				Handler: sop_stage.MoveSopStageHandler(serverCtx),
-			},
-		},
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_stage/create",
+					Handler: sop_stage.CreateSopStageHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_stage/update",
+					Handler: sop_stage.UpdateSopStageHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_stage/delete",
+					Handler: sop_stage.DeleteSopStageHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_stage/list",
+					Handler: sop_stage.GetSopStageListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_stage",
+					Handler: sop_stage.GetSopStageByIdHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_stage/detail",
+					Handler: sop_stage.GetSopStageDetailHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/sop_stage/move",
+					Handler: sop_stage.MoveSopStageHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
 	)
 
 	server.AddRoutes(