feat(api-key): 增加 API Key 上次使用时间并补齐测试
This commit is contained in:
@@ -83,6 +83,7 @@ func TestAPIContracts(t *testing.T) {
|
||||
"status": "active",
|
||||
"ip_whitelist": null,
|
||||
"ip_blacklist": null,
|
||||
"last_used_at": null,
|
||||
"quota": 0,
|
||||
"quota_used": 0,
|
||||
"expires_at": null,
|
||||
@@ -122,6 +123,7 @@ func TestAPIContracts(t *testing.T) {
|
||||
"status": "active",
|
||||
"ip_whitelist": null,
|
||||
"ip_blacklist": null,
|
||||
"last_used_at": null,
|
||||
"quota": 0,
|
||||
"quota_used": 0,
|
||||
"expires_at": null,
|
||||
@@ -1471,6 +1473,20 @@ func (r *stubApiKeyRepo) IncrementQuotaUsed(ctx context.Context, id int64, amoun
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (r *stubApiKeyRepo) UpdateLastUsed(ctx context.Context, id int64, usedAt time.Time) error {
|
||||
key, ok := r.byID[id]
|
||||
if !ok {
|
||||
return service.ErrAPIKeyNotFound
|
||||
}
|
||||
ts := usedAt
|
||||
key.LastUsedAt = &ts
|
||||
key.UpdatedAt = usedAt
|
||||
clone := *key
|
||||
r.byID[id] = &clone
|
||||
r.byKey[clone.Key] = &clone
|
||||
return nil
|
||||
}
|
||||
|
||||
type stubUsageLogRepo struct {
|
||||
userLogs map[int64][]service.UsageLog
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user