refactor(backend): switch to DDD

This commit is contained in:
2025-10-09 00:59:30 +03:00
parent 4e0fc431e2
commit c39d82fafd
9 changed files with 461 additions and 343 deletions
+46
View File
@@ -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",
}
}