From 65ae23f46e5cda16decd6d399668569d655bceac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Tue, 6 Oct 2026 21:38:09 +0300 Subject: [PATCH] feat(domain): add idempotency scope, result and conflict error --- backend/internal/domain/errors.go | 11 +++++++++++ backend/internal/domain/idempotency.go | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 backend/internal/domain/idempotency.go 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[:] +}