HasCurrentVersion Compares the specified CV with the fetched documents CV, returns error on mismatch between the two
(ctx context.Context, cv Version)
| 1437 | |
| 1438 | // HasCurrentVersion Compares the specified CV with the fetched documents CV, returns error on mismatch between the two |
| 1439 | func (d *Document) HasCurrentVersion(ctx context.Context, cv Version) error { |
| 1440 | if d.HLV == nil { |
| 1441 | return base.RedactErrorf("no HLV present in fetched doc %s", base.UD(d.ID)) |
| 1442 | } |
| 1443 | |
| 1444 | // fetch the current version for the loaded doc and compare against the CV specified in the IDandCV key |
| 1445 | fetchedDocSource, fetchedDocVersion := d.HLV.GetCurrentVersion() |
| 1446 | if fetchedDocSource != cv.SourceID || fetchedDocVersion != cv.Value { |
| 1447 | base.DebugfCtx(ctx, base.KeyCRUD, "mismatch between specified current version and fetched document current version for doc %s", base.UD(d.ID)) |
| 1448 | // return not found as specified cv does not match fetched doc cv |
| 1449 | return base.ErrNotFound |
| 1450 | } |
| 1451 | return nil |
| 1452 | } |
| 1453 | |
| 1454 | // SetAttachments updates the attachments metadata for the document. |
| 1455 | func (d *Document) SetAttachments(attachments AttachmentsMeta) { |