mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
Merge branch 'feature/1.7-liujian' into 'main'
Fix: Issue of API duplicate publishing when publishing services See merge request apipark/APIPark!331
This commit is contained in:
@@ -78,17 +78,14 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
|
||||
return "", fmt.Errorf("cluster not set:%w", err)
|
||||
}
|
||||
|
||||
apis, err := m.apiService.ListInfoForService(ctx, proInfo.Id)
|
||||
apis, err := m.apiService.ListForService(ctx, proInfo.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", errors.New("api not found")
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
if len(apis) == 0 {
|
||||
return "", errors.New("api not found")
|
||||
}
|
||||
apiUUIDS := utils.SliceToSlice(apis, func(a *api.Info) string {
|
||||
apiUUIDS := utils.SliceToSlice(apis, func(a *api.API) string {
|
||||
return a.UUID
|
||||
})
|
||||
apiProxy, err := m.apiService.ListLatestCommitProxy(ctx, apiUUIDS...)
|
||||
@@ -122,10 +119,10 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
|
||||
return c.Key, c.UUID
|
||||
})
|
||||
})
|
||||
|
||||
apiInfos, err := m.apiService.ListInfo(ctx, apiUUIDS...)
|
||||
var newRelease *release.Release
|
||||
err = m.transaction.Transaction(ctx, func(ctx context.Context) error {
|
||||
for _, a := range apis {
|
||||
for _, a := range apiInfos {
|
||||
err = m.apiService.SaveRequest(ctx, a.UUID, &api.Request{
|
||||
Path: a.Path,
|
||||
Methods: a.Methods,
|
||||
|
||||
@@ -351,7 +351,14 @@ func (i *imlRouterModule) Delete(ctx context.Context, serviceId string, apiId st
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return i.apiService.Delete(ctx, apiId)
|
||||
return i.transaction.Transaction(ctx, func(ctx context.Context) error {
|
||||
err = i.apiService.Delete(ctx, apiId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return i.apiService.DeleteAPIInfo(ctx, apiId)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (i *imlRouterModule) Prefix(ctx context.Context, serviceId string) (string, error) {
|
||||
|
||||
@@ -41,6 +41,12 @@ type imlAPIService struct {
|
||||
universally.IServiceDelete
|
||||
}
|
||||
|
||||
func (i *imlAPIService) DeleteAPIInfo(ctx context.Context, aid string) error {
|
||||
return i.apiInfoStore.SoftDelete(ctx, map[string]interface{}{
|
||||
"uuid": aid,
|
||||
})
|
||||
}
|
||||
|
||||
func (i *imlAPIService) DeleteByService(ctx context.Context, serviceId string) error {
|
||||
return i.store.SoftDelete(ctx, map[string]interface{}{
|
||||
"service": serviceId,
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
type IAPIService interface {
|
||||
universally.IServiceGet[API]
|
||||
universally.IServiceDelete
|
||||
DeleteAPIInfo(ctx context.Context, aid string) error
|
||||
CountByService(ctx context.Context, service string) (int64, error)
|
||||
CountMapByService(ctx context.Context, service ...string) (map[string]int64, error)
|
||||
Exist(ctx context.Context, aid string, api *Exist) error
|
||||
|
||||
@@ -34,6 +34,7 @@ type Info struct {
|
||||
Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"` // 更新人
|
||||
UpdateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:update_at;comment:更新时间"`
|
||||
Disable bool `gorm:"type:tinyint(1);not null;column:disable;comment:是否禁用 0:否 1:是"`
|
||||
IsDelete bool `gorm:"type:tinyint(1);not null;column:is_delete;comment:是否删除 0:否 1:是"`
|
||||
}
|
||||
|
||||
func (i *Info) TableName() string {
|
||||
|
||||
Reference in New Issue
Block a user