Skip to content

Commit

Permalink
CDI-696: add the Get method to retrieve Preset by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-lukyanchyk committed May 10, 2024
1 parent 3cdf8fe commit 43d7c27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions presets/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type PresetsService interface {
Apply(ctx context.Context, presetID int, req *ApplyRequest) (*AppliedPreset, error)
GetAppliedPreset(ctx context.Context, presetID, objectID int) (*AppliedPreset, error)
Unapply(ctx context.Context, presetID, objectID int) error
Get(ctx context.Context, presetID int) (*Preset, error)
}

type ApplyRequest struct {
Expand All @@ -23,3 +24,8 @@ type AppliedPreset struct {
PresetID int
ObjectID int
}

type Preset struct {
ID int `json:"id"`
Name string `json:"name"`
}
11 changes: 11 additions & 0 deletions presets/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ func (s *Service) Unapply(ctx context.Context, presetID, objectID int) error {

return nil
}

func (s *Service) Get(ctx context.Context, presetID int) (*Preset, error) {
path := fmt.Sprintf("/cdn/presets/%d", presetID)
var preset Preset

if err := s.r.Request(ctx, http.MethodGet, path, nil, &preset); err != nil {
return nil, fmt.Errorf("unable to retrieve preset with id=%d. Make sure the ID provided is correct. Details: %w", presetID, err)
}

return &preset, nil
}

0 comments on commit 43d7c27

Please sign in to comment.