diff --git a/backend/internal/domain/errors.go b/backend/internal/domain/errors.go index d3ec9be..0ec6795 100644 --- a/backend/internal/domain/errors.go +++ b/backend/internal/domain/errors.go @@ -49,6 +49,17 @@ func (e *AlreadyExistsError) Error() string { func (e *AlreadyExistsError) Unwrap() error { return ErrAlreadyExists } func (e *AlreadyExistsError) Code() ErrorCode { return CodeConflict } +type IdempotencyConflictError struct { + Key string +} + +func (e *IdempotencyConflictError) Error() string { + return "Idempotency-Key " + e.Key + " уже использован с другим телом запроса" +} + +func (e *IdempotencyConflictError) Unwrap() error { return ErrAlreadyExists } +func (e *IdempotencyConflictError) Code() ErrorCode { return CodeConflict } + type ValidationError struct { Field string Message string diff --git a/backend/internal/domain/idempotency.go b/backend/internal/domain/idempotency.go new file mode 100644 index 0000000..f7616d9 --- /dev/null +++ b/backend/internal/domain/idempotency.go @@ -0,0 +1,23 @@ +package domain + +import ( + "crypto/sha256" +) + +type IdempotencyScope struct { + UserID string + Method string + Path string + Key string +} + +type CreateIdempotentResult struct { + Status int + Body []byte + Replayed bool +} + +func RequestHash(text string) []byte { + sum := sha256.Sum256([]byte(text)) + return sum[:] +}