Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
3f92a431
"vscode:/vscode.git/clone" did not exist on "7eda43c99ee14d2972263aeee0e21e664753ae49"
Unverified
Commit
3f92a431
authored
Dec 27, 2025
by
IanShaw
Committed by
GitHub
Dec 27, 2025
Browse files
test: 完善 UsageLogRepo 测试 stub 的过滤逻辑 (#50)
parent
2101f1d1
Changes
1
Show whitespace changes
Inline
Side-by-side
backend/internal/server/api_contract_test.go
View file @
3f92a431
...
@@ -925,8 +925,38 @@ func (r *stubUsageLogRepo) GetUserModelStats(ctx context.Context, userID int64,
...
@@ -925,8 +925,38 @@ func (r *stubUsageLogRepo) GetUserModelStats(ctx context.Context, userID int64,
func
(
r
*
stubUsageLogRepo
)
ListWithFilters
(
ctx
context
.
Context
,
params
pagination
.
PaginationParams
,
filters
usagestats
.
UsageLogFilters
)
([]
service
.
UsageLog
,
*
pagination
.
PaginationResult
,
error
)
{
func
(
r
*
stubUsageLogRepo
)
ListWithFilters
(
ctx
context
.
Context
,
params
pagination
.
PaginationParams
,
filters
usagestats
.
UsageLogFilters
)
([]
service
.
UsageLog
,
*
pagination
.
PaginationResult
,
error
)
{
logs
:=
r
.
userLogs
[
filters
.
UserID
]
logs
:=
r
.
userLogs
[
filters
.
UserID
]
total
:=
int64
(
len
(
logs
))
out
:=
paginateLogs
(
logs
,
params
)
// Apply filters
var
filtered
[]
service
.
UsageLog
for
_
,
log
:=
range
logs
{
// Apply ApiKeyID filter
if
filters
.
ApiKeyID
>
0
&&
log
.
ApiKeyID
!=
filters
.
ApiKeyID
{
continue
}
// Apply Model filter
if
filters
.
Model
!=
""
&&
log
.
Model
!=
filters
.
Model
{
continue
}
// Apply Stream filter
if
filters
.
Stream
!=
nil
&&
log
.
Stream
!=
*
filters
.
Stream
{
continue
}
// Apply BillingType filter
if
filters
.
BillingType
!=
nil
&&
log
.
BillingType
!=
*
filters
.
BillingType
{
continue
}
// Apply time range filters
if
filters
.
StartTime
!=
nil
&&
log
.
CreatedAt
.
Before
(
*
filters
.
StartTime
)
{
continue
}
if
filters
.
EndTime
!=
nil
&&
log
.
CreatedAt
.
After
(
*
filters
.
EndTime
)
{
continue
}
filtered
=
append
(
filtered
,
log
)
}
total
:=
int64
(
len
(
filtered
))
out
:=
paginateLogs
(
filtered
,
params
)
return
out
,
paginationResult
(
total
,
params
),
nil
return
out
,
paginationResult
(
total
,
params
),
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment