diff --git a/azure/azevents/azevents.go b/azure/azevents/azevents.go index 8d0e262..b0f2b33 100644 --- a/azure/azevents/azevents.go +++ b/azure/azevents/azevents.go @@ -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 @@ -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,