Cleanup publish version
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -58,6 +58,12 @@ type (
|
|||||||
OrganizationID gid.GID `json:"organization_id"`
|
OrganizationID gid.GID `json:"organization_id"`
|
||||||
PeopleID gid.GID `json:"people_id"`
|
PeopleID gid.GID `json:"people_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BulkPublishVersionsRequest struct {
|
||||||
|
DocumentIDs []gid.GID
|
||||||
|
PublishedBy gid.GID
|
||||||
|
Changelog string
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -147,9 +153,7 @@ func (s DocumentService) GenerateChangelog(
|
|||||||
|
|
||||||
func (s *DocumentService) BulkPublishVersions(
|
func (s *DocumentService) BulkPublishVersions(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
documentIds []gid.GID,
|
req BulkPublishVersionsRequest,
|
||||||
publishedBy gid.GID,
|
|
||||||
changelog string,
|
|
||||||
) ([]*coredata.DocumentVersion, []*coredata.Document, error) {
|
) ([]*coredata.DocumentVersion, []*coredata.Document, error) {
|
||||||
var publishedVersions []*coredata.DocumentVersion
|
var publishedVersions []*coredata.DocumentVersion
|
||||||
var updatedDocuments []*coredata.Document
|
var updatedDocuments []*coredata.Document
|
||||||
@@ -157,8 +161,13 @@ func (s *DocumentService) BulkPublishVersions(
|
|||||||
err := s.svc.pg.WithTx(
|
err := s.svc.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(tx pg.Conn) error {
|
func(tx pg.Conn) error {
|
||||||
for _, documentID := range documentIds {
|
people := &coredata.People{}
|
||||||
document, version, err := s.publishVersionInTx(ctx, tx, documentID, publishedBy, &changelog)
|
if err := people.LoadByID(ctx, tx, s.svc.scope, req.PublishedBy); err != nil {
|
||||||
|
return fmt.Errorf("cannot load people: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, documentID := range req.DocumentIDs {
|
||||||
|
document, version, err := s.publishVersionInTx(ctx, tx, documentID, people, &req.Changelog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot publish document %q: %w", documentID, err)
|
return fmt.Errorf("cannot publish document %q: %w", documentID, err)
|
||||||
}
|
}
|
||||||
@@ -191,8 +200,18 @@ func (s *DocumentService) PublishVersion(
|
|||||||
ctx,
|
ctx,
|
||||||
func(tx pg.Conn) error {
|
func(tx pg.Conn) error {
|
||||||
var err error
|
var err error
|
||||||
document, documentVersion, err = s.publishVersionInTx(ctx, tx, documentID, publishedBy, changelog)
|
|
||||||
return err
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, tx, s.svc.scope, publishedBy); err != nil {
|
||||||
|
return fmt.Errorf("cannot load people: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
document, documentVersion, err = s.publishVersionInTx(ctx, tx, documentID, people, changelog)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot publish version: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -207,19 +226,14 @@ func (s *DocumentService) publishVersionInTx(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
tx pg.Conn,
|
tx pg.Conn,
|
||||||
documentID gid.GID,
|
documentID gid.GID,
|
||||||
publishedBy gid.GID,
|
publishedBy *coredata.People,
|
||||||
changelog *string,
|
changelog *string,
|
||||||
) (*coredata.Document, *coredata.DocumentVersion, error) {
|
) (*coredata.Document, *coredata.DocumentVersion, error) {
|
||||||
document := &coredata.Document{}
|
document := &coredata.Document{}
|
||||||
documentVersion := &coredata.DocumentVersion{}
|
documentVersion := &coredata.DocumentVersion{}
|
||||||
publishedVersion := &coredata.DocumentVersion{}
|
publishedVersion := &coredata.DocumentVersion{}
|
||||||
people := &coredata.People{}
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
if err := people.LoadByID(ctx, tx, s.svc.scope, publishedBy); err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("cannot load people: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := document.LoadByID(ctx, tx, s.svc.scope, documentID); err != nil {
|
if err := document.LoadByID(ctx, tx, s.svc.scope, documentID); err != nil {
|
||||||
return nil, nil, fmt.Errorf("cannot load document %q: %w", documentID, err)
|
return nil, nil, fmt.Errorf("cannot load document %q: %w", documentID, err)
|
||||||
}
|
}
|
||||||
@@ -252,9 +266,7 @@ func (s *DocumentService) publishVersionInTx(
|
|||||||
|
|
||||||
documentVersion.Status = coredata.DocumentStatusPublished
|
documentVersion.Status = coredata.DocumentStatusPublished
|
||||||
documentVersion.PublishedAt = &now
|
documentVersion.PublishedAt = &now
|
||||||
if publishedBy != gid.Nil {
|
documentVersion.PublishedBy = &publishedBy.ID
|
||||||
documentVersion.PublishedBy = &people.ID
|
|
||||||
}
|
|
||||||
documentVersion.UpdatedAt = now
|
documentVersion.UpdatedAt = now
|
||||||
|
|
||||||
if err := document.Update(ctx, tx, s.svc.scope); err != nil {
|
if err := document.Update(ctx, tx, s.svc.scope); err != nil {
|
||||||
|
|||||||
@@ -1854,7 +1854,14 @@ func (r *mutationResolver) BulkPublishDocumentVersions(ctx context.Context, inpu
|
|||||||
panic(fmt.Errorf("cannot get people: %w", err))
|
panic(fmt.Errorf("cannot get people: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
documentVersions, documents, err := prb.Documents.BulkPublishVersions(ctx, input.DocumentIds, people.ID, input.Changelog)
|
documentVersions, documents, err := prb.Documents.BulkPublishVersions(
|
||||||
|
ctx,
|
||||||
|
probo.BulkPublishVersionsRequest{
|
||||||
|
DocumentIDs: input.DocumentIds,
|
||||||
|
PublishedBy: people.ID,
|
||||||
|
Changelog: input.Changelog,
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("cannot bulk publish document versions: %w", err))
|
panic(fmt.Errorf("cannot bulk publish document versions: %w", err))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user