migrated to fp-go curry function
This commit is contained in:
parent
bded64757a
commit
89422726bf
@ -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)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user