refactor(backend): switch to DDD
This commit is contained in:
@@ -52,7 +52,6 @@ type (
|
||||
Creator User `json:"creator"`
|
||||
Notes pgtype.Text `json:"notes"`
|
||||
Metadata json.RawMessage `json:"metadata"`
|
||||
Tags []TagCore `json:"tags"`
|
||||
Viewed int `json:"viewed"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package domain
|
||||
|
||||
type ErrorCode string
|
||||
|
||||
const (
|
||||
// File errors
|
||||
ErrFileNotFound ErrorCode = "FILE_NOT_FOUND"
|
||||
ErrMIMENotSupported ErrorCode = "MIME_NOT_SUPPORTEDF"
|
||||
|
||||
// Tag errors
|
||||
ErrTagNotFound ErrorCode = "TAG_NOT_FOUND"
|
||||
|
||||
// General errors
|
||||
ErrValidation ErrorCode = "VALIDATION_ERROR"
|
||||
ErrInternal ErrorCode = "INTERNAL_SERVER_ERROR"
|
||||
)
|
||||
|
||||
type DomainError struct {
|
||||
Err error `json:"-"`
|
||||
Code ErrorCode `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Details []any `json:"-"`
|
||||
}
|
||||
|
||||
func (e *DomainError) Error() string {
|
||||
if e.Err != nil {
|
||||
return e.Message + ": " + e.Err.Error()
|
||||
}
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func NewDomainError(err error, code ErrorCode, details ...any) *DomainError {
|
||||
return &DomainError{
|
||||
Err: err,
|
||||
Code: code,
|
||||
Details: details,
|
||||
}
|
||||
}
|
||||
|
||||
func NewUnexpectedError(err error) *DomainError {
|
||||
return &DomainError{
|
||||
Err: err,
|
||||
Code: ErrInternal,
|
||||
Message: "An unexpected error occured",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FileRepository interface {
|
||||
GetAccess(ctx context.Context, user_id int, file_id string) (canView, canEdit bool, domainErr *DomainError)
|
||||
GetSlice(ctx context.Context, user_id int, filter, sort string, limit, offset int) (files Slice[FileItem], domainErr *DomainError)
|
||||
Get(ctx context.Context, user_id int, file_id string) (file FileFull, domainErr *DomainError)
|
||||
Add(ctx context.Context, user_id int, name, mime string, datetime time.Time, notes string, metadata json.RawMessage) (file FileCore, domainErr *DomainError)
|
||||
Update(ctx context.Context, user_id int, file_id string, updates map[string]interface{}) (domainErr *DomainError)
|
||||
Delete(ctx context.Context, user_id int, file_id string) (domainErr *DomainError)
|
||||
}
|
||||
Reference in New Issue
Block a user