-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,066 additions
and
882 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Package domain contains common values used accross the whole domain implementation. | ||
package domain | ||
|
||
import "errors" | ||
|
||
var ( | ||
// ErrNotFound is a sentinel error value returned when an entity is not found. | ||
ErrNotFound = errors.New("not found") | ||
|
||
// ErrForbidden is a sentinel error value returned when an operation is forbidden. | ||
ErrForbidden = errors.New("forbidden") | ||
|
||
// ErrInvalidCharacter is a sentinel error value returned when an operation targets a character and that | ||
// character does not exist or is otherwise invalid. | ||
ErrInvalidCharacter = errors.New("invlid character") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Package repository defines the port interface for a session repository to | ||
// abstract persistence access for a session. | ||
package repository | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/halimath/fate-core-remote-table/backend/internal/domain/session" | ||
) | ||
|
||
// NoSave is a sentinel value returned to signal, that a repository must not be | ||
// saved in the datastore. | ||
var NoSave = errors.New("no save") | ||
|
||
// UnitOfWork defines a function type that defines the interface for callback | ||
// functions that perform some atomic unit of work on a [session.Session]. | ||
// ctx is used to define deadlines and additional context values. exists signals | ||
// whether the s exists in the datastore. s contains the current values for the | ||
// session. | ||
// | ||
// The function returns a session.Session to update the datastore with if the | ||
// returned error is nil. If the error is the sentinal value NoSave, then no | ||
// insert/update is exectued and the returned session is ignored. Any other | ||
// non-nil error value causes no update and is propagated to any caller. | ||
type UnitOfWork func(ctx context.Context, exists bool, s session.Session) (session.Session, error) | ||
|
||
// Port defines the port interface for repository implementations | ||
// managing a session. | ||
type Port interface { | ||
// Perform executes uow. It first tries to load the session.Session identified | ||
// by id and passes that information to uow. It returns an error returned | ||
// from uow or from the underlying datastore. | ||
Perform(ctx context.Context, id string, uow UnitOfWork) error | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/internal/domain/ports/repository/repositorymock/repositorymock.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package repositorymock | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/halimath/fate-core-remote-table/backend/internal/domain/ports/repository" | ||
"github.com/halimath/fate-core-remote-table/backend/internal/domain/session" | ||
) | ||
|
||
type Mock struct { | ||
S session.Session | ||
} | ||
|
||
func (r *Mock) Perform(ctx context.Context, id string, uow repository.UnitOfWork) error { | ||
s, err := uow(ctx, r.S.ID == id, r.S) | ||
if errors.Is(err, repository.NoSave) { | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
r.S = s | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.