(ctx context.Context, serviceId string, input *dto.CreateInput)
| 65 | } |
| 66 | |
| 67 | func (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 { |
nothing calls this directly
no test coverage detected