github.com/Files-com/files-sdk-go/v3@v3.1.81/filecomment.go (about)

     1  package files_sdk
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	lib "github.com/Files-com/files-sdk-go/v3/lib"
     7  )
     8  
     9  type FileComment struct {
    10  	Id        int64    `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"`
    11  	Body      string   `json:"body,omitempty" path:"body,omitempty" url:"body,omitempty"`
    12  	Reactions []string `json:"reactions,omitempty" path:"reactions,omitempty" url:"reactions,omitempty"`
    13  	Path      string   `json:"path,omitempty" path:"path,omitempty" url:"path,omitempty"`
    14  }
    15  
    16  func (f FileComment) Identifier() interface{} {
    17  	return f.Id
    18  }
    19  
    20  type FileCommentCollection []FileComment
    21  
    22  type FileCommentListForParams struct {
    23  	Path string `url:"-,omitempty" required:"false" json:"-,omitempty" path:"path"`
    24  	ListParams
    25  }
    26  
    27  type FileCommentCreateParams struct {
    28  	Body string `url:"body,omitempty" required:"true" json:"body,omitempty" path:"body"`
    29  	Path string `url:"path,omitempty" required:"true" json:"path,omitempty" path:"path"`
    30  }
    31  
    32  type FileCommentUpdateParams struct {
    33  	Id   int64  `url:"-,omitempty" required:"false" json:"-,omitempty" path:"id"`
    34  	Body string `url:"body,omitempty" required:"true" json:"body,omitempty" path:"body"`
    35  }
    36  
    37  type FileCommentDeleteParams struct {
    38  	Id int64 `url:"-,omitempty" required:"false" json:"-,omitempty" path:"id"`
    39  }
    40  
    41  func (f *FileComment) UnmarshalJSON(data []byte) error {
    42  	type fileComment FileComment
    43  	var v fileComment
    44  	if err := json.Unmarshal(data, &v); err != nil {
    45  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{})
    46  	}
    47  
    48  	*f = FileComment(v)
    49  	return nil
    50  }
    51  
    52  func (f *FileCommentCollection) UnmarshalJSON(data []byte) error {
    53  	type fileComments FileCommentCollection
    54  	var v fileComments
    55  	if err := json.Unmarshal(data, &v); err != nil {
    56  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{})
    57  	}
    58  
    59  	*f = FileCommentCollection(v)
    60  	return nil
    61  }
    62  
    63  func (f *FileCommentCollection) ToSlice() *[]interface{} {
    64  	ret := make([]interface{}, len(*f))
    65  	for i, v := range *f {
    66  		ret[i] = v
    67  	}
    68  
    69  	return &ret
    70  }