github.com/altipla-consulting/ravendb-go-client@v0.1.3/delete_attachment_operation.go (about) 1 package ravendb 2 3 import ( 4 "net/http" 5 ) 6 7 var ( 8 _ IOperation = &DeleteAttachmentOperation{} 9 ) 10 11 type DeleteAttachmentOperation struct { 12 Command *DeleteAttachmentCommand 13 14 _documentID string 15 _name string 16 _changeVector *string 17 } 18 19 func NewDeleteAttachmentOperation(documentID string, name string, changeVector *string) *DeleteAttachmentOperation { 20 return &DeleteAttachmentOperation{ 21 _documentID: documentID, 22 _name: name, 23 _changeVector: changeVector, 24 } 25 } 26 27 func (o *DeleteAttachmentOperation) GetCommand(store *DocumentStore, conventions *DocumentConventions, cache *httpCache) (RavenCommand, error) { 28 var err error 29 o.Command, err = NewDeleteAttachmentCommand(o._documentID, o._name, o._changeVector) 30 return o.Command, err 31 } 32 33 var _ RavenCommand = &DeleteAttachmentCommand{} 34 35 type DeleteAttachmentCommand struct { 36 RavenCommandBase 37 38 _documentID string 39 _name string 40 _changeVector *string 41 } 42 43 func NewDeleteAttachmentCommand(documentID string, name string, changeVector *string) (*DeleteAttachmentCommand, error) { 44 if stringIsBlank(documentID) { 45 return nil, newIllegalArgumentError("documentId cannot be null") 46 } 47 48 if stringIsBlank(name) { 49 return nil, newIllegalArgumentError("name cannot be null") 50 } 51 52 cmd := &DeleteAttachmentCommand{ 53 RavenCommandBase: NewRavenCommandBase(), 54 _documentID: documentID, 55 _name: name, 56 _changeVector: changeVector, 57 } 58 cmd.RavenCommandBase.ResponseType = RavenCommandResponseTypeEmpty 59 return cmd, nil 60 } 61 62 func (c *DeleteAttachmentCommand) createRequest(node *ServerNode) (*http.Request, error) { 63 url := node.URL + "/databases/" + node.Database + "/attachments?id=" + urlUtilsEscapeDataString(c._documentID) + "&name=" + urlUtilsEscapeDataString(c._name) 64 65 request, err := newHttpDelete(url, nil) 66 if err != nil { 67 return nil, err 68 } 69 addChangeVectorIfNotNull(c._changeVector, request) 70 return request, err 71 }