Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the removing while fetching #2

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/adapters/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ var (
ErrValueDoesntExist = errors.New("value doesn't exists in the db")
ErrFetchValue = errors.New("failed to fetch data from db")
ErrDeserializeData = errors.New("failed to deserialize data")
ErrRemove = errors.New("failed to delete the data")
)
12 changes: 11 additions & 1 deletion src/adapters/redis/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type repository struct {
client *redis.Client
}


func NewRepository(client *redis.Client) ports.Repository {
return &repository{
client: client,
Expand Down Expand Up @@ -49,10 +50,19 @@ func (r *repository) GetData(ctx context.Context, id uuid.UUID) (*domain.Data, e
if err != nil {
log.Error(err.Error())
if err == redis.Nil {
return nil,ErrValueDoesntExist
return nil, ErrValueDoesntExist
}
return nil, ErrFetchValue
}

return &data, nil
}

func (r *repository) RemoveData(ctx context.Context, id uuid.UUID) error {
err := r.client.Del(ctx,id.String()).Err()
if err != nil {
log.Error(err.Error())
return ErrRemove
}
return nil
}
1 change: 1 addition & 0 deletions src/core/ports/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import (
type Repository interface {
AddData(ctx context.Context, id uuid.UUID, data domain.Data) error
GetData(ctx context.Context, id uuid.UUID) (*domain.Data, error)
RemoveData(ctx context.Context, id uuid.UUID) error
}
8 changes: 7 additions & 1 deletion src/core/service/pbin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ func (s *service) GetContent(ctx context.Context, dataRequest *domain.DataReques
log.Error(err.Error())
return nil, ErrDecrypting
}
// 4. return the content
// 4. remove the data from the db
err = s.repository.RemoveData(ctx,dataRequest.Id)
if err != nil {
log.Error(err.Error())
}

// 5. return the content
content := domain.Content(string(plainText))
return &content, nil
}