Skip to content

Commit

Permalink
Creates Portfolio Group when multiple Portfolios are Uploaded (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdubs authored Jan 22, 2024
1 parent 7840197 commit 514a93e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions azure/azevents/azevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type DB interface {
CreateBlob(tx db.Tx, b *pacta.Blob) (pacta.BlobID, error)
CreatePortfolio(tx db.Tx, p *pacta.Portfolio) (pacta.PortfolioID, error)

CreatePortfolioGroup(tx db.Tx, pg *pacta.PortfolioGroup) (pacta.PortfolioGroupID, error)
CreatePortfolioGroupMembership(tx db.Tx, pgID pacta.PortfolioGroupID, pID pacta.PortfolioID) error

IncompleteUploads(tx db.Tx, ids []pacta.IncompleteUploadID) (map[pacta.IncompleteUploadID]*pacta.IncompleteUpload, error)
UpdateIncompleteUpload(tx db.Tx, id pacta.IncompleteUploadID, mutations ...db.UpdateIncompleteUploadFn) error

Expand Down Expand Up @@ -336,6 +339,20 @@ func (s *Server) handleParsedPortfolio(id string, resp *task.ParsePortfolioRespo
}
portfolioIDs = append(portfolioIDs, portfolioID)
}
if len(portfolioIDs) > 1 {
pgID, err := s.db.CreatePortfolioGroup(tx, &pacta.PortfolioGroup{
Owner: &pacta.Owner{ID: ownerID},
Name: "Upload on " + now.Format("2006-01-02"),
})
if err != nil {
return fmt.Errorf("creating portfolio_group: %w", err)
}
for _, pID := range portfolioIDs {
if err := s.db.CreatePortfolioGroupMembership(tx, pgID, pID); err != nil {
return fmt.Errorf("creating portfolio_group_membership: %w", err)
}
}
}
for iuid, iu := range incompleteUploads {
err := s.db.UpdateIncompleteUpload(
tx,
Expand Down

0 comments on commit 514a93e

Please sign in to comment.