Skip to content

Commit

Permalink
feat (SRI-03) : add logic removing prev cache before update/delete sh…
Browse files Browse the repository at this point in the history
…ort url operation
  • Loading branch information
PickHD committed Jul 3, 2023
1 parent 14d148f commit e2cc53d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions shortener/internal/v1/service/short.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ func (ss *ShortServiceImpl) UpdateShort(ctx context.Context, req *model.UpdateSh
return model.NewError(model.Validation, err.Error())
}

data, err := ss.ShortRepo.GetByID(ctx, req.ID)
if err != nil {
return err
}

// delete cache if any
err = ss.ShortRepo.DeleteFullURLByKey(ctx, data.ShortURL)
if err != nil {
return err
}

return ss.ShortRepo.UpdateFullURLByID(ctx, req)
}

Expand All @@ -162,6 +173,17 @@ func (ss *ShortServiceImpl) DeleteShort(ctx context.Context, req *model.DeleteSh
ctx, span := tr.Start(ctx, "Start DeleteShort")
defer span.End()

data, err := ss.ShortRepo.GetByID(ctx, req.ID)
if err != nil {
return err
}

// delete cache if any
err = ss.ShortRepo.DeleteFullURLByKey(ctx, data.ShortURL)
if err != nil {
return err
}

return ss.ShortRepo.DeleteByID(ctx, req)
}

Expand Down

0 comments on commit e2cc53d

Please sign in to comment.