Skip to content

Commit

Permalink
CDI-696: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-lukyanchyk committed May 9, 2024
1 parent 00ce521 commit acf83e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions presets/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import (
)

type PresetsService interface {
Create(ctx context.Context, presetID int64, req *CreateRequest) (*Preset, error)
Get(ctx context.Context, presetID, objectID int64) (*Preset, error)
Delete(ctx context.Context, presetID, objectID int64) error
Apply(ctx context.Context, presetID int64, req *ApplyRequest) (*AppliedPreset, error)
GetAppliedPreset(ctx context.Context, presetID, objectID int64) (*AppliedPreset, error)
Unapply(ctx context.Context, presetID, objectID int64) error
}

type CreateRequest struct {
type ApplyRequest struct {
ObjectID int `json:"object_id"`
}

type GetResponse struct {
type GetAppliedPresetResponse struct {
ObjectType *string `json:"object_type"`
ObjectIDs []int `json:"object_ids"`
}

type Preset struct {
ID int
type AppliedPreset struct {
PresetID int
ObjectID int
}
16 changes: 8 additions & 8 deletions presets/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func NewService(r gcore.Requester) *Service {
return &Service{r: r}
}

func (s *Service) Create(ctx context.Context, presetID int64, req *CreateRequest) (*Preset, error) {
preset := Preset{
ID: int(presetID),
func (s *Service) Apply(ctx context.Context, presetID int64, req *ApplyRequest) (*AppliedPreset, error) {
preset := AppliedPreset{
PresetID: int(presetID),
ObjectID: req.ObjectID,
}

Expand All @@ -32,10 +32,10 @@ func (s *Service) Create(ctx context.Context, presetID int64, req *CreateRequest
return &preset, nil
}

func (s *Service) Get(ctx context.Context, presetID, objectID int64) (*Preset, error) {
var response GetResponse
preset := Preset{
ID: int(presetID),
func (s *Service) GetAppliedPreset(ctx context.Context, presetID, objectID int64) (*AppliedPreset, error) {
var response GetAppliedPresetResponse
preset := AppliedPreset{
PresetID: int(presetID),
ObjectID: int(objectID),
}

Expand All @@ -54,7 +54,7 @@ func (s *Service) Get(ctx context.Context, presetID, objectID int64) (*Preset, e
return nil, fmt.Errorf("error: preset with id %d is not applied to the object with id %d", presetID, objectID)
}

func (s *Service) Delete(ctx context.Context, presetID, objectID int64) error {
func (s *Service) Unapply(ctx context.Context, presetID, objectID int64) error {
path := fmt.Sprintf("/cdn/presets/%d/applied/%d", presetID, objectID)

if err := s.r.Request(ctx, http.MethodDelete, path, nil, nil); err != nil {
Expand Down

0 comments on commit acf83e0

Please sign in to comment.