Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MetafieldService to LocationService #306

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion location.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
"time"
)

const locationsBasePath = "locations"
const (
locationsBasePath = "locations"
locationsResourceName = "locations"
)

// LocationService is an interface for interfacing with the location endpoints
// of the Shopify API.
Expand All @@ -18,6 +21,9 @@ type LocationService interface {
Get(ctx context.Context, id uint64, options interface{}) (*Location, error)
// Retrieves a count of locations
Count(ctx context.Context, options interface{}) (int, error)

// MetafieldsService used for Location resource to communicate with Metafields resource
MetafieldsService
}

type Location struct {
Expand Down Expand Up @@ -100,6 +106,42 @@ func (s *LocationServiceOp) Count(ctx context.Context, options interface{}) (int
return s.client.Count(ctx, path, options)
}

// ListMetafields for a Location resource.
func (s *LocationServiceOp) ListMetafields(ctx context.Context, locationId uint64, options interface{}) ([]Metafield, error) {
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
return metafieldService.List(ctx, options)
}

// Count metafields for a Location resource.
func (s *LocationServiceOp) CountMetafields(ctx context.Context, locationId uint64, options interface{}) (int, error) {
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
return metafieldService.Count(ctx, options)
}

// GetMetafield for a Location resource.
func (s *LocationServiceOp) GetMetafield(ctx context.Context, locationId uint64, metafieldId uint64, options interface{}) (*Metafield, error) {
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
return metafieldService.Get(ctx, metafieldId, options)
}

// CreateMetafield for a Location resource.
func (s *LocationServiceOp) CreateMetafield(ctx context.Context, locationId uint64, metafield Metafield) (*Metafield, error) {
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
return metafieldService.Create(ctx, metafield)
}

// UpdateMetafield for a Location resource.
func (s *LocationServiceOp) UpdateMetafield(ctx context.Context, locationId uint64, metafield Metafield) (*Metafield, error) {
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
return metafieldService.Update(ctx, metafield)
}

// DeleteMetafield for a Location resource.
func (s *LocationServiceOp) DeleteMetafield(ctx context.Context, locationId uint64, metafieldId uint64) error {
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
return metafieldService.Delete(ctx, metafieldId)
}

// Represents the result from the locations/X.json endpoint
type LocationResource struct {
Location *Location `json:"location"`
Expand Down
Loading