Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
fix(pkg): pointer and method fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineDao committed Oct 5, 2019
1 parent 282ec86 commit c26bd58
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 45 deletions.
21 changes: 2 additions & 19 deletions pkg/apiClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const apiClientBasePath = "clients"

// APIClient is the request response when fetching apiClients
type APIClient struct {
Metadata Metadata
Metadata
Role string `json:"role,omitempty"`
DocumentName string `json:"documentName,omitempty"`
DocumentType string `json:"documentType,omitempty"`
Expand All @@ -22,7 +22,7 @@ type APIClient struct {

// APIClientRequest is the request payload used to create and update apiClients
type APIClientRequest struct {
Metadata *RequestMetadata
RequestMetadata
Role string `json:"role,omitempty"`
DocumentName string `json:"documentName,omitempty"`
DocumentType string `json:"documentType,omitempty"`
Expand Down Expand Up @@ -134,20 +134,3 @@ func (s *APIClientService) CreateComment(ctx context.Context, id string, new Com

return resource, resp, nil
}

// GetComments will get comments for a specific APIClient indexed by ID.
func (s *APIClientService) GetComments(ctx context.Context, id string) ([]Comment, *http.Response, error) {
resource := new([]Comment)

req, err := s.client.NewRequest(ctx, http.MethodGet, "comments/"+apiClientBasePath+"/"+id, nil)
if err != nil {
return *resource, nil, err
}

resp, _, err := s.client.Do(ctx, req, &resource, false)
if err != nil {
return *resource, nil, err
}

return *resource, resp, nil
}
12 changes: 6 additions & 6 deletions pkg/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const objectBasePath = "objects"

// Object is the request response when fetching objects
type Object struct {
Metadata Metadata
Metadata
ApplicationID string `json:"applicationId,omitempty"`
Hash string `json:"hash,omitempty"`
GeometryHash string `json:"geometryHash,omitempty"`
Expand All @@ -25,7 +25,7 @@ type Object struct {

// ObjectRequest is the request payload used to create and update objects
type ObjectRequest struct {
Metadata *RequestMetadata
RequestMetadata
ApplicationID string `json:"applicationId,omitempty"`
Hash string `json:"hash,omitempty"`
GeometryHash string `json:"geometryHash,omitempty"`
Expand All @@ -51,11 +51,11 @@ type ObjectService struct {
client *Client
}

// List retrieves a list of Objects
func (s *ObjectService) List(ctx context.Context) ([]Object, *http.Response, error) {
// Search retrieves a list of Objects
func (s *ObjectService) Search(ctx context.Context, query string, ids []string) ([]Object, *http.Response, error) {
resource := new([]Object)

req, err := s.client.NewRequest(ctx, http.MethodGet, objectBasePath, nil)
req, err := s.client.NewRequest(ctx, http.MethodPost, objectBasePath+"/getbulk?"+query, ids)
if err != nil {
return *resource, nil, err
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (s *ObjectService) GetComments(ctx context.Context, id string) ([]Comment,
return *resource, nil, err
}

resp, _, err := s.client.Do(ctx, req, &resource, false)
resp, _, err := s.client.Do(ctx, req, resource, false)
if err != nil {
return *resource, nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ProjectPermissions struct {

// Project is the request response when fetching projects
type Project struct {
Metadata Metadata
Metadata
Name string `json:"name"`
Tags []string `json:"tags,omitempty"`
Streams []string `json:"streams,omitempty"`
Expand All @@ -31,10 +31,10 @@ type ProjectStreamResponse struct {

// ProjectRequest is the request payload used to create and update projects
type ProjectRequest struct {
Metadata *RequestMetadata
Name string `json:"name"`
Tags []string `json:"tags"`
Streams []string `json:"streams"`
RequestMetadata
Name string `json:"name"`
Tags []string `json:"tags"`
Streams []string `json:"streams"`
}

// ProjectService is the service that communicates with the Projects API
Expand Down Expand Up @@ -149,7 +149,7 @@ func (s *ProjectService) GetComments(ctx context.Context, id string) ([]Comment,
return *resource, nil, err
}

resp, _, err := s.client.Do(ctx, req, &resource, false)
resp, _, err := s.client.Do(ctx, req, resource, false)
if err != nil {
return *resource, nil, err
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/resourcebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import "time"
// Metadata is the common metadata all resources (bar accounts) possess when returned
// from the Speckle Server.
type Metadata struct {
ID string `json:"_id,omitempty"`
Private bool `json:"private"`
CanRead []string `json:"canRead"`
CanWrite []string `json:"canWrite"`
Owner string `json:"owner"`
AnonymousComments bool `json:"anonymousComments"`
Comments []string `json:"comments"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Version int `json:"__v"`
ID string `json:"_id,omitempty"`
Private bool `json:"private"`
CanRead []string `json:"canRead"`
CanWrite []string `json:"canWrite"`
Owner string `json:"owner"`
AnonymousComments bool `json:"anonymousComments"`
Comments []string `json:"comments"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Version int `json:"__v"`
}

// RequestMetadata is the common metadata all resources (bar accounts) should posess
Expand Down
8 changes: 4 additions & 4 deletions pkg/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type Layer struct {

// Stream is the request response when fetching streams
type Stream struct {
*Metadata
StreamID string `json:"streamdId,omitempty"`
Metadata
StreamID string `json:"streamId,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Expand All @@ -61,7 +61,7 @@ type StreamStreamResponse struct {

// StreamRequest is the request payload used to create and update streams
type StreamRequest struct {
*RequestMetadata
RequestMetadata
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Expand Down Expand Up @@ -208,7 +208,7 @@ func (s *StreamService) GetComments(ctx context.Context, id string) ([]Comment,
return *resource, nil, err
}

resp, _, err := s.client.Do(ctx, req, &resource, false)
resp, _, err := s.client.Do(ctx, req, resource, false)
if err != nil {
return *resource, nil, err
}
Expand Down

0 comments on commit c26bd58

Please sign in to comment.