feat: go - added repositories for buisness logic

This commit is contained in:
2025-01-02 13:56:46 +00:00
parent 615e749a12
commit 5d836ac199
10 changed files with 246 additions and 28 deletions
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}