-
Notifications
You must be signed in to change notification settings - Fork 16
/
document_session_attachments.go
57 lines (49 loc) · 1.82 KB
/
document_session_attachments.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package ravendb
// Note: Java's IAttachmentsSessionOperations is DocumentSessionAttachments
// TODO: make a unique wrapper type
type AttachmentsSessionOperations = DocumentSessionAttachments
type DocumentSessionAttachments struct {
*DocumentSessionAttachmentsBase
}
func NewDocumentSessionAttachments(session *InMemoryDocumentSessionOperations) *DocumentSessionAttachments {
res := &DocumentSessionAttachments{}
res.DocumentSessionAttachmentsBase = NewDocumentSessionAttachmentsBase(session)
return res
}
func (s *DocumentSessionAttachments) Exists(documentID string, name string) (bool, error) {
command, err := NewHeadAttachmentCommand(documentID, name, nil)
if err != nil {
return false, err
}
err = s.requestExecutor.ExecuteCommand(command, s.sessionInfo)
if err != nil {
return false, err
}
res := command.Result != ""
return res, nil
}
func (s *DocumentSessionAttachments) GetByID(documentID string, name string) (*AttachmentResult, error) {
operation := NewGetAttachmentOperation(documentID, name, AttachmentDocument, "", nil)
err := s.session.GetOperations().Send(operation, s.sessionInfo)
if err != nil {
return nil, err
}
res := operation.Command.Result
return res, nil
}
func (s *DocumentSessionAttachments) Get(entity interface{}, name string) (*AttachmentResult, error) {
document := getDocumentInfoByEntity(s.documents, entity)
if document == nil {
return nil, throwEntityNotInSession(entity)
}
return s.GetByID(document.id, name)
}
func (s *DocumentSessionAttachments) GetRevision(documentID string, name string, changeVector *string) (*AttachmentResult, error) {
operation := NewGetAttachmentOperation(documentID, name, AttachmentRevision, "", changeVector)
err := s.session.GetOperations().Send(operation, s.sessionInfo)
if err != nil {
return nil, err
}
res := operation.Command.Result
return res, nil
}