Navigation Menu

Skip to content

Commit

Permalink
refactor: extract ReportIdempotency constants
Browse files Browse the repository at this point in the history
  • Loading branch information
GalvinGao committed Aug 15, 2022
1 parent 313cb0a commit 9d8137e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/constant/report.go
@@ -1,5 +1,7 @@
package constant

import "time"

const (
FurnitureArkItemID = "furni"

Expand All @@ -20,6 +22,9 @@ const (

ViolationReliabilityRejectRuleRangeLeast = 1 << 8
ViolationReliabilityRejectRuleRangeMost = 1 << 10

ReportIdempotencyLifetime = time.Hour * 24
ReportIdempotencyRedisHashKey = "report-idempotency"
)

// DropTypeMap maps an API drop type to a database drop type.
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/v2/report.go
Expand Up @@ -3,7 +3,6 @@ package v2
import (
"encoding/json"
"strings"
"time"

"github.com/go-redis/redis/v8"
"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -32,7 +31,7 @@ type Report struct {

func RegisterReport(v2 *svr.V2, c Report) {
v2.Post("/report", middlewares.Idempotency(&middlewares.IdempotencyConfig{
Lifetime: time.Hour * 24,
Lifetime: constant.ReportIdempotencyLifetime,
KeyHeader: constant.IdempotencyKeyHeader,
KeepResponseHeaders: []string{
fiber.HeaderContentType,
Expand All @@ -41,7 +40,7 @@ func RegisterReport(v2 *svr.V2, c Report) {
constant.PenguinIDSetHeader,
constant.ShimCompatibilityHeaderKey,
},
Storage: fiberstore.NewRedis(c.Redis, "report-idempotency"),
Storage: fiberstore.NewRedis(c.Redis, constant.ReportIdempotencyRedisHashKey),
}), c.SingularReport)
v2.Post("/report/recall", c.RecallSingularReport)
v2.Post("/report/recognition", c.RecognitionReport)
Expand Down

0 comments on commit 9d8137e

Please sign in to comment.