diff --git a/controller/service/iml.go b/controller/service/iml.go index b1c847a7..fae4a479 100644 --- a/controller/service/iml.go +++ b/controller/service/iml.go @@ -197,7 +197,16 @@ func (i *imlServiceController) CreateAIService(ctx *gin.Context, teamID string, }, Disable: false, }) + if err != nil { + return err + } _, err = i.upstreamModule.Save(ctx, info.Id, newAIUpstream(info.Id, *input.Provider, p.URI())) + if err != nil { + return err + } + i.docModule.SaveServiceDoc(ctx, info.Id, &service_dto.SaveServiceDoc{ + Doc: "The Translation API allows developers to translate text from one language to another. It supports multiple languages and enables easy integration of high-quality translation features into applications. With simple API requests, you can quickly translate content into different target languages.", + }) return err }) diff --git a/module/ai-api/schema.go b/module/ai-api/schema.go index c78c0d58..caf72423 100644 --- a/module/ai-api/schema.go +++ b/module/ai-api/schema.go @@ -13,12 +13,12 @@ func genOpenAPI3Template(title string, description string) *openapi3.T { Description: description, Version: "beta", } - result.Tags = openapi3.Tags{ - { - Name: title, - Description: description, - }, - } + //result.Tags = openapi3.Tags{ + // { + // Name: title, + // Description: description, + // }, + //} result.Components = components result.Paths = new(openapi3.Paths) return result @@ -159,15 +159,16 @@ func genResponseSchema() *openapi3.Schema { result := openapi3.NewObjectSchema() result.Description = "Response from the server" result.WithPropertyRef("message", messageSchemaRef) - result.WithProperty("code", openapi3.NewInt32Schema().WithMin(0)) + openapi3.NewIntegerSchema() + result.WithProperty("code", openapi3.NewIntegerSchema()) result.WithProperty("error", openapi3.NewStringSchema()) - result.WithProperty("finish_reason", openapi3.NewStringSchema().WithEnum([]string{ + result.WithProperty("finish_reason", openapi3.NewStringSchema().WithEnum( "stop", "length", "function_call", "content_filter", "null", - })) + )) return result } diff --git a/module/catalogue/iml.go b/module/catalogue/iml.go index 08bcb2d4..62a38dac 100644 --- a/module/catalogue/iml.go +++ b/module/catalogue/iml.go @@ -4,10 +4,11 @@ import ( "context" "errors" "fmt" - api_doc "github.com/APIParkLab/APIPark/service/api-doc" "math" "sort" + api_doc "github.com/APIParkLab/APIPark/service/api-doc" + service_doc "github.com/APIParkLab/APIPark/service/service-doc" service_tag "github.com/APIParkLab/APIPark/service/service-tag" @@ -118,6 +119,10 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal // 当系统不可作为订阅方时,不可订阅 continue } + status := subscribe.ApplyStatusReview + if s.ApprovalType == service.ApprovalTypeAuto { + status = subscribe.ApplyStatusSubscribe + } err = i.subscribeApplyService.Create(ctx, &subscribe.CreateApply{ Uuid: uuid.New().String(), @@ -126,7 +131,7 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal Application: appId, ApplyTeam: appInfo.Team, Reason: subscribeInfo.Reason, - Status: subscribe.ApplyStatusReview, + Status: status, Applier: userId, }) @@ -137,20 +142,20 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal // 修改订阅表状态 subscribers, err := i.subscribeService.ListByApplication(ctx, subscribeInfo.Service, appId) if err != nil { - if !errors.Is(err, gorm.ErrRecordNotFound) { - return err - } - err = i.subscribeService.Create(ctx, &subscribe.CreateSubscribe{ - Uuid: uuid.New().String(), - Service: subscribeInfo.Service, - Application: appId, - ApplyStatus: subscribe.ApplyStatusReview, - From: subscribe.FromSubscribe, - }) - if err != nil { - return err - } - + //if !errors.Is(err, gorm.ErrRecordNotFound) { + // return err + //} + //err = i.subscribeService.Create(ctx, &subscribe.CreateSubscribe{ + // Uuid: uuid.New().String(), + // Service: subscribeInfo.Service, + // Application: appId, + // ApplyStatus: status, + // From: subscribe.FromSubscribe, + //}) + //if err != nil { + // return err + //} + return err } else { subscriberMap := utils.SliceToMap(subscribers, func(t *subscribe.Subscribe) string { return t.Application @@ -161,14 +166,13 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal Uuid: uuid.New().String(), Service: subscribeInfo.Service, Application: appId, - ApplyStatus: subscribe.ApplyStatusReview, + ApplyStatus: status, From: subscribe.FromSubscribe, }) if err != nil { return err } } else if v.ApplyStatus != subscribe.ApplyStatusSubscribe { - status := subscribe.ApplyStatusReview err = i.subscribeService.Save(ctx, v.Id, &subscribe.UpdateSubscribe{ ApplyStatus: &status, }) diff --git a/module/service/dto/input.go b/module/service/dto/input.go index 7962e67d..63192be0 100644 --- a/module/service/dto/input.go +++ b/module/service/dto/input.go @@ -1,28 +1,30 @@ package service_dto type CreateService struct { - Id string `json:"id"` - Name string `json:"name"` - Prefix string `json:"prefix"` - Description string `json:"description"` - ServiceType string `json:"service_type"` - Logo string `json:"logo"` - Tags []string `json:"tags"` - Catalogue string `json:"catalogue"` - Kind *string `json:"kind,omitempty"` - Provider *string `json:"provider" aocheck:"ai_provider"` - AsApp *bool `json:"as_app"` - AsServer *bool `json:"as_server"` + Id string `json:"id"` + Name string `json:"name"` + Prefix string `json:"prefix"` + Description string `json:"description"` + ServiceType string `json:"service_type"` + Logo string `json:"logo"` + Tags []string `json:"tags"` + Catalogue string `json:"catalogue"` + ApprovalType string `json:"approval_type"` + Kind *string `json:"kind,omitempty"` + Provider *string `json:"provider" aocheck:"ai_provider"` + AsApp *bool `json:"as_app"` + AsServer *bool `json:"as_server"` } type EditService struct { - Name *string `json:"name"` - Description *string `json:"description"` - ServiceType *string `json:"service_type"` - Catalogue *string `json:"catalogue"` - Logo *string `json:"logo"` - Tags *[]string `json:"tags"` - Provider *string `json:"provider" aocheck:"ai_provider"` + Name *string `json:"name"` + Description *string `json:"description"` + ServiceType *string `json:"service_type"` + Catalogue *string `json:"catalogue"` + Logo *string `json:"logo"` + Tags *[]string `json:"tags"` + Provider *string `json:"provider" aocheck:"ai_provider"` + ApprovalType *string `json:"approval_type"` } type CreateApp struct { diff --git a/module/service/dto/output.go b/module/service/dto/output.go index 649ea875..6ceaf1ee 100644 --- a/module/service/dto/output.go +++ b/module/service/dto/output.go @@ -44,20 +44,21 @@ type SimpleAppItem struct { } type Service struct { - Id string `json:"id"` - Name string `json:"name"` - Prefix string `json:"prefix,omitempty"` - Description string `json:"description"` - Team auto.Label `json:"team" aolabel:"team"` - CreateTime auto.TimeLabel `json:"create_time"` - UpdateTime auto.TimeLabel `json:"update_time"` - ServiceType string `json:"service_type"` - Catalogue auto.Label `json:"catalogue" aolabel:"catalogue"` - Tags []auto.Label `json:"tags" aolabel:"tag"` - Logo string `json:"logo"` - Provider *auto.Label `json:"provider,omitempty" aolabel:"ai_provider"` - AsServer bool `json:"as_server"` - AsApp bool `json:"as_app"` + Id string `json:"id"` + Name string `json:"name"` + Prefix string `json:"prefix,omitempty"` + Description string `json:"description"` + Team auto.Label `json:"team" aolabel:"team"` + CreateTime auto.TimeLabel `json:"create_time"` + UpdateTime auto.TimeLabel `json:"update_time"` + ServiceType string `json:"service_type"` + Catalogue auto.Label `json:"catalogue" aolabel:"catalogue"` + Tags []auto.Label `json:"tags" aolabel:"tag"` + Logo string `json:"logo"` + Provider *auto.Label `json:"provider,omitempty" aolabel:"ai_provider"` + ApprovalType string `json:"approval_type"` + AsServer bool `json:"as_server"` + AsApp bool `json:"as_app"` } type App struct { @@ -73,18 +74,19 @@ type App struct { func ToService(model *service.Service) *Service { s := &Service{ - Id: model.Id, - Name: model.Name, - Prefix: model.Prefix, - Description: model.Description, - Team: auto.UUID(model.Team), - ServiceType: model.ServiceType.String(), - Logo: model.Logo, - Catalogue: auto.UUID(model.Catalogue), - CreateTime: auto.TimeLabel(model.CreateTime), - UpdateTime: auto.TimeLabel(model.UpdateTime), - AsServer: model.AsServer, - AsApp: model.AsApp, + Id: model.Id, + Name: model.Name, + Prefix: model.Prefix, + Description: model.Description, + Team: auto.UUID(model.Team), + ServiceType: model.ServiceType.String(), + Logo: model.Logo, + Catalogue: auto.UUID(model.Catalogue), + CreateTime: auto.TimeLabel(model.CreateTime), + UpdateTime: auto.TimeLabel(model.UpdateTime), + ApprovalType: model.ApprovalType.String(), + AsServer: model.AsServer, + AsApp: model.AsApp, } switch model.Kind { case service.AIService: diff --git a/module/service/iml.go b/module/service/iml.go index 326acd1d..a9250b41 100644 --- a/module/service/iml.go +++ b/module/service/iml.go @@ -313,6 +313,7 @@ func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *ser Catalogue: input.Catalogue, Prefix: input.Prefix, Logo: input.Logo, + ApprovalType: service.ApprovalType(input.ApprovalType), AdditionalConfig: make(map[string]string), } if mo.ServiceType == service.PublicService && mo.Catalogue == "" { @@ -340,6 +341,7 @@ func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *ser } else { mo.AsServer = *input.AsServer } + input.Prefix = strings.Trim(strings.Trim(input.Prefix, " "), "/") err := i.transaction.Transaction(ctx, func(ctx context.Context) error { if input.Tags != nil { @@ -385,6 +387,10 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d return fmt.Errorf("catalogue can not be empty") } } + var approvalType service.ApprovalType + if input.ApprovalType != nil { + approvalType = service.ApprovalType(*input.ApprovalType) + } err = i.serviceService.Save(ctx, id, &service.Edit{ Name: input.Name, @@ -393,6 +399,7 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d ServiceType: serviceType, Catalogue: input.Catalogue, AdditionalConfig: &info.AdditionalConfig, + ApprovalType: &approvalType, }) if err != nil { return err diff --git a/service/service/iml.go b/service/service/iml.go index 41470885..69604366 100644 --- a/service/service/iml.go +++ b/service/service/iml.go @@ -159,6 +159,7 @@ func createEntityHandler(i *Create) *service.Service { Prefix: i.Prefix, Team: i.Team, ServiceType: i.ServiceType.Int(), + ApprovalType: i.ApprovalType.Int(), Kind: i.Kind.Int(), AdditionalConfig: string(cfg), Catalogue: i.Catalogue, @@ -189,4 +190,7 @@ func updateHandler(e *service.Service, i *Edit) { cfg, _ := json.Marshal(*i.AdditionalConfig) e.AdditionalConfig = string(cfg) } + if i.ApprovalType != nil { + e.ApprovalType = (*i.ApprovalType).Int() + } } diff --git a/service/service/model.go b/service/service/model.go index c31ef4ff..03e19fab 100644 --- a/service/service/model.go +++ b/service/service/model.go @@ -75,6 +75,39 @@ func ToServiceKind(s int) Kind { } } +const ( + ApprovalTypeAuto ApprovalType = "auto" + ApprovalTypeManual ApprovalType = "manual" +) + +type ApprovalType string + +func (s ApprovalType) String() string { + return string(s) +} + +func (s ApprovalType) Int() int { + switch s { + case "auto": + return 1 + case "manual": + return 0 + default: + return 0 + } +} + +func ToApprovalType(s int) ApprovalType { + switch s { + case 1: + return "auto" + case 0: + return "manual" + default: + return "manual" + } +} + type Service struct { Id string Name string @@ -88,6 +121,7 @@ type Service struct { AdditionalConfig map[string]string AsServer bool AsApp bool + ApprovalType ApprovalType CreateTime time.Time UpdateTime time.Time } @@ -107,6 +141,7 @@ func FromEntity(e *service.Service) *Service { ServiceType: ToServiceType(e.ServiceType), Kind: ToServiceKind(e.Kind), Catalogue: e.Catalogue, + ApprovalType: ToApprovalType(e.ApprovalType), AsServer: e.AsServer, AsApp: e.AsApp, CreateTime: e.CreateAt, @@ -126,6 +161,7 @@ type Create struct { Kind Kind Catalogue string AdditionalConfig map[string]string + ApprovalType ApprovalType AsServer bool AsApp bool } @@ -138,6 +174,7 @@ type Edit struct { Catalogue *string Logo *string AdditionalConfig *map[string]string + ApprovalType *ApprovalType } type CreateTag struct { diff --git a/stores/service/model.go b/stores/service/model.go index b68d3409..af06a80a 100644 --- a/stores/service/model.go +++ b/stores/service/model.go @@ -18,6 +18,7 @@ type Service struct { IsDelete int `gorm:"type:tinyint(1);not null;column:is_delete;comment:是否删除"` Kind int `gorm:"type:tinyint(4);not null;column:kind;comment:服务种类,0:Rest服务,1:AI服务"` AdditionalConfig string `gorm:"type:text;not null;column:additional_config;comment:额外配置"` + ApprovalType int `gorm:"type:tinyint(4);not null;column:approval_type;comment:审批类型"` AsServer bool `gorm:"type:tinyint(1);not null;column:as_server;comment:是否为服务端项目"` AsApp bool `gorm:"type:tinyint(1);not null;column:as_app;comment:是否为应用项目"` }