From 89422726bfc17b7b5a9603df03ebad048be556b9 Mon Sep 17 00:00:00 2001 From: Jean Jacques Avril Date: Sat, 4 Jan 2025 11:16:46 +0000 Subject: [PATCH] migrated to fp-go curry function --- .../internal/application/repository/helper.go | 14 -------------- .../repository/project_repository_impl.go | 14 ++++++++------ .../repository/project_task_repository_impl.go | 13 +++++++------ .../repository/time_entry_repository_impl.go | 15 ++++++++------- .../repository/user_repository_impl.go | 13 +++++++------ 5 files changed, 30 insertions(+), 39 deletions(-) delete mode 100644 backend-go/internal/application/repository/helper.go diff --git a/backend-go/internal/application/repository/helper.go b/backend-go/internal/application/repository/helper.go deleted file mode 100644 index 4fe8780..0000000 --- a/backend-go/internal/application/repository/helper.go +++ /dev/null @@ -1,14 +0,0 @@ -package repository - -import ( - "context" - - E "github.com/IBM/fp-go/either" -) - -// curried is a helper function to simplify currying by taking a context and returning a function. -func curried[T any, R any](ctx context.Context, fn func(context.Context, T) E.Either[error, R]) func(T) E.Either[error, R] { - return func(input T) E.Either[error, R] { - return fn(ctx, input) - } -} diff --git a/backend-go/internal/application/repository/project_repository_impl.go b/backend-go/internal/application/repository/project_repository_impl.go index aaad895..3ec1f81 100644 --- a/backend-go/internal/application/repository/project_repository_impl.go +++ b/backend-go/internal/application/repository/project_repository_impl.go @@ -7,6 +7,8 @@ import ( "context" E "github.com/IBM/fp-go/either" + F "github.com/IBM/fp-go/function" + ) // ProjectRepositoryImpl implements the ProjectRepository interface. @@ -21,30 +23,30 @@ func NewProjectRepository(dataSource data.ProjectDataSource) repository.ProjectR // Create delegates the creation of a project to the data source. func (r *ProjectRepositoryImpl) Create(ctx context.Context) func(project entities.ProjectCreate) E.Either[error, entities.Project] { - return curried(ctx, r.dataSource.Create) + return F.Curry2(r.dataSource.Create)(ctx) } // FindByID delegates fetching a project by ID to the data source. func (r *ProjectRepositoryImpl) FindByID(ctx context.Context) func(id string) E.Either[error, entities.Project] { - return curried(ctx, r.dataSource.FindByID) + return F.Curry2(r.dataSource.FindByID)(ctx) } // FindByUserID delegates fetching projects by user ID to the data source. func (r *ProjectRepositoryImpl) FindByUserID(ctx context.Context) func(userID string) E.Either[error, []entities.Project] { - return curried(ctx, r.dataSource.FindByUserID) + return F.Curry2(r.dataSource.FindByUserID)(ctx) } // Update delegates updating a project to the data source. func (r *ProjectRepositoryImpl) Update(ctx context.Context) func(project entities.ProjectUpdate) E.Either[error, entities.Project] { - return curried(ctx, r.dataSource.Update) + return F.Curry2(r.dataSource.Update)(ctx) } // Delete delegates deleting a project to the data source. func (r *ProjectRepositoryImpl) Delete(ctx context.Context) func(id string) E.Either[error, entities.Project] { - return curried(ctx, r.dataSource.Delete) + return F.Curry2(r.dataSource.Delete)(ctx) } // FindAll delegates fetching all projects to the data source. func (r *ProjectRepositoryImpl) FindAll(ctx context.Context) E.Either[error, []entities.Project] { - return r.dataSource.FindAll(ctx) + return F.Curry1(r.dataSource.FindAll)(ctx) } diff --git a/backend-go/internal/application/repository/project_task_repository_impl.go b/backend-go/internal/application/repository/project_task_repository_impl.go index 8637980..4aeb520 100644 --- a/backend-go/internal/application/repository/project_task_repository_impl.go +++ b/backend-go/internal/application/repository/project_task_repository_impl.go @@ -7,6 +7,7 @@ import ( "context" E "github.com/IBM/fp-go/either" + F "github.com/IBM/fp-go/function" ) // ProjectTaskRepositoryImpl implements the ProjectTaskRepository interface. @@ -21,30 +22,30 @@ func NewProjectTaskRepository(dataSource data.ProjectTaskDataSource) repository. // Create delegates the creation of a project task to the data source. func (r *ProjectTaskRepositoryImpl) Create(ctx context.Context) func(task entities.ProjectTaskCreate) E.Either[error, entities.ProjectTask] { - return curried(ctx, r.dataSource.Create) + return F.Curry2(r.dataSource.Create)(ctx) } // FindByID delegates fetching a project task by ID to the data source. func (r *ProjectTaskRepositoryImpl) FindByID(ctx context.Context) func(id string) E.Either[error, entities.ProjectTask] { - return curried(ctx, r.dataSource.FindByID) + return F.Curry2(r.dataSource.FindByID)(ctx) } // FindByProjectID delegates fetching project tasks by project ID to the data source. func (r *ProjectTaskRepositoryImpl) FindByProjectID(ctx context.Context) func(projectID string) E.Either[error, []entities.ProjectTask] { - return curried(ctx, r.dataSource.FindByProjectID) + return F.Curry2(r.dataSource.FindByProjectID)(ctx) } // Update delegates updating a project task to the data source. func (r *ProjectTaskRepositoryImpl) Update(ctx context.Context) func(task entities.ProjectTaskUpdate) E.Either[error, entities.ProjectTask] { - return curried(ctx, r.dataSource.Update) + return F.Curry2(r.dataSource.Update)(ctx) } // Delete delegates deleting a project task to the data source. func (r *ProjectTaskRepositoryImpl) Delete(ctx context.Context) func(id string) E.Either[error, entities.ProjectTask] { - return curried(ctx, r.dataSource.Delete) + return F.Curry2(r.dataSource.Delete)(ctx) } // FindAll delegates fetching all project tasks to the data source. func (r *ProjectTaskRepositoryImpl) FindAll(ctx context.Context) E.Either[error, []entities.ProjectTask] { - return r.dataSource.FindAll(ctx) + return F.Curry1(r.dataSource.FindAll)(ctx) } diff --git a/backend-go/internal/application/repository/time_entry_repository_impl.go b/backend-go/internal/application/repository/time_entry_repository_impl.go index e6857a9..4f65335 100644 --- a/backend-go/internal/application/repository/time_entry_repository_impl.go +++ b/backend-go/internal/application/repository/time_entry_repository_impl.go @@ -7,6 +7,7 @@ import ( "context" E "github.com/IBM/fp-go/either" + F "github.com/IBM/fp-go/function" ) // TimeEntryRepositoryImpl implements the TimeEntryRepository interface. @@ -21,35 +22,35 @@ func NewTimeEntryRepository(dataSource data.TimeEntryDataSource) repository.Time // Create delegates the creation of a TimeEntry to the data source. func (r *TimeEntryRepositoryImpl) Create(ctx context.Context) func(entry entities.TimeEntryCreate) E.Either[error, entities.TimeEntry] { - return curried(ctx, r.dataSource.Create) + return F.Curry2(r.dataSource.Create)(ctx) } // FindByID delegates fetching a TimeEntry by ID to the data source. func (r *TimeEntryRepositoryImpl) FindByID(ctx context.Context) func(id string) E.Either[error, entities.TimeEntry] { - return curried(ctx, r.dataSource.FindByID) + return F.Curry2(r.dataSource.FindByID)(ctx) } // FindByUserID delegates fetching TimeEntries by UserID to the data source. func (r *TimeEntryRepositoryImpl) FindByUserID(ctx context.Context) func(userID string) E.Either[error, []entities.TimeEntry] { - return curried(ctx, r.dataSource.FindByUserID) + return F.Curry2(r.dataSource.FindByUserID)(ctx) } // FindByProjectID delegates fetching TimeEntries by ProjectID to the data source. func (r *TimeEntryRepositoryImpl) FindByProjectID(ctx context.Context) func(projectID string) E.Either[error, []entities.TimeEntry] { - return curried(ctx, r.dataSource.FindByProjectID) + return F.Curry2(r.dataSource.FindByProjectID)(ctx) } // Update delegates updating a TimeEntry to the data source. func (r *TimeEntryRepositoryImpl) Update(ctx context.Context) func(entry entities.TimeEntryUpdate) E.Either[error, entities.TimeEntry] { - return curried(ctx, r.dataSource.Update) + return F.Curry2(r.dataSource.Update)(ctx) } // Delete delegates deleting a TimeEntry to the data source. func (r *TimeEntryRepositoryImpl) Delete(ctx context.Context) func(id string) E.Either[error, entities.TimeEntry] { - return curried(ctx, r.dataSource.Delete) + return F.Curry2(r.dataSource.Delete)(ctx) } // FindAll delegates fetching all TimeEntries to the data source. func (r *TimeEntryRepositoryImpl) FindAll(ctx context.Context) E.Either[error, []entities.TimeEntry] { - return r.dataSource.FindAll(ctx) + return F.Curry1(r.dataSource.FindAll)(ctx) } diff --git a/backend-go/internal/application/repository/user_repository_impl.go b/backend-go/internal/application/repository/user_repository_impl.go index 68b381e..9f96b0d 100644 --- a/backend-go/internal/application/repository/user_repository_impl.go +++ b/backend-go/internal/application/repository/user_repository_impl.go @@ -7,6 +7,7 @@ import ( "context" E "github.com/IBM/fp-go/either" + F "github.com/IBM/fp-go/function" ) // UserRepositoryImpl implements the UserRepository interface. @@ -21,30 +22,30 @@ func NewUserRepository(dataSource data.UserDataSource) repository.UserRepository // Create delegates the creation of a user to the data source. func (r *UserRepositoryImpl) Create(ctx context.Context) func(user entities.UserCreate) E.Either[error, entities.User] { - return curried(ctx, r.dataSource.Create) + return F.Curry2(r.dataSource.Create)(ctx) } // FindByID delegates fetching a user by ID to the data source. func (r *UserRepositoryImpl) FindByID(ctx context.Context) func(id string) E.Either[error, entities.User] { - return curried(ctx, r.dataSource.FindByID) + return F.Curry2(r.dataSource.FindByID)(ctx) } // FindByEmail delegates fetching a user by email to the data source. func (r *UserRepositoryImpl) FindByEmail(ctx context.Context) func(email string) E.Either[error, entities.User] { - return curried(ctx, r.dataSource.FindByEmail) + return F.Curry2(r.dataSource.FindByEmail)(ctx) } // Update delegates updating a user to the data source. func (r *UserRepositoryImpl) Update(ctx context.Context) func(user entities.UserUpdate) E.Either[error, entities.User] { - return curried(ctx, r.dataSource.Update) + return F.Curry2(r.dataSource.Update)(ctx) } // Delete delegates deleting a user to the data source. func (r *UserRepositoryImpl) Delete(ctx context.Context) func(id string) E.Either[error, entities.User] { - return curried(ctx, r.dataSource.Delete) + return F.Curry2(r.dataSource.Delete)(ctx) } // FindAll delegates fetching all users to the data source. func (r *UserRepositoryImpl) FindAll(ctx context.Context) E.Either[error, []entities.User] { - return r.dataSource.FindAll(ctx) + return F.Curry1(r.dataSource.FindAll)(ctx) }