diff --git a/module/release/iml.go b/module/release/iml.go index 5aa337cc..296c5fa5 100644 --- a/module/release/iml.go +++ b/module/release/iml.go @@ -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, diff --git a/module/router/iml.go b/module/router/iml.go index 7cac0566..a7f368fc 100644 --- a/module/router/iml.go +++ b/module/router/iml.go @@ -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) { diff --git a/service/api/iml.go b/service/api/iml.go index a784fed5..5cfa23a0 100644 --- a/service/api/iml.go +++ b/service/api/iml.go @@ -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, diff --git a/service/api/service.go b/service/api/service.go index 7e2a758f..4059428c 100644 --- a/service/api/service.go +++ b/service/api/service.go @@ -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 diff --git a/stores/api/model.go b/stores/api/model.go index 9447da32..b1eb2ded 100644 --- a/stores/api/model.go +++ b/stores/api/model.go @@ -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 {