后端优化完成

This commit is contained in:
Liujian
2024-10-12 10:42:52 +08:00
parent 518846a281
commit c434d7c954
9 changed files with 139 additions and 72 deletions
+10 -9
View File
@@ -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
}
+22 -18
View File
@@ -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,
})
+21 -19
View File
@@ -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 {
+28 -26
View File
@@ -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:
+7
View File
@@ -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