Skip to content

Commit 874efaf

Browse files
authoredSep 13, 2024
feat(location): add MetafieldService to LocationService (bold-commerce#306)
1 parent 730f4f4 commit 874efaf

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed
 

‎location.go

+43-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import (
66
"time"
77
)
88

9-
const locationsBasePath = "locations"
9+
const (
10+
locationsBasePath = "locations"
11+
locationsResourceName = "locations"
12+
)
1013

1114
// LocationService is an interface for interfacing with the location endpoints
1215
// of the Shopify API.
@@ -18,6 +21,9 @@ type LocationService interface {
1821
Get(ctx context.Context, id uint64, options interface{}) (*Location, error)
1922
// Retrieves a count of locations
2023
Count(ctx context.Context, options interface{}) (int, error)
24+
25+
// MetafieldsService used for Location resource to communicate with Metafields resource
26+
MetafieldsService
2127
}
2228

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

109+
// ListMetafields for a Location resource.
110+
func (s *LocationServiceOp) ListMetafields(ctx context.Context, locationId uint64, options interface{}) ([]Metafield, error) {
111+
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
112+
return metafieldService.List(ctx, options)
113+
}
114+
115+
// Count metafields for a Location resource.
116+
func (s *LocationServiceOp) CountMetafields(ctx context.Context, locationId uint64, options interface{}) (int, error) {
117+
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
118+
return metafieldService.Count(ctx, options)
119+
}
120+
121+
// GetMetafield for a Location resource.
122+
func (s *LocationServiceOp) GetMetafield(ctx context.Context, locationId uint64, metafieldId uint64, options interface{}) (*Metafield, error) {
123+
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
124+
return metafieldService.Get(ctx, metafieldId, options)
125+
}
126+
127+
// CreateMetafield for a Location resource.
128+
func (s *LocationServiceOp) CreateMetafield(ctx context.Context, locationId uint64, metafield Metafield) (*Metafield, error) {
129+
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
130+
return metafieldService.Create(ctx, metafield)
131+
}
132+
133+
// UpdateMetafield for a Location resource.
134+
func (s *LocationServiceOp) UpdateMetafield(ctx context.Context, locationId uint64, metafield Metafield) (*Metafield, error) {
135+
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
136+
return metafieldService.Update(ctx, metafield)
137+
}
138+
139+
// DeleteMetafield for a Location resource.
140+
func (s *LocationServiceOp) DeleteMetafield(ctx context.Context, locationId uint64, metafieldId uint64) error {
141+
metafieldService := &MetafieldServiceOp{client: s.client, resource: locationsResourceName, resourceId: locationId}
142+
return metafieldService.Delete(ctx, metafieldId)
143+
}
144+
103145
// Represents the result from the locations/X.json endpoint
104146
type LocationResource struct {
105147
Location *Location `json:"location"`

0 commit comments

Comments
 (0)
Please sign in to comment.