mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
发布功能完成
This commit is contained in:
+18
-20
@@ -229,24 +229,7 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
|
||||
|
||||
return nil, fmt.Errorf("get running release failed: %w", err)
|
||||
}
|
||||
_, docCommits, _, err := i.releaseService.GetReleaseInfos(ctx, r.UUID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get release apis failed: %w", err)
|
||||
}
|
||||
apiMap := make(map[string]*release.APIDocumentCommit)
|
||||
apiIds := make([]string, 0, len(docCommits))
|
||||
for _, v := range docCommits {
|
||||
apiIds = append(apiIds, v.API)
|
||||
apiMap[v.API] = v
|
||||
}
|
||||
//apiList, err := i.apiService.ListInfo(ctx, apiIds...)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//apiNum := 0
|
||||
//if len(docCommits) > 0 {
|
||||
// i.apiDocService.ListDocCommit(ctx,docCommits[0].Commit)
|
||||
//}
|
||||
|
||||
countMap, err := i.subscribeService.CountMapByService(ctx, subscribe.ApplyStatusSubscribe, sid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -260,13 +243,27 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
|
||||
}, func(t *service_tag.Tag) bool {
|
||||
return t.Sid == sid
|
||||
})
|
||||
_, _, docCommits, _, err := i.releaseService.GetReleaseInfos(ctx, r.UUID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get release apis failed: %w", err)
|
||||
}
|
||||
var apiDoc string
|
||||
var apiNum int
|
||||
if len(docCommits) > 0 {
|
||||
commit, err := i.apiDocService.GetDocCommit(ctx, docCommits[0].Commit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
apiDoc = commit.Data.Content
|
||||
apiNum = int(commit.Data.APICount)
|
||||
}
|
||||
return &catalogue_dto.ServiceDetail{
|
||||
Name: s.Name,
|
||||
Description: s.Description,
|
||||
Document: docStr,
|
||||
Basic: &catalogue_dto.ServiceBasic{
|
||||
Team: auto.UUID(s.Team),
|
||||
//ApiNum: len(apis),
|
||||
Team: auto.UUID(s.Team),
|
||||
ApiNum: apiNum,
|
||||
AppNum: int(countMap[s.Id]),
|
||||
Tags: auto.List(tagIds),
|
||||
Catalogue: auto.UUID(s.Catalogue),
|
||||
@@ -274,6 +271,7 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
|
||||
UpdateTime: auto.TimeLabel(r.CreateAt),
|
||||
Logo: s.Logo,
|
||||
},
|
||||
APIDoc: apiDoc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
+53
-21
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/cluster"
|
||||
"github.com/APIParkLab/APIPark/service/service"
|
||||
@@ -33,6 +34,7 @@ type imlReleaseModule struct {
|
||||
projectDiffModule serviceDiff.IServiceDiffModule `autowired:""`
|
||||
releaseService release.IReleaseService `autowired:""`
|
||||
apiService api.IAPIService `autowired:""`
|
||||
apiDocService api_doc.IAPIDocService `autowired:""`
|
||||
upstreamService upstream.IUpstreamService `autowired:""`
|
||||
publishService publish.IPublishService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
@@ -54,7 +56,7 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
|
||||
return "", fmt.Errorf("cluster not set:%w", err)
|
||||
}
|
||||
|
||||
apis, err := m.apiService.ListForService(ctx, proInfo.Id)
|
||||
apis, err := m.apiService.ListInfoForService(ctx, proInfo.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", errors.New("api not found")
|
||||
@@ -64,7 +66,7 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
|
||||
if len(apis) == 0 {
|
||||
return "", errors.New("api not found")
|
||||
}
|
||||
apiUUIDS := utils.SliceToSlice(apis, func(a *api.API) string {
|
||||
apiUUIDS := utils.SliceToSlice(apis, func(a *api.Info) string {
|
||||
return a.UUID
|
||||
})
|
||||
apiProxy, err := m.apiService.ListLatestCommitProxy(ctx, apiUUIDS...)
|
||||
@@ -77,16 +79,7 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
|
||||
if len(apis) != len(apiProxy) {
|
||||
return "", errors.New("api or document not found")
|
||||
}
|
||||
//apiDocs, err := m.apiService.ListLatestCommitDocument(ctx, apiUUIDS...)
|
||||
//if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return "", errors.New("api config or document not found")
|
||||
// }
|
||||
// return "", err
|
||||
//}
|
||||
//if len(apis) != len(apiDocs) {
|
||||
// return "", errors.New("api or document not found")
|
||||
//}
|
||||
|
||||
upstreams, err := m.upstreamService.ListLatestCommit(ctx, serviceId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@@ -98,9 +91,7 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
|
||||
apiProxyCommits := utils.SliceToMapO(apiProxy, func(c *commit.Commit[api.Proxy]) (string, string) {
|
||||
return c.Target, c.UUID
|
||||
})
|
||||
//apiDocumentCommits := utils.SliceToMapO(apiDocs, func(c *commit.Commit[api.Document]) (string, string) {
|
||||
// return c.Target, c.UUID
|
||||
//})
|
||||
|
||||
upstreamCommits := utils.SliceToMapArray(upstreams, func(c *commit.Commit[upstream.Config]) string {
|
||||
return c.Target
|
||||
})
|
||||
@@ -109,15 +100,56 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
|
||||
return c.Key, c.UUID
|
||||
})
|
||||
})
|
||||
if !m.releaseService.Completeness(utils.SliceToSlice(clusters, func(s *cluster.Cluster) string {
|
||||
return s.Uuid
|
||||
}), apiUUIDS, apiProxy, nil, upstreams) {
|
||||
return "", errors.New("completeness check failed")
|
||||
}
|
||||
newRelease, err := m.releaseService.CreateRelease(ctx, serviceId, input.Version, input.Remark, apiProxyCommits, nil, upstreamCommitsForUKC)
|
||||
|
||||
var newRelease *release.Release
|
||||
err = m.transaction.Transaction(ctx, func(ctx context.Context) error {
|
||||
for _, a := range apis {
|
||||
err = m.apiService.SaveRequest(ctx, a.UUID, &api.Request{
|
||||
Path: a.Path,
|
||||
Methods: a.Methods,
|
||||
Protocols: a.Protocols,
|
||||
Match: a.Match,
|
||||
Disable: a.Disable,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
requestCommits, err := m.apiService.ListLatestCommitRequest(ctx, apiUUIDS...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
doc, err := m.apiDocService.GetDoc(ctx, serviceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = m.apiDocService.CommitDoc(ctx, serviceId, doc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
docCommit, err := m.apiDocService.LatestDocCommit(ctx, serviceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
docCommitMap := map[string]string{
|
||||
docCommit.Target: docCommit.UUID,
|
||||
}
|
||||
if !m.releaseService.Completeness(utils.SliceToSlice(clusters, func(s *cluster.Cluster) string {
|
||||
return s.Uuid
|
||||
}), apiUUIDS, requestCommits, apiProxy, upstreams) {
|
||||
return errors.New("completeness check failed")
|
||||
}
|
||||
requestCommitMap := utils.SliceToMapO(requestCommits, func(c *commit.Commit[api.Request]) (string, string) {
|
||||
return c.Target, c.UUID
|
||||
})
|
||||
newRelease, err = m.releaseService.CreateRelease(ctx, serviceId, input.Version, input.Remark, requestCommitMap, apiProxyCommits, docCommitMap, nil, upstreamCommitsForUKC)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return newRelease.UUID, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user