forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathput_attachment_command_data.go
53 lines (45 loc) · 1.31 KB
/
put_attachment_command_data.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
package ravendb
import "io"
type PutAttachmentCommandData struct {
*CommandData
stream io.Reader
contentType string
}
var _ ICommandData = &PutAttachmentCommandData{} // verify interface match
func NewPutAttachmentCommandData(documentID string, name string, stream io.Reader, contentType string, changeVector *string) (*PutAttachmentCommandData, error) {
if stringIsBlank(documentID) {
return nil, newIllegalArgumentError("DocumentId cannot be null or empty")
}
if stringIsBlank(name) {
return nil, newIllegalArgumentError("Name cannot be null or empty")
}
res := &PutAttachmentCommandData{
CommandData: &CommandData{
Type: CommandAttachmentPut,
ID: documentID,
Name: name,
ChangeVector: changeVector,
},
stream: stream,
contentType: contentType,
}
return res, nil
}
func (d *PutAttachmentCommandData) serialize(conventions *DocumentConventions) (interface{}, error) {
res := d.baseJSON()
res["Name"] = d.Name
if d.contentType != "" {
res["ContentType"] = d.contentType
} else {
res["ContentType"] = nil
}
res["Type"] = "AttachmentPUT"
res["ChangeVector"] = d.ChangeVector
return res, nil
}
func (d *PutAttachmentCommandData) getStream() io.Reader {
return d.stream
}
func (d *PutAttachmentCommandData) GetContentType() string {
return d.contentType
}