From 43d7c2719cbb907d1dab923206543bfe63d0438e Mon Sep 17 00:00:00 2001 From: Andrei Lukyanchyk Date: Fri, 10 May 2024 15:12:29 +0200 Subject: [PATCH] CDI-696: add the Get method to retrieve Preset by ID --- presets/presets.go | 6 ++++++ presets/service.go | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/presets/presets.go b/presets/presets.go index 863fef9..7c9e1b9 100644 --- a/presets/presets.go +++ b/presets/presets.go @@ -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 { @@ -23,3 +24,8 @@ type AppliedPreset struct { PresetID int ObjectID int } + +type Preset struct { + ID int `json:"id"` + Name string `json:"name"` +} diff --git a/presets/service.go b/presets/service.go index a32de7d..ba3c9db 100644 --- a/presets/service.go +++ b/presets/service.go @@ -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 +}