MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / Create

Method Create

module/release/iml.go:67–199  ·  view source on GitHub ↗
(ctx context.Context, serviceId string, input *dto.CreateInput)

Source from the content-addressed store, hash-verified

65}
66
67func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *dto.CreateInput) (string, error) {
68 proInfo, err := m.projectService.Check(ctx, serviceId, projectRuleMustServer)
69 if err != nil {
70 if errors.Is(err, gorm.ErrRecordNotFound) {
71 return "", errors.New("project not found")
72 }
73 return "", err
74 }
75 clusters, err := m.clusterService.List(ctx)
76 if err != nil || len(clusters) == 0 {
77 return "", fmt.Errorf("cluster not set:%w", err)
78 }
79
80 apis, err := m.apiService.ListForService(ctx, proInfo.Id)
81 if err != nil {
82 return "", err
83 }
84 if len(apis) == 0 {
85 return "", errors.New("api not found")
86 }
87 apiUUIDS := utils.SliceToSlice(apis, func(a *api.API) string {
88 return a.UUID
89 })
90 apiProxy, err := m.apiService.ListLatestCommitProxy(ctx, apiUUIDS...)
91 if err != nil {
92 if errors.Is(err, gorm.ErrRecordNotFound) {
93 return "", errors.New("api config or document not found")
94 }
95 return "", err
96 }
97 if len(apis) != len(apiProxy) {
98 return "", errors.New("api or document not found")
99 }
100
101 upstreams, err := m.upstreamService.ListLatestCommit(ctx, cluster.DefaultClusterID, serviceId)
102 if err != nil {
103 if errors.Is(err, gorm.ErrRecordNotFound) {
104 return "", errors.New("api config or document not found")
105 }
106 return "", err
107 }
108
109 apiProxyCommits := utils.SliceToMapO(apiProxy, func(c *commit.Commit[api.Proxy]) (string, string) {
110 return c.Target, c.UUID
111 })
112
113 upstreamCommits := utils.SliceToMapArray(upstreams, func(c *commit.Commit[upstream.Config]) string {
114 return c.Target
115 })
116 upstreamCommitsForUKC := utils.MapChange(upstreamCommits, func(ls []*commit.Commit[upstream.Config]) map[string]string {
117 return utils.SliceToMapO(ls, func(c *commit.Commit[upstream.Config]) (string, string) {
118 return c.Key, c.UUID
119 })
120 })
121 apiInfos, err := m.apiService.ListInfo(ctx, apiUUIDS...)
122 var newRelease *release.Release
123 err = m.transaction.Transaction(ctx, func(ctx context.Context) error {
124 for _, a := range apiInfos {

Callers

nothing calls this directly

Calls 15

latestStrategyCommitsMethod · 0.95
CheckMethod · 0.65
ListMethod · 0.65
ListForServiceMethod · 0.65
ListLatestCommitProxyMethod · 0.65
ListLatestCommitMethod · 0.65
ListInfoMethod · 0.65
SaveRequestMethod · 0.65
GetDocMethod · 0.65
CommitDocMethod · 0.65
LatestDocCommitMethod · 0.65

Tested by

no test coverage detected