fix integration
Build and Deploy / build-and-deploy (push) Successful in 19m19s

This commit is contained in:
2026-06-04 19:52:44 +03:00
parent 5f5c5de407
commit a9c931bd71
6 changed files with 132 additions and 39 deletions
+15
View File
@@ -7,8 +7,11 @@ import (
"log"
"FamilyHub/src/domain"
"github.com/lib/pq"
)
var ErrReceiptAlreadyExists = errors.New("receipt already exists")
type ReceiptsRepository interface {
Create(ctx context.Context, receipt *domain.Receipt) (int64, error)
GetByID(ctx context.Context, id int64) (*domain.Receipt, error)
@@ -129,6 +132,9 @@ func (r *ReceiptsSQLRepository) Create(ctx context.Context, receipt *domain.Rece
err = tx.QueryRowContext(ctx, query, args...).Scan(&receiptID)
if err != nil {
if isReceiptAlreadyExistsError(err) {
return 0, ErrReceiptAlreadyExists
}
return 0, err
}
@@ -185,6 +191,15 @@ func (r *ReceiptsSQLRepository) Create(ctx context.Context, receipt *domain.Rece
return receiptID, nil
}
func isReceiptAlreadyExistsError(err error) bool {
var pqErr *pq.Error
if !errors.As(err, &pqErr) {
return false
}
return pqErr.Code == "23505" && pqErr.Constraint == "receipts_receipt_number_key"
}
func (r *ReceiptsSQLRepository) GetByID(ctx context.Context, id int64) (*domain.Receipt, error) {
var receipt domain.Receipt