feat: go - added repositories for buisness logic
This commit is contained in:
parent
615e749a12
commit
5d836ac199
10
README.md
10
README.md
@ -61,7 +61,9 @@ structured into well-defined layers with separation of concerns.
|
|||||||
|
|
||||||
#### Requirements
|
#### Requirements
|
||||||
|
|
||||||
- PNPM: npm install -g pnpm
|
- Docker
|
||||||
|
- (WSL on Windows)
|
||||||
|
|
||||||
|
|
||||||
# Run Software
|
# 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
|
you can also install the dev environment on your host system. Make sure versions
|
||||||
do match.
|
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
|
## Frontend
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd frontend-react
|
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
|
deno run dev # starts web ui on port 3000
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
}
|
@ -3,6 +3,7 @@ package data
|
|||||||
import (
|
import (
|
||||||
"actatempus_backend/internal/domain/entities"
|
"actatempus_backend/internal/domain/entities"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
E "github.com/IBM/fp-go/either"
|
E "github.com/IBM/fp-go/either"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3,14 +3,16 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"actatempus_backend/internal/domain/entities"
|
"actatempus_backend/internal/domain/entities"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
E "github.com/IBM/fp-go/either"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProjectRepository defines the operations for interacting with project data.
|
// ProjectRepository defines the operations for interacting with project data.
|
||||||
type ProjectRepository interface {
|
type ProjectRepository interface {
|
||||||
Create(ctx context.Context, project entities.Project) (entities.Project, error)
|
Create(ctx context.Context, project entities.ProjectCreate) E.Either[error,entities.Project]
|
||||||
FindByID(ctx context.Context, id string) (entities.Project, error)
|
FindByID(ctx context.Context, id string) E.Either[error,entities.Project]
|
||||||
FindByUserID(ctx context.Context, userID string) ([]entities.Project, error)
|
FindByUserID(ctx context.Context, userID string) E.Either[error,[]entities.Project]
|
||||||
Update(ctx context.Context, project entities.Project) (entities.Project, error)
|
Update(ctx context.Context, project entities.ProjectUpdate) E.Either[error,entities.Project]
|
||||||
Delete(ctx context.Context, id string) error
|
Delete(ctx context.Context, id string) E.Either[error,entities.Project]
|
||||||
FindAll(ctx context.Context) ([]entities.Project, error)
|
FindAll(ctx context.Context) E.Either[error,[]entities.Project]
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,16 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"actatempus_backend/internal/domain/entities"
|
"actatempus_backend/internal/domain/entities"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
E "github.com/IBM/fp-go/either"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProjectTaskRepository defines the operations for interacting with project task data.
|
// ProjectTaskRepository defines the operations for interacting with project task data.
|
||||||
type ProjectTaskRepository interface {
|
type ProjectTaskRepository interface {
|
||||||
Create(ctx context.Context, task entities.ProjectTask) (entities.ProjectTask, error)
|
Create(ctx context.Context, task entities.ProjectTaskCreate) E.Either[error,entities.ProjectTask]
|
||||||
FindByID(ctx context.Context, id string) (entities.ProjectTask, error)
|
FindByID(ctx context.Context, id string) E.Either[error,entities.ProjectTask]
|
||||||
FindByProjectID(ctx context.Context, projectID string) ([]entities.ProjectTask, error)
|
FindByProjectID(ctx context.Context, projectID string) E.Either[error,[]entities.ProjectTask]
|
||||||
Update(ctx context.Context, task entities.ProjectTask) (entities.ProjectTask, error)
|
Update(ctx context.Context, task entities.ProjectTaskUpdate) E.Either[error,entities.ProjectTask]
|
||||||
Delete(ctx context.Context, id string) error
|
Delete(ctx context.Context, id string) E.Either[error,entities.ProjectTask]
|
||||||
FindAll(ctx context.Context) ([]entities.ProjectTask, error)
|
FindAll(ctx context.Context) E.Either[error,[]entities.ProjectTask]
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,17 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"actatempus_backend/internal/domain/entities"
|
"actatempus_backend/internal/domain/entities"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
E "github.com/IBM/fp-go/either"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TimeEntryRepository defines the operations for interacting with time entry data.
|
// TimeEntryRepository defines the operations for interacting with time entry data.
|
||||||
type TimeEntryRepository interface {
|
type TimeEntryRepository interface {
|
||||||
Create(ctx context.Context, entry entities.TimeEntry) (entities.TimeEntry, error)
|
Create(ctx context.Context, entry entities.TimeEntryCreate) E.Either[error,entities.TimeEntry]
|
||||||
FindByID(ctx context.Context, id string) (entities.TimeEntry, error)
|
FindByID(ctx context.Context, id string) E.Either[error,entities.TimeEntry]
|
||||||
FindByUserID(ctx context.Context, userID string) ([]entities.TimeEntry, error)
|
FindByUserID(ctx context.Context, userID string) E.Either[error,[]entities.TimeEntry]
|
||||||
FindByProjectID(ctx context.Context, projectID string) ([]entities.TimeEntry, error)
|
FindByProjectID(ctx context.Context, projectID string) E.Either[error,[]entities.TimeEntry]
|
||||||
Update(ctx context.Context, entry entities.TimeEntry) (entities.TimeEntry, error)
|
Update(ctx context.Context, entry entities.TimeEntryUpdate) E.Either[error,entities.TimeEntry]
|
||||||
Delete(ctx context.Context, id string) error
|
Delete(ctx context.Context, id string) E.Either[error,entities.TimeEntry]
|
||||||
FindAll(ctx context.Context) ([]entities.TimeEntry, error)
|
FindAll(ctx context.Context) E.Either[error,[]entities.TimeEntry]
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,16 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"actatempus_backend/internal/domain/entities"
|
"actatempus_backend/internal/domain/entities"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
E "github.com/IBM/fp-go/either"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserRepository defines the operations for interacting with user data.
|
// UserRepository defines the operations for interacting with user data.
|
||||||
type UserRepository interface {
|
type UserRepository interface {
|
||||||
Create(ctx context.Context, user entities.UserCreate) (entities.User, error)
|
Create(ctx context.Context, user entities.UserCreate) E.Either[error,entities.User]
|
||||||
FindByID(ctx context.Context, id string) (entities.User, error)
|
FindByID(ctx context.Context, id string) E.Either[error,entities.User]
|
||||||
FindByEmail(ctx context.Context, email string) (entities.User, error)
|
FindByEmail(ctx context.Context, email string) E.Either[error,entities.User]
|
||||||
Update(ctx context.Context, user entities.UserUpdate) (entities.User, error)
|
Update(ctx context.Context, user entities.UserUpdate) E.Either[error,entities.User]
|
||||||
Delete(ctx context.Context, id string) error
|
Delete(ctx context.Context, id string) E.Either[error,entities.User]
|
||||||
FindAll(ctx context.Context) ([]entities.User, error)
|
FindAll(ctx context.Context) E.Either[error,[]entities.User]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user