From 1f7c3381eeb9590a6b91f8ada2f7011dbd612763 Mon Sep 17 00:00:00 2001 From: Brandon Sprague Date: Thu, 11 Jan 2024 16:46:15 -0800 Subject: [PATCH] Update generated OAPI bindings, fix enum conv, other small bugs (#136) --- cmd/server/pactasrv/analysis.go | 28 +++++++++---------- cmd/server/pactasrv/conv/conv_test.go | 4 +++ cmd/server/pactasrv/conv/oapi_to_pacta.go | 19 ++++++------- frontend/components/portfolio/ListView.vue | 19 ++++++++++++- frontend/openapi/generated/pacta/index.ts | 2 ++ .../generated/pacta/models/AuditLogAction.ts | 1 + .../generated/pacta/models/MergeUsersReq.ts | 16 +++++++++++ .../generated/pacta/models/MergeUsersResp.ts | 28 +++++++++++++++++++ .../pacta/services/DefaultService.ts | 20 +++++++++++++ 9 files changed, 111 insertions(+), 26 deletions(-) create mode 100644 frontend/openapi/generated/pacta/models/MergeUsersReq.ts create mode 100644 frontend/openapi/generated/pacta/models/MergeUsersResp.ts diff --git a/cmd/server/pactasrv/analysis.go b/cmd/server/pactasrv/analysis.go index aced9a1..2d69232 100644 --- a/cmd/server/pactasrv/analysis.go +++ b/cmd/server/pactasrv/analysis.go @@ -139,20 +139,20 @@ func (s *Server) RunAnalysis(ctx context.Context, request api.RunAnalysisRequest return nil, err } - analysisType, err := conv.AnalysisTypeFromOAPI(&request.Body.AnalysisType) + analysisType, err := conv.AnalysisTypeFromOAPI(request.Body.AnalysisType) if err != nil { return nil, err } var ais []entityForAnalysis if request.Body.InitiativeId != nil { - ais = append(ais, initiativeAnalysis{iID: pacta.InitiativeID(*request.Body.InitiativeId), s: s}) + ais = append(ais, &initiativeAnalysis{iID: pacta.InitiativeID(*request.Body.InitiativeId), s: s}) } if request.Body.PortfolioGroupId != nil { - ais = append(ais, portfolioGroupAnalysis{pgID: pacta.PortfolioGroupID(*request.Body.PortfolioGroupId), s: s}) + ais = append(ais, &portfolioGroupAnalysis{pgID: pacta.PortfolioGroupID(*request.Body.PortfolioGroupId), s: s}) } if request.Body.PortfolioId != nil { - ais = append(ais, portfolioAnalysis{pID: pacta.PortfolioID(*request.Body.PortfolioId), s: s}) + ais = append(ais, &portfolioAnalysis{pID: pacta.PortfolioID(*request.Body.PortfolioId), s: s}) } if len(ais) == 0 { return nil, oapierr.BadRequest("one of initiative_id, portfolio_group_id, or portfolio_id is required") @@ -200,7 +200,7 @@ func (s *Server) RunAnalysis(ctx context.Context, request api.RunAnalysisRequest } aID, err := s.DB.CreateAnalysis(tx, &pacta.Analysis{ - AnalysisType: *analysisType, + AnalysisType: analysisType, PortfolioSnapshot: &pacta.PortfolioSnapshot{ID: snapshotID}, PACTAVersion: &pacta.PACTAVersion{ID: pvID}, Owner: &pacta.Owner{ID: actorInfo.OwnerID}, @@ -216,7 +216,7 @@ func (s *Server) RunAnalysis(ctx context.Context, request api.RunAnalysisRequest ActorOwner: &pacta.Owner{ID: actorInfo.OwnerID}, Action: pacta.AuditLogAction_Create, PrimaryTargetType: pacta.AuditLogTargetType_Analysis, - PrimaryTargetID: string(analysisID), + PrimaryTargetID: string(aID), PrimaryTargetOwner: &pacta.Owner{ID: actorInfo.OwnerID}, }); err != nil { return fmt.Errorf("creating audit log: %w", err) @@ -232,7 +232,7 @@ func (s *Server) RunAnalysis(ctx context.Context, request api.RunAnalysisRequest return nil, oapierr.Internal("failed to create analysis", zap.Error(err)) } - switch *analysisType { + switch analysisType { case pacta.AnalysisType_Audit: taskID, runnerID, err := s.TaskRunner.CreateAudit(ctx, &task.CreateAuditRequest{ AnalysisID: analysisID, @@ -252,7 +252,7 @@ func (s *Server) RunAnalysis(ctx context.Context, request api.RunAnalysisRequest } s.Logger.Info("created report task", zap.String("task_id", string(taskID)), zap.String("runner_id", string(runnerID)), zap.String("analysis_id", string(analysisID))) default: - return nil, oapierr.Internal("unknown analysis type", zap.String("analysis_type", string(*analysisType))) + return nil, oapierr.Internal("unknown analysis type", zap.String("analysis_type", string(analysisType))) } return api.RunAnalysis200JSONResponse{AnalysisId: string(analysisID)}, nil @@ -278,7 +278,7 @@ func notFoundErr[T ~string](typeName string, id T, fields ...zapcore.Field) erro return oapierr.NotFound(fmt.Sprintf("%s not found", typeName), fs...) } -func (pa portfolioAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { +func (pa *portfolioAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { actorInfo, err := pa.s.getActorInfoOrErrIfAnon(ctx) if err != nil { return err @@ -300,7 +300,7 @@ func (pa portfolioAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { return nil } -func (pa portfolioAnalysis) createSnapshot(tx db.Tx) (pacta.PortfolioSnapshotID, []pacta.BlobID, error) { +func (pa *portfolioAnalysis) createSnapshot(tx db.Tx) (pacta.PortfolioSnapshotID, []pacta.BlobID, error) { sID, err := pa.s.DB.CreateSnapshotOfPortfolio(tx, pa.pID) if err != nil { return "", nil, fmt.Errorf("creating snapshot of portfolio: %w", err) @@ -315,7 +315,7 @@ type portfolioGroupAnalysis struct { pg *pacta.PortfolioGroup } -func (pga portfolioGroupAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { +func (pga *portfolioGroupAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { actorInfo, err := pga.s.getActorInfoOrErrIfAnon(ctx) if err != nil { return err @@ -337,7 +337,7 @@ func (pga portfolioGroupAnalysis) checkAuth(ctx context.Context, tx db.Tx) error return nil } -func (pga portfolioGroupAnalysis) createSnapshot(tx db.Tx) (pacta.PortfolioSnapshotID, []pacta.BlobID, error) { +func (pga *portfolioGroupAnalysis) createSnapshot(tx db.Tx) (pacta.PortfolioSnapshotID, []pacta.BlobID, error) { sID, err := pga.s.DB.CreateSnapshotOfPortfolioGroup(tx, pga.pgID) if err != nil { return "", nil, fmt.Errorf("creating snapshot of portfolio group: %w", err) @@ -364,7 +364,7 @@ type initiativeAnalysis struct { i *pacta.Initiative } -func (ia initiativeAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { +func (ia *initiativeAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { // This crudely tests whether or not a user is a manager of the initiative. if err := ia.s.initiativeDoAuthzAndAuditLog(ctx, ia.iID, pacta.AuditLogAction_Update); err != nil { return err @@ -380,7 +380,7 @@ func (ia initiativeAnalysis) checkAuth(ctx context.Context, tx db.Tx) error { return nil } -func (ia initiativeAnalysis) createSnapshot(tx db.Tx) (pacta.PortfolioSnapshotID, []pacta.BlobID, error) { +func (ia *initiativeAnalysis) createSnapshot(tx db.Tx) (pacta.PortfolioSnapshotID, []pacta.BlobID, error) { sID, err := ia.s.DB.CreateSnapshotOfInitiative(tx, ia.iID) if err != nil { return "", nil, fmt.Errorf("creating snapshot of initiative: %w", err) diff --git a/cmd/server/pactasrv/conv/conv_test.go b/cmd/server/pactasrv/conv/conv_test.go index a06d113..2af6f12 100644 --- a/cmd/server/pactasrv/conv/conv_test.go +++ b/cmd/server/pactasrv/conv/conv_test.go @@ -22,6 +22,10 @@ func TestAuditLogTargetTypeRoundTrip(t *testing.T) { testEnumConvertability(t, pacta.AuditLogTargetTypeValues, auditLogTargetTypeToOAPI, auditLogTargetTypeFromOAPI) } +func TestAnalysisTypeRoundTrip(t *testing.T) { + testEnumConvertability(t, pacta.AnalysisTypeValues, AnalysisTypeToOAPI, AnalysisTypeFromOAPI) +} + func testEnumConvertability[A comparable, B any](t *testing.T, as []A, aToB func(in A) (B, error), bToA func(in B) (A, error)) { for _, a := range as { b, err := aToB(a) diff --git a/cmd/server/pactasrv/conv/oapi_to_pacta.go b/cmd/server/pactasrv/conv/oapi_to_pacta.go index 242de81..ee2c4e0 100644 --- a/cmd/server/pactasrv/conv/oapi_to_pacta.go +++ b/cmd/server/pactasrv/conv/oapi_to_pacta.go @@ -83,17 +83,14 @@ func InitiativeInvitationFromOAPI(i *api.InitiativeInvitationCreate) (*pacta.Ini }, nil } -func AnalysisTypeFromOAPI(at *api.AnalysisType) (*pacta.AnalysisType, error) { - if at == nil { - return nil, oapierr.BadRequest("analysisTypeFromOAPI: can't convert nil pointer") - } - switch string(*at) { - case "audit": - return ptr(pacta.AnalysisType_Audit), nil - case "report": - return ptr(pacta.AnalysisType_Report), nil - } - return nil, oapierr.BadRequest("analysisTypeFromOAPI: unknown analysis type", zap.String("analysis_type", string(*at))) +func AnalysisTypeFromOAPI(at api.AnalysisType) (pacta.AnalysisType, error) { + switch at { + case api.AnalysisTypeAUDIT: + return pacta.AnalysisType_Audit, nil + case api.AnalysisTypeREPORT: + return pacta.AnalysisType_Report, nil + } + return "", oapierr.BadRequest("analysisTypeFromOAPI: unknown analysis type", zap.String("analysis_type", string(at))) } func HoldingsDateFromOAPI(hd *api.HoldingsDate) (*pacta.HoldingsDate, error) { diff --git a/frontend/components/portfolio/ListView.vue b/frontend/components/portfolio/ListView.vue index b8390ce..be32987 100644 --- a/frontend/components/portfolio/ListView.vue +++ b/frontend/components/portfolio/ListView.vue @@ -1,6 +1,6 @@