From 5d836ac199644a7573e6502b64a38249720c5c71 Mon Sep 17 00:00:00 2001 From: Jean Jacques Avril Date: Thu, 2 Jan 2025 13:56:46 +0000 Subject: [PATCH] feat: go - added repositories for buisness logic --- README.md | 10 +++- .../repository/project_repository_impl.go | 50 +++++++++++++++++ .../project_task_repository_impl.go | 48 ++++++++++++++++ .../repository/time_entry_repository_impl.go | 55 +++++++++++++++++++ .../repository/user_repository_impl.go | 50 +++++++++++++++++ .../internal/domain/data/user_data_source.go | 3 +- .../domain/repository/project_repository.go | 14 +++-- .../repository/project_task_repository.go | 14 +++-- .../repository/time_entry_repository.go | 16 +++--- .../domain/repository/user_repository.go | 14 +++-- 10 files changed, 246 insertions(+), 28 deletions(-) create mode 100644 backend-go/internal/application/repository/project_repository_impl.go create mode 100644 backend-go/internal/application/repository/project_task_repository_impl.go create mode 100644 backend-go/internal/application/repository/time_entry_repository_impl.go create mode 100644 backend-go/internal/application/repository/user_repository_impl.go diff --git a/README.md b/README.md index bbfce25..a1f83f9 100755 --- a/README.md +++ b/README.md @@ -61,7 +61,9 @@ structured into well-defined layers with separation of concerns. #### Requirements -- PNPM: npm install -g pnpm +- Docker +- (WSL on Windows) + # Run Software @@ -69,11 +71,15 @@ You can start developing and hacking by starting the dev container. Besides that you can also install the dev environment on your host system. Make sure versions do match. +IMPORTANT: Place the repository on a unix native file system before starting the devcontainer. Otherwise you will experience severe performance issues. +On Windows I recommend pulling the git repository on a wsl instance. (e.g. Ubuntu) +Then navigate inside the folder and run ```code .``` to launch visual studio code. Visual Studio code then asks you if the devcointainer should be launched. + ## Frontend ```bash cd frontend-react -deno install # devcontainer does this for you +#deno install # devcontainer does this for you deno run dev # starts web ui on port 3000 ``` diff --git a/backend-go/internal/application/repository/project_repository_impl.go b/backend-go/internal/application/repository/project_repository_impl.go new file mode 100644 index 0000000..419cfd7 --- /dev/null +++ b/backend-go/internal/application/repository/project_repository_impl.go @@ -0,0 +1,50 @@ +package repository + +import ( + "actatempus_backend/internal/domain/data" + "actatempus_backend/internal/domain/entities" + "actatempus_backend/internal/domain/repository" + "context" + + E "github.com/IBM/fp-go/either" +) + +// ProjectRepositoryImpl implements the ProjectRepository interface. +type ProjectRepositoryImpl struct { + dataSource data.ProjectDataSource +} + +// NewProjectRepository creates a new instance of ProjectRepositoryImpl. +func NewProjectRepository(dataSource data.ProjectDataSource) repository.ProjectRepository { + return &ProjectRepositoryImpl{dataSource: dataSource} +} + +// Create delegates the creation of a project to the data source. +func (r *ProjectRepositoryImpl) Create(ctx context.Context, project entities.ProjectCreate) E.Either[error, entities.Project] { + return r.dataSource.Create(ctx, project) +} + +// FindByID delegates fetching a project by ID to the data source. +func (r *ProjectRepositoryImpl) FindByID(ctx context.Context, id string) E.Either[error, entities.Project] { + return r.dataSource.FindByID(ctx, id) +} + +// FindByUserID delegates fetching all projects for a user to the data source. +func (r *ProjectRepositoryImpl) FindByUserID(ctx context.Context, userID string) E.Either[error, []entities.Project] { + return r.dataSource.FindByUserID(ctx, userID) +} + +// Update delegates updating a project to the data source. +func (r *ProjectRepositoryImpl) Update(ctx context.Context, project entities.ProjectUpdate) E.Either[error, entities.Project] { + return r.dataSource.Update(ctx, project) +} + +// Delete delegates deleting a project to the data source. +func (r *ProjectRepositoryImpl) Delete(ctx context.Context, id string) E.Either[error, entities.Project] { + return r.dataSource.Delete(ctx, id) +} + +// 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) +} diff --git a/backend-go/internal/application/repository/project_task_repository_impl.go b/backend-go/internal/application/repository/project_task_repository_impl.go new file mode 100644 index 0000000..a100352 --- /dev/null +++ b/backend-go/internal/application/repository/project_task_repository_impl.go @@ -0,0 +1,48 @@ +package repository + +import ( + "actatempus_backend/internal/domain/data" + "actatempus_backend/internal/domain/entities" + "actatempus_backend/internal/domain/repository" + "context" + + E "github.com/IBM/fp-go/either" +) + +// ProjectTaskRepositoryImpl implements the ProjectTaskRepository interface. +type ProjectTaskRepositoryImpl struct { + dataSource data.ProjectTaskDataSource +} +// NewProjectTaskRepository creates a new instance of ProjectTaskRepositoryImpl. +func NewProjectTaskRepository(dataSource data.ProjectTaskDataSource) repository.ProjectTaskRepository { + return &ProjectTaskRepositoryImpl{dataSource: dataSource} +} +// FindByProjectID implements repository.ProjectTaskRepository. +func (r *ProjectTaskRepositoryImpl) FindByProjectID(ctx context.Context, projectID string) E.Either[error, []entities.ProjectTask] { + return r.dataSource.FindByProjectID(ctx, projectID) +} + +// Create delegates the creation of a project task to the data source. +func (r *ProjectTaskRepositoryImpl) Create(ctx context.Context, task entities.ProjectTaskCreate) E.Either[error, entities.ProjectTask] { + return r.dataSource.Create(ctx, task) +} + +// FindByID delegates fetching a project task by ID to the data source. +func (r *ProjectTaskRepositoryImpl) FindByID(ctx context.Context, id string) E.Either[error, entities.ProjectTask] { + return r.dataSource.FindByID(ctx, id) +} + +// Update delegates updating a project task to the data source. +func (r *ProjectTaskRepositoryImpl) Update(ctx context.Context, task entities.ProjectTaskUpdate) E.Either[error, entities.ProjectTask] { + return r.dataSource.Update(ctx, task) +} + +// Delete delegates deleting a project task to the data source. +func (r *ProjectTaskRepositoryImpl) Delete(ctx context.Context, id string) E.Either[error, entities.ProjectTask] { + return r.dataSource.Delete(ctx, id) +} + +// 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) +} diff --git a/backend-go/internal/application/repository/time_entry_repository_impl.go b/backend-go/internal/application/repository/time_entry_repository_impl.go new file mode 100644 index 0000000..ea74f03 --- /dev/null +++ b/backend-go/internal/application/repository/time_entry_repository_impl.go @@ -0,0 +1,55 @@ +package repository + +import ( + "actatempus_backend/internal/domain/data" + "actatempus_backend/internal/domain/entities" + "actatempus_backend/internal/domain/repository" + "context" + + E "github.com/IBM/fp-go/either" +) + +// TimeEntryRepositoryImpl implements the TimeEntryRepository interface. +type TimeEntryRepositoryImpl struct { + dataSource data.TimeEntryDataSource +} + +// NewTimeEntryRepository creates a new instance of TimeEntryRepositoryImpl. +func NewTimeEntryRepository(dataSource data.TimeEntryDataSource) repository.TimeEntryRepository { + return &TimeEntryRepositoryImpl{dataSource: dataSource} +} + +// FindByProjectID implements repository.TimeEntryRepository. +func (r *TimeEntryRepositoryImpl) FindByProjectID(ctx context.Context, projectID string) E.Either[error, []entities.TimeEntry] { + return r.dataSource.FindByProjectID(ctx, projectID) +} + +// FindByUserID implements repository.TimeEntryRepository. +func (r *TimeEntryRepositoryImpl) FindByUserID(ctx context.Context, userID string) E.Either[error, []entities.TimeEntry] { + return r.dataSource.FindByUserID(ctx, userID) +} + +// Create delegates the creation of a time entry to the data source. +func (r *TimeEntryRepositoryImpl) Create(ctx context.Context, entry entities.TimeEntryCreate) E.Either[error, entities.TimeEntry] { + return r.dataSource.Create(ctx, entry) +} + +// FindByID delegates fetching a time entry by ID to the data source. +func (r *TimeEntryRepositoryImpl) FindByID(ctx context.Context, id string) E.Either[error, entities.TimeEntry] { + return r.dataSource.FindByID(ctx, id) +} + +// Update delegates updating a time entry to the data source. +func (r *TimeEntryRepositoryImpl) Update(ctx context.Context, entry entities.TimeEntryUpdate) E.Either[error, entities.TimeEntry] { + return r.dataSource.Update(ctx, entry) +} + +// Delete delegates deleting a time entry to the data source. +func (r *TimeEntryRepositoryImpl) Delete(ctx context.Context, id string) E.Either[error, entities.TimeEntry] { + return r.dataSource.Delete(ctx, id) +} + +// FindAll delegates fetching all time entries to the data source. +func (r *TimeEntryRepositoryImpl) FindAll(ctx context.Context) E.Either[error, []entities.TimeEntry] { + return 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 new file mode 100644 index 0000000..9224676 --- /dev/null +++ b/backend-go/internal/application/repository/user_repository_impl.go @@ -0,0 +1,50 @@ +package repository + +import ( + "actatempus_backend/internal/domain/entities" + "actatempus_backend/internal/domain/repository" + "actatempus_backend/internal/domain/data" + "context" + + E "github.com/IBM/fp-go/either" +) + +// UserRepositoryImpl implements the UserRepository interface. +type UserRepositoryImpl struct { + dataSource data.UserDataSource +} + +// NewUserRepository creates a new instance of UserRepositoryImpl. +func NewUserRepository(dataSource data.UserDataSource) repository.UserRepository { + return &UserRepositoryImpl{dataSource: dataSource} +} + +// Create delegates the creation of a user to the data source. +func (r *UserRepositoryImpl) Create(ctx context.Context, user entities.UserCreate) E.Either[error, entities.User] { + return r.dataSource.Create(ctx, user) +} + +// FindByID delegates fetching a user by ID to the data source. +func (r *UserRepositoryImpl) FindByID(ctx context.Context, id string) E.Either[error, entities.User] { + return r.dataSource.FindByID(ctx, id) +} + +// FindByEmail delegates fetching a user by email to the data source. +func (r *UserRepositoryImpl) FindByEmail(ctx context.Context, email string) E.Either[error, entities.User] { + return r.dataSource.FindByEmail(ctx, email) +} + +// Update delegates updating a user to the data source. +func (r *UserRepositoryImpl) Update(ctx context.Context, user entities.UserUpdate) E.Either[error, entities.User] { + return r.dataSource.Update(ctx, user) +} + +// Delete delegates deleting a user to the data source. +func (r *UserRepositoryImpl) Delete(ctx context.Context, id string) E.Either[error, entities.User] { + return r.dataSource.Delete(ctx, id) +} + +// 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) +} diff --git a/backend-go/internal/domain/data/user_data_source.go b/backend-go/internal/domain/data/user_data_source.go index 3e4ddeb..bc231a4 100644 --- a/backend-go/internal/domain/data/user_data_source.go +++ b/backend-go/internal/domain/data/user_data_source.go @@ -3,7 +3,8 @@ package data import ( "actatempus_backend/internal/domain/entities" "context" - E "github.com/IBM/fp-go/either" + + E "github.com/IBM/fp-go/either" ) // UserDataSource defines the operations for interacting with user data. diff --git a/backend-go/internal/domain/repository/project_repository.go b/backend-go/internal/domain/repository/project_repository.go index b8c3880..6273a1e 100644 --- a/backend-go/internal/domain/repository/project_repository.go +++ b/backend-go/internal/domain/repository/project_repository.go @@ -3,14 +3,16 @@ package repository import ( "actatempus_backend/internal/domain/entities" "context" + + E "github.com/IBM/fp-go/either" ) // ProjectRepository defines the operations for interacting with project data. type ProjectRepository interface { - Create(ctx context.Context, project entities.Project) (entities.Project, error) - FindByID(ctx context.Context, id string) (entities.Project, error) - FindByUserID(ctx context.Context, userID string) ([]entities.Project, error) - Update(ctx context.Context, project entities.Project) (entities.Project, error) - Delete(ctx context.Context, id string) error - FindAll(ctx context.Context) ([]entities.Project, error) + Create(ctx context.Context, project entities.ProjectCreate) E.Either[error,entities.Project] + FindByID(ctx context.Context, id string) E.Either[error,entities.Project] + FindByUserID(ctx context.Context, userID string) E.Either[error,[]entities.Project] + Update(ctx context.Context, project entities.ProjectUpdate) E.Either[error,entities.Project] + Delete(ctx context.Context, id string) E.Either[error,entities.Project] + FindAll(ctx context.Context) E.Either[error,[]entities.Project] } diff --git a/backend-go/internal/domain/repository/project_task_repository.go b/backend-go/internal/domain/repository/project_task_repository.go index 9e86542..93e66ec 100644 --- a/backend-go/internal/domain/repository/project_task_repository.go +++ b/backend-go/internal/domain/repository/project_task_repository.go @@ -3,14 +3,16 @@ package repository import ( "actatempus_backend/internal/domain/entities" "context" + + E "github.com/IBM/fp-go/either" ) // ProjectTaskRepository defines the operations for interacting with project task data. type ProjectTaskRepository interface { - Create(ctx context.Context, task entities.ProjectTask) (entities.ProjectTask, error) - FindByID(ctx context.Context, id string) (entities.ProjectTask, error) - FindByProjectID(ctx context.Context, projectID string) ([]entities.ProjectTask, error) - Update(ctx context.Context, task entities.ProjectTask) (entities.ProjectTask, error) - Delete(ctx context.Context, id string) error - FindAll(ctx context.Context) ([]entities.ProjectTask, error) + Create(ctx context.Context, task entities.ProjectTaskCreate) E.Either[error,entities.ProjectTask] + FindByID(ctx context.Context, id string) E.Either[error,entities.ProjectTask] + FindByProjectID(ctx context.Context, projectID string) E.Either[error,[]entities.ProjectTask] + Update(ctx context.Context, task entities.ProjectTaskUpdate) E.Either[error,entities.ProjectTask] + Delete(ctx context.Context, id string) E.Either[error,entities.ProjectTask] + FindAll(ctx context.Context) E.Either[error,[]entities.ProjectTask] } diff --git a/backend-go/internal/domain/repository/time_entry_repository.go b/backend-go/internal/domain/repository/time_entry_repository.go index fc26971..1fe4c34 100644 --- a/backend-go/internal/domain/repository/time_entry_repository.go +++ b/backend-go/internal/domain/repository/time_entry_repository.go @@ -3,15 +3,17 @@ package repository import ( "actatempus_backend/internal/domain/entities" "context" + + E "github.com/IBM/fp-go/either" ) // TimeEntryRepository defines the operations for interacting with time entry data. type TimeEntryRepository interface { - Create(ctx context.Context, entry entities.TimeEntry) (entities.TimeEntry, error) - FindByID(ctx context.Context, id string) (entities.TimeEntry, error) - FindByUserID(ctx context.Context, userID string) ([]entities.TimeEntry, error) - FindByProjectID(ctx context.Context, projectID string) ([]entities.TimeEntry, error) - Update(ctx context.Context, entry entities.TimeEntry) (entities.TimeEntry, error) - Delete(ctx context.Context, id string) error - FindAll(ctx context.Context) ([]entities.TimeEntry, error) + Create(ctx context.Context, entry entities.TimeEntryCreate) E.Either[error,entities.TimeEntry] + FindByID(ctx context.Context, id string) E.Either[error,entities.TimeEntry] + FindByUserID(ctx context.Context, userID string) E.Either[error,[]entities.TimeEntry] + FindByProjectID(ctx context.Context, projectID string) E.Either[error,[]entities.TimeEntry] + Update(ctx context.Context, entry entities.TimeEntryUpdate) E.Either[error,entities.TimeEntry] + Delete(ctx context.Context, id string) E.Either[error,entities.TimeEntry] + FindAll(ctx context.Context) E.Either[error,[]entities.TimeEntry] } diff --git a/backend-go/internal/domain/repository/user_repository.go b/backend-go/internal/domain/repository/user_repository.go index 400e222..3fdb5fd 100755 --- a/backend-go/internal/domain/repository/user_repository.go +++ b/backend-go/internal/domain/repository/user_repository.go @@ -3,14 +3,16 @@ package repository import ( "actatempus_backend/internal/domain/entities" "context" + + E "github.com/IBM/fp-go/either" ) // UserRepository defines the operations for interacting with user data. type UserRepository interface { - Create(ctx context.Context, user entities.UserCreate) (entities.User, error) - FindByID(ctx context.Context, id string) (entities.User, error) - FindByEmail(ctx context.Context, email string) (entities.User, error) - Update(ctx context.Context, user entities.UserUpdate) (entities.User, error) - Delete(ctx context.Context, id string) error - FindAll(ctx context.Context) ([]entities.User, error) + Create(ctx context.Context, user entities.UserCreate) E.Either[error,entities.User] + FindByID(ctx context.Context, id string) E.Either[error,entities.User] + FindByEmail(ctx context.Context, email string) E.Either[error,entities.User] + Update(ctx context.Context, user entities.UserUpdate) E.Either[error,entities.User] + Delete(ctx context.Context, id string) E.Either[error,entities.User] + FindAll(ctx context.Context) E.Either[error,[]entities.User] }