Skip to content

Commit

Permalink
feat(location): add MetafieldService to LocationService (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
ar3s3ru authored Sep 13, 2024
1 parent 730f4f4 commit 874efaf
Showing 1 changed file with 43 additions and 1 deletion.
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

0 comments on commit 874efaf

Please sign in to comment.