mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c7f561a55d | |||
| 30bead497e | |||
| 34ecd56cc4 | |||
| e4b46ea2e2 | |||
| 9e520be8b5 | |||
| 2f7db1c871 | |||
| 0aa526b6d4 | |||
| 9c54fec65e | |||
| 9315a5de4c | |||
| e09d35ec53 | |||
| 07c904be75 | |||
| c2c6f2b3f6 | |||
| 0a3fdd61c8 | |||
| d424b68b2b |
@@ -5,3 +5,5 @@
|
||||
/apipark
|
||||
.gitlab-ci.yml
|
||||
/.vscode/
|
||||
.vscode/
|
||||
.air.toml
|
||||
@@ -241,8 +241,18 @@ function BasicLayout({ project = 'core' }: { project: string }) {
|
||||
headerTitleRender={() => (
|
||||
<div className="w-[192px] flex items-center">
|
||||
<img className="h-[20px] cursor-pointer " src={Logo} onClick={() => navigator(mainPage)} />
|
||||
<a className="align-text-top" href="https://github.com/APIParkLab/APIPark" target="_blank" className="ml-[5px] h-[25px] relative">
|
||||
<img src="https://img.shields.io/github/stars/APIParkLab/APIPark?style=social" className='absolute top-[6px]' width={75} alt="" />
|
||||
<a
|
||||
className="align-text-top ml-[5px] h-[25px] relative"
|
||||
href="https://github.com/APIParkLab/APIPark"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<img
|
||||
src="https://img.shields.io/github/stars/APIParkLab/APIPark?style=social"
|
||||
className="absolute top-[6px]"
|
||||
width={75}
|
||||
alt=""
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -870,5 +870,6 @@
|
||||
"K8097d6be": "is an open-source AI Gateway and API Portal that unifies access to OpenAI, DeepSeek, and other AI models. With enterprise-grade security features and real-time monitoring, it helps teams safely manage and share their AI APIs through a unified gateway.",
|
||||
"Kf1ce5b3": "✨ We'd love your support on Github! Leave us a star or share your feedback. ",
|
||||
"K3af90490": "⚡ You can quickly open the API for everyone to use via the following methods:",
|
||||
"K6b99dce8": "address"
|
||||
"K6b99dce8": "address",
|
||||
"Kce2fcdbf": "No Permission"
|
||||
}
|
||||
|
||||
@@ -892,5 +892,6 @@
|
||||
"K8097d6be": "OpenAIやDeepSeekなどのさまざまなAIモデルに迅速にアクセスできるオープンソースのワンストップAIゲートウェイおよびAPIポータルです。統一されたリクエスト形式を使用して、モデルの切り替えによるビジネスへの影響を回避し、企業レベルのAPIセキュリティ(認証/レート制限/センシティブワードフィルタリング)とリアルタイムの使用量監視を提供します。チーム内でのAPI共有やコラボレーションをサポートし、インターフェースのサブスクリプション認証を管理してAPIのセキュリティを確保します。",
|
||||
"Kf1ce5b3": "✨ Githubでスターを付けていただくか、製品フィードバックをお寄せください。",
|
||||
"K3af90490": "⚡ 以下の方法で、APIをすぐに公開して皆さんに利用してもらえます:",
|
||||
"K6b99dce8": "Ollama アドレス"
|
||||
"K6b99dce8": "Ollama アドレス",
|
||||
"Kce2fcdbf": "権限がありません"
|
||||
}
|
||||
|
||||
@@ -823,5 +823,6 @@
|
||||
"K8097d6be": "是开源的一站式 AI 网关与 API 门户,可快速接入 OpenAI/DeepSeek 等各类 AI 模型,通过统一请求格式避免模型切换对业务造成影响,提供企业级 API 安全防护(鉴权/限流/敏感词过滤)与实时用量监控,支持团队内 API 共享协作,管理接口订阅授权并保证您的API安全。",
|
||||
"Kf1ce5b3": "✨ 欢迎在 Github 为我们 Star 或提供产品反馈意见。",
|
||||
"K3af90490": "⚡您可快速通过以下方式开放API供大家使用:",
|
||||
"K6b99dce8": "Ollama 地址"
|
||||
"K6b99dce8": "Ollama 地址",
|
||||
"Kce2fcdbf": "暂无权限"
|
||||
}
|
||||
|
||||
@@ -892,5 +892,6 @@
|
||||
"K8097d6be": "是一個開源的一站式 AI 閘道和 API 入口網站,可快速接入 OpenAI/DeepSeek 等各類 AI 模型,通過統一的請求格式避免模型切換對業務造成影響,提供企業級 API 安全防護(鑑權/限流/敏感詞過濾)與實時用量監控,支持團隊內 API 共享協作,管理介面訂閱授權並保證您的 API 安全。",
|
||||
"Kf1ce5b3": "✨ 歡迎在 Github 為我們 Star 或提供產品反饋意見。",
|
||||
"K3af90490": "⚡ 您可以快速通過以下方式開放 API 供大家使用:",
|
||||
"K6b99dce8": "Ollama 地址"
|
||||
"K6b99dce8": "Ollama 地址",
|
||||
"Kce2fcdbf": "暫無權限"
|
||||
}
|
||||
|
||||
@@ -133,9 +133,7 @@ const LocalModelList: React.FC = () => {
|
||||
const configureService = (address?: string) => {
|
||||
modal.confirm({
|
||||
title: $t('配置 Ollama 服务'),
|
||||
content: (
|
||||
<ConfigureOllamaService ref={ConfigureOllamaServiceRef} address={address}></ConfigureOllamaService>
|
||||
),
|
||||
content: <ConfigureOllamaService ref={ConfigureOllamaServiceRef} address={address}></ConfigureOllamaService>,
|
||||
onOk: () => {
|
||||
return ConfigureOllamaServiceRef.current?.save().then((res) => {
|
||||
if (res === true) {
|
||||
@@ -175,9 +173,11 @@ const LocalModelList: React.FC = () => {
|
||||
<div>
|
||||
<Icon className="align-sub mr-[5px]" icon="ph:hard-drives-light" width="50" height="50" />
|
||||
<div>{$t('模型部署服务未配置')}</div>
|
||||
<Button type="primary" className="mt-[10px]" onClick={() => configureService()}>
|
||||
{$t('配置服务')}
|
||||
</Button>
|
||||
<WithPermission access="system.devops.ai_provider.edit">
|
||||
<Button type="primary" className="mt-[10px]" onClick={() => configureService()}>
|
||||
{$t('配置服务')}
|
||||
</Button>
|
||||
</WithPermission>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
@@ -448,14 +448,19 @@ const LocalModelList: React.FC = () => {
|
||||
setSearchWord(e.target.value)
|
||||
pageListRef.current?.reload()
|
||||
}}
|
||||
beforeNewBtn={
|
||||
[<Button className="mr-btnbase" key="removeFromDep" onClick={() => configureService(ollamaAddress)}>{$t('配置服务')}</Button>]
|
||||
}
|
||||
beforeNewBtn={[
|
||||
<WithPermission access="system.devops.ai_provider.edit">
|
||||
<Button className="mr-btnbase" key="removeFromDep" onClick={() => configureService(ollamaAddress)}>
|
||||
{$t('配置服务')}
|
||||
</Button>
|
||||
</WithPermission>
|
||||
]}
|
||||
showPagination={true}
|
||||
searchPlaceholder={$t('请输入名称搜索')}
|
||||
columns={columns}
|
||||
addNewBtnTitle={$t('部署模型')}
|
||||
onAddNewBtnClick={handleAdd}
|
||||
addNewBtnAccess="system.devops.ai_provider.edit"
|
||||
addNewBtnDisabled={!ollamaAddress}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -216,6 +216,7 @@ const OnlineModelList: React.FC = () => {
|
||||
showPagination={true}
|
||||
searchPlaceholder={$t('请输入名称搜索')}
|
||||
columns={columns}
|
||||
addNewBtnAccess="system.devops.ai_provider.edit"
|
||||
addNewBtnTitle={$t('添加模型')}
|
||||
onAddNewBtnClick={handleAdd}
|
||||
/>
|
||||
|
||||
@@ -36,6 +36,10 @@ export const AIModelGuide = () => {
|
||||
* rest 服务卡片点击事件
|
||||
*/
|
||||
const restCardClick = async () => {
|
||||
const permission = checkAccess('system.workspace.service.edit', accessData)
|
||||
if (!permission) {
|
||||
return message.warning($t('暂无权限'))
|
||||
}
|
||||
modal.confirm({
|
||||
title: $t('添加 Rest 服务'),
|
||||
content: <RestAIDeploy ref={restAiDeployRef}></RestAIDeploy>,
|
||||
@@ -58,6 +62,10 @@ export const AIModelGuide = () => {
|
||||
* AI 模型配置弹窗
|
||||
*/
|
||||
const aiCardClick = () => {
|
||||
const permission = checkAccess('system.devops.ai_provider.edit', accessData)
|
||||
if (!permission) {
|
||||
return message.warning($t('暂无权限'))
|
||||
}
|
||||
// 更新弹窗
|
||||
const updateEntityData = (data: any) => {
|
||||
entityData.current = data
|
||||
@@ -130,6 +138,10 @@ export const AIModelGuide = () => {
|
||||
* 本地部署 AI 并生成 API
|
||||
*/
|
||||
const localModelCardClick = async () => {
|
||||
const permission = checkAccess('system.devops.ai_provider.edit', accessData)
|
||||
if (!permission) {
|
||||
return message.warning($t('暂无权限'))
|
||||
}
|
||||
if (!ollamaAddress) {
|
||||
navigateTo('/aisetting?status=unconfigure')
|
||||
return
|
||||
@@ -156,6 +168,10 @@ export const AIModelGuide = () => {
|
||||
}
|
||||
const deployDeepSeek = async (e: any) => {
|
||||
e.stopPropagation()
|
||||
const permission = checkAccess('system.devops.ai_provider.edit', accessData)
|
||||
if (!permission) {
|
||||
return message.warning($t('暂无权限'))
|
||||
}
|
||||
if (!ollamaAddress) {
|
||||
navigateTo('/aisetting?status=unconfigure')
|
||||
return
|
||||
|
||||
@@ -87,10 +87,12 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
|
||||
if (serviceId && configuredProvider.length > 0) {
|
||||
const providerID = form.getFieldValue('provider')
|
||||
const provider = configuredProvider?.find((item: any) => item.id === providerID)
|
||||
if (provider?.type === 'local') {
|
||||
getLocalModelList(false)
|
||||
} else {
|
||||
getOnlineModelList(provider?.id, false)
|
||||
if (provider) {
|
||||
if (provider?.type === 'local') {
|
||||
getLocalModelList(false)
|
||||
} else {
|
||||
getOnlineModelList(provider?.id, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -17,6 +17,7 @@ require (
|
||||
github.com/influxdata/influxdb-client-go/v2 v2.14.0
|
||||
github.com/nsqio/go-nsq v1.1.0
|
||||
github.com/ollama/ollama v0.5.8
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/urfave/cli v1.22.16
|
||||
golang.org/x/crypto v0.31.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
@@ -31,6 +32,7 @@ require (
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
@@ -59,6 +61,7 @@ require (
|
||||
github.com/oapi-codegen/runtime v1.0.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/perimeterx/marshmallow v1.1.5 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/redis/go-redis/v9 v9.5.3 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
|
||||
@@ -23,6 +23,7 @@ type CreateService struct {
|
||||
Model *string `json:"model"`
|
||||
AsApp *bool `json:"as_app"`
|
||||
AsServer *bool `json:"as_server"`
|
||||
ModelMapping string `json:"model_mapping"`
|
||||
}
|
||||
|
||||
type EditService struct {
|
||||
@@ -36,6 +37,7 @@ type EditService struct {
|
||||
Model *string `json:"model"`
|
||||
ApprovalType *string `json:"approval_type"`
|
||||
State *string `json:"state"`
|
||||
ModelMapping string `json:"model_mapping"`
|
||||
}
|
||||
|
||||
type CreateApp struct {
|
||||
|
||||
@@ -104,6 +104,7 @@ type Service struct {
|
||||
AsApp bool `json:"as_app"`
|
||||
ServiceKind string `json:"service_kind"`
|
||||
State string `json:"state"`
|
||||
ModelMapping string `json:"model_mapping"`
|
||||
}
|
||||
|
||||
type App struct {
|
||||
@@ -191,16 +192,17 @@ type ServiceDoc struct {
|
||||
}
|
||||
|
||||
type ExportService struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Prefix string `json:"prefix,omitempty"`
|
||||
Description string `json:"description"`
|
||||
Team string `json:"team"`
|
||||
ServiceType string `json:"service_type"`
|
||||
Catalogue string `json:"catalogue"`
|
||||
Tags []string `json:"tags"`
|
||||
Logo string `json:"logo"`
|
||||
Doc string `json:"doc"`
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Prefix string `json:"prefix,omitempty"`
|
||||
Description string `json:"description"`
|
||||
Team string `json:"team"`
|
||||
ServiceType string `json:"service_type"`
|
||||
Catalogue string `json:"catalogue"`
|
||||
Tags []string `json:"tags"`
|
||||
Logo string `json:"logo"`
|
||||
Doc string `json:"doc"`
|
||||
ModelMapping string `json:"model_mapping"`
|
||||
}
|
||||
|
||||
type ExportApp struct {
|
||||
|
||||
+26
-17
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/eolinker/ap-account/service/role"
|
||||
|
||||
application_authorization "github.com/APIParkLab/APIPark/service/application-authorization"
|
||||
service_model_mapping "github.com/APIParkLab/APIPark/service/service-model-mapping"
|
||||
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
|
||||
@@ -68,6 +69,8 @@ type imlServiceModule struct {
|
||||
apiService api.IAPIService `autowired:""`
|
||||
apiDocService api_doc.IAPIDocService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
|
||||
serviceModelMappingService service_model_mapping.IServiceModelMappingService `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlServiceModule) ExportAll(ctx context.Context) ([]*service_dto.ExportService, error) {
|
||||
@@ -116,11 +119,9 @@ func (i *imlServiceModule) ExportAll(ctx context.Context) ([]*service_dto.Export
|
||||
items = append(items, info)
|
||||
}
|
||||
return items, nil
|
||||
|
||||
}
|
||||
|
||||
func (i *imlServiceModule) searchMyServices(ctx context.Context, teamId string, keyword string) ([]*service.Service, error) {
|
||||
|
||||
userID := utils.UserId(ctx)
|
||||
condition := make(map[string]interface{})
|
||||
condition["as_server"] = true
|
||||
@@ -140,7 +141,6 @@ func (i *imlServiceModule) searchMyServices(ctx context.Context, teamId string,
|
||||
condition["team"] = teamIds
|
||||
return i.serviceService.Search(ctx, keyword, condition, "create_at desc")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (i *imlServiceModule) SearchMyServices(ctx context.Context, teamId string, keyword string) ([]*service_dto.ServiceItem, error) {
|
||||
@@ -182,7 +182,6 @@ func (i *imlServiceModule) Simple(ctx context.Context) ([]*service_dto.SimpleSer
|
||||
|
||||
items := make([]*service_dto.SimpleServiceItem, 0, len(services))
|
||||
for _, p := range services {
|
||||
|
||||
items = append(items, &service_dto.SimpleServiceItem{
|
||||
Id: p.Id,
|
||||
Name: p.Name,
|
||||
@@ -195,14 +194,12 @@ func (i *imlServiceModule) Simple(ctx context.Context) ([]*service_dto.SimpleSer
|
||||
|
||||
func (i *imlServiceModule) MySimple(ctx context.Context) ([]*service_dto.SimpleServiceItem, error) {
|
||||
services, err := i.searchMyServices(ctx, "", "")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]*service_dto.SimpleServiceItem, 0, len(services))
|
||||
for _, p := range services {
|
||||
|
||||
items = append(items, &service_dto.SimpleServiceItem{
|
||||
Id: p.Id,
|
||||
Name: p.Name,
|
||||
@@ -247,6 +244,13 @@ func (i *imlServiceModule) Get(ctx context.Context, id string) (*service_dto.Ser
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
serviceModelMapping, err := i.serviceModelMappingService.Get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.ModelMapping = serviceModelMapping.Content
|
||||
|
||||
log.Infof("get service cost %d ms", time.Since(now).Milliseconds())
|
||||
return s, nil
|
||||
}
|
||||
@@ -318,7 +322,6 @@ func toServiceItem(model *service.Service) *service_dto.ServiceItem {
|
||||
}
|
||||
|
||||
func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *service_dto.CreateService) (*service_dto.Service, error) {
|
||||
|
||||
if input.Id == "" {
|
||||
input.Id = uuid.New().String()
|
||||
}
|
||||
@@ -356,7 +359,6 @@ func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *ser
|
||||
return nil, fmt.Errorf("ai service: model can not be empty")
|
||||
}
|
||||
mo.AdditionalConfig["model"] = *input.Model
|
||||
|
||||
}
|
||||
if input.AsApp == nil {
|
||||
// 默认值为false
|
||||
@@ -388,6 +390,14 @@ func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *ser
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := i.serviceModelMappingService.Save(ctx, &service_model_mapping.Save{
|
||||
Sid: input.Id,
|
||||
Content: input.ModelMapping,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return i.serviceService.Create(ctx, mo)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -410,7 +420,6 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
|
||||
if input.Model != nil {
|
||||
info.AdditionalConfig["model"] = *input.Model
|
||||
}
|
||||
|
||||
}
|
||||
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
|
||||
serviceType := (*service.ServiceType)(input.ServiceType)
|
||||
@@ -457,9 +466,15 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
|
||||
}
|
||||
}
|
||||
}
|
||||
err = i.serviceModelMappingService.Save(ctx, &service_model_mapping.Save{
|
||||
Sid: id,
|
||||
Content: input.ModelMapping,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -523,7 +538,6 @@ type imlServiceDocModule struct {
|
||||
|
||||
func (i *imlServiceDocModule) ServiceDoc(ctx context.Context, pid string) (*serviceDto.ServiceDoc, error) {
|
||||
_, err := i.serviceService.Check(ctx, pid, map[string]bool{"as_server": true})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -555,7 +569,6 @@ func (i *imlServiceDocModule) ServiceDoc(ctx context.Context, pid string) (*serv
|
||||
|
||||
func (i *imlServiceDocModule) SaveServiceDoc(ctx context.Context, pid string, input *serviceDto.SaveServiceDoc) error {
|
||||
_, err := i.serviceService.Check(ctx, pid, map[string]bool{"as_server": true})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -737,7 +750,6 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string
|
||||
}
|
||||
|
||||
func (i *imlAppModule) CreateApp(ctx context.Context, teamID string, input *service_dto.CreateApp) (*service_dto.App, error) {
|
||||
|
||||
if input.Id == "" {
|
||||
input.Id = uuid.New().String()
|
||||
}
|
||||
@@ -759,9 +771,7 @@ func (i *imlAppModule) CreateApp(ctx context.Context, teamID string, input *serv
|
||||
}
|
||||
|
||||
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
|
||||
|
||||
return i.serviceService.Create(ctx, mo)
|
||||
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -770,7 +780,7 @@ func (i *imlAppModule) CreateApp(ctx context.Context, teamID string, input *serv
|
||||
}
|
||||
|
||||
func (i *imlAppModule) UpdateApp(ctx context.Context, appId string, input *service_dto.UpdateApp) (*service_dto.App, error) {
|
||||
//userId := utils.UserId(ctx)
|
||||
// userId := utils.UserId(ctx)
|
||||
info, err := i.serviceService.Get(ctx, appId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -907,7 +917,6 @@ func (i *imlAppModule) MySimpleApps(ctx context.Context, keyword string) ([]*ser
|
||||
}
|
||||
items := make([]*service_dto.SimpleAppItem, 0, len(services))
|
||||
for _, p := range services {
|
||||
|
||||
items = append(items, &service_dto.SimpleAppItem{
|
||||
Id: p.Id,
|
||||
Name: p.Name,
|
||||
|
||||
@@ -3,9 +3,10 @@ package service_doc
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
"time"
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
|
||||
"github.com/eolinker/go-common/utils"
|
||||
"gorm.io/gorm"
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@ package service_doc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
"reflect"
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package service_model_mapping
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/APIParkLab/APIPark/stores/service"
|
||||
"github.com/eolinker/go-common/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var _ IServiceModelMappingService = (*imlServiceModelMappingService)(nil)
|
||||
|
||||
type imlServiceModelMappingService struct {
|
||||
store service.IServiceModelMappingStore `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlServiceModelMappingService) Get(ctx context.Context, sid string) (*ModelMapping, error) {
|
||||
entity, err := i.store.First(ctx, map[string]interface{}{"sid": sid})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return &ModelMapping{
|
||||
Sid: sid,
|
||||
Content: "",
|
||||
}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return FromEntity(entity), nil
|
||||
}
|
||||
|
||||
func FromEntity(e *service.ModelMapping) *ModelMapping {
|
||||
content := ""
|
||||
if e.Content != "" {
|
||||
content = e.Content
|
||||
}
|
||||
return &ModelMapping{
|
||||
ID: e.Id,
|
||||
Sid: e.Sid,
|
||||
Content: content,
|
||||
CreateAt: e.CreateAt,
|
||||
UpdateAt: e.UpdateAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *imlServiceModelMappingService) Save(ctx context.Context, input *Save) error {
|
||||
info, err := i.store.First(ctx, map[string]interface{}{"sid": input.Sid})
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
userID := utils.UserId(ctx)
|
||||
if info != nil {
|
||||
info.Content = input.Content
|
||||
info.Updater = userID
|
||||
info.UpdateAt = time.Now()
|
||||
return i.store.Save(ctx, info)
|
||||
}
|
||||
return i.store.Insert(ctx, &service.ModelMapping{
|
||||
Sid: input.Sid,
|
||||
Content: input.Content,
|
||||
CreateAt: time.Now(),
|
||||
UpdateAt: time.Now(),
|
||||
Creator: userID,
|
||||
Updater: userID,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package service_model_mapping
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ModelMapping struct {
|
||||
ID int64 `json:"id"`
|
||||
Sid string `json:"sid"`
|
||||
Content string `json:"content"`
|
||||
Creator string `json:"creator"`
|
||||
Updater string `json:"updater"`
|
||||
CreateAt time.Time `json:"create_at"`
|
||||
UpdateAt time.Time `json:"update_at"`
|
||||
}
|
||||
|
||||
type Save struct {
|
||||
Sid string `json:"sid" validate:"required"`
|
||||
Content string `json:"content" validate:"required"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package service_model_mapping
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
)
|
||||
|
||||
type IServiceModelMappingService interface {
|
||||
Get(ctx context.Context, sid string) (*ModelMapping, error)
|
||||
Save(ctx context.Context, input *Save) error
|
||||
}
|
||||
|
||||
func init() {
|
||||
autowire.Auto[IServiceModelMappingService](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlServiceModelMappingService))
|
||||
})
|
||||
}
|
||||
@@ -14,9 +14,7 @@ import (
|
||||
"github.com/APIParkLab/APIPark/stores/service"
|
||||
)
|
||||
|
||||
var (
|
||||
_ IServiceService = (*imlServiceService)(nil)
|
||||
)
|
||||
var _ IServiceService = (*imlServiceService)(nil)
|
||||
|
||||
type imlServiceService struct {
|
||||
store service.IServiceStore `autowired:""`
|
||||
@@ -154,9 +152,11 @@ func (i *imlServiceService) OnComplete() {
|
||||
func labelHandler(e *service.Service) []string {
|
||||
return []string{e.Name, e.UUID, e.Description}
|
||||
}
|
||||
|
||||
func uniquestHandler(i *Create) []map[string]interface{} {
|
||||
return []map[string]interface{}{{"uuid": i.Id}}
|
||||
}
|
||||
|
||||
func createEntityHandler(i *Create) *service.Service {
|
||||
cfg, _ := json.Marshal(i.AdditionalConfig)
|
||||
now := time.Now()
|
||||
|
||||
@@ -4,15 +4,14 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/eolinker/go-common/auto"
|
||||
"github.com/eolinker/go-common/store"
|
||||
"github.com/eolinker/go-common/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
_ IServiceDelete = (*imlServiceDelete[any])(nil)
|
||||
)
|
||||
var _ IServiceDelete = (*imlServiceDelete[any])(nil)
|
||||
|
||||
type IServiceDelete interface {
|
||||
Delete(ctx context.Context, uuid string) error
|
||||
@@ -26,10 +25,12 @@ func NewDelete[E any](store store.ISearchStore[E]) IServiceDelete {
|
||||
assert(new(E))
|
||||
return &imlServiceDelete[E]{store: store}
|
||||
}
|
||||
|
||||
func NewSoftDelete[E any](s store.ISearchStore[E]) IServiceDelete {
|
||||
assert(new(E))
|
||||
return &imlServiceSoftDelete[E]{store: s}
|
||||
}
|
||||
|
||||
func (p *imlServiceDelete[E]) Delete(ctx context.Context, uuid string) error {
|
||||
return p.store.Transaction(ctx, func(ctx context.Context) error {
|
||||
o, err := p.store.First(ctx, map[string]interface{}{"uuid": uuid})
|
||||
@@ -46,7 +47,6 @@ func (p *imlServiceDelete[E]) Delete(ctx context.Context, uuid string) error {
|
||||
}
|
||||
return p.store.SetLabels(ctx, idValue(o))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
type imlServiceSoftDelete[E any] struct {
|
||||
@@ -66,7 +66,5 @@ func (p *imlServiceSoftDelete[E]) Delete(ctx context.Context, uuid string) error
|
||||
|
||||
auto.Auto("operator", operator, o)
|
||||
return p.store.SoftDelete(ctx, map[string]interface{}{"uuid": uuid})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,6 +1,8 @@
|
||||
package service
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"`
|
||||
@@ -27,6 +29,7 @@ type Service struct {
|
||||
func (p *Service) IdValue() int64 {
|
||||
return p.Id
|
||||
}
|
||||
|
||||
func (p *Service) TableName() string {
|
||||
return "service"
|
||||
}
|
||||
@@ -87,3 +90,21 @@ func (d *Doc) IdValue() int64 {
|
||||
func (d *Doc) TableName() string {
|
||||
return "server_doc"
|
||||
}
|
||||
|
||||
type ModelMapping struct {
|
||||
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:PRIMARY ID;primary_key"`
|
||||
Sid string `gorm:"size:36;not null;column:sid;comment:service uuid;uniqueIndex:unique_sid;"`
|
||||
Content string `gorm:"type:text;not null;column:content;comment:mapping json"`
|
||||
Creator string `gorm:"type:varchar(36);not null;column:creator;comment:creator" aovalue:"creator"`
|
||||
Updater string `gorm:"type:varchar(36);not null;column:updater;comment:updater" aovalue:"updater"`
|
||||
CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:create_at"`
|
||||
UpdateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;column:update_at;comment:update_at"`
|
||||
}
|
||||
|
||||
func (m *ModelMapping) TableName() string {
|
||||
return "service_model_mapping"
|
||||
}
|
||||
|
||||
func (m *ModelMapping) IdValue() int64 {
|
||||
return m.Id
|
||||
}
|
||||
|
||||
+13
-1
@@ -1,10 +1,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
"github.com/eolinker/go-common/store"
|
||||
)
|
||||
import "reflect"
|
||||
|
||||
type IServiceStore interface {
|
||||
store.ISearchStore[Service]
|
||||
@@ -37,6 +38,14 @@ type imlAuthorizationStore struct {
|
||||
store.SearchStore[Authorization]
|
||||
}
|
||||
|
||||
type IServiceModelMappingStore interface {
|
||||
store.ISearchStore[ModelMapping]
|
||||
}
|
||||
|
||||
type imlServiceModelMappingStore struct {
|
||||
store.SearchStore[ModelMapping]
|
||||
}
|
||||
|
||||
func init() {
|
||||
autowire.Auto[IServiceStore](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlServiceStore))
|
||||
@@ -52,4 +61,7 @@ func init() {
|
||||
return reflect.ValueOf(new(imlServiceDocStore))
|
||||
})
|
||||
|
||||
autowire.Auto[IServiceModelMappingStore](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlServiceModelMappingStore))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user