Skip to content

fix: listTasks query parsing - #362

Closed
nahapetyan-serob wants to merge 1 commit into
mainfrom
serob/fix-query-parameter-handling
Closed

fix: listTasks query parsing#362
nahapetyan-serob wants to merge 1 commit into
mainfrom
serob/fix-query-parameter-handling

Conversation

@nahapetyan-serob

Copy link
Copy Markdown
Collaborator

GET /tasks?historyLength=N and ?statusTimestampAfter=... were silently
dropped by the REST ListTasks handler. The parse closure dispatched on
target type with a type switch, but *int / *time.Time fields on
ListTasksRequest produced **int / **time.Time arguments that no case
matched — so the values never reached the request.

Replaced the type-switch parse closure with a typed parseQueryParams
helper that returns (*a2a.ListTasksRequest, error).
Extracted parseHistoryLength and parseStatusTimestampAfter helpers,
reused by handleGetTask and handleListTasks.

Added new test to verify correctly parsed ListTasksRequest reaching to handler
Extended TestREST_ListTasksParseErrors with historyLength and
statusTimestampAfter invalid-value cases.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors query parameter parsing in a2asrv/rest.go by replacing inline parsing logic with dedicated helper functions (parseListTasksQueryParams, parseHistoryLength, and parseStatusTimestampAfter) and adds comprehensive unit tests in a2asrv/rest_test.go to verify query parsing. The reviewer suggested simplifying the parseHistoryLength and parseStatusTimestampAfter helper functions by returning early when the query parameter is empty, which improves readability and avoids declaring unnecessary pointer variables.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread a2asrv/rest.go
Comment on lines +501 to +512
func parseHistoryLength(query url.Values) (*int, error) {
historyLengthRaw := query.Get("historyLength")
var historyLength *int
if historyLengthRaw != "" {
val, err := strconv.Atoi(historyLengthRaw)
if err != nil {
return nil, err
}
historyLength = &val
}
return historyLength, nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This helper function can be simplified by returning early when the query parameter is empty. This avoids declaring an unnecessary pointer variable and makes the logic more direct and readable.

func parseHistoryLength(query url.Values) (*int, error) {
	raw := query.Get("historyLength")
	if raw == "" {
		return nil, nil
	}
	val, err := strconv.Atoi(raw)
	if err != nil {
		return nil, err
	}
	return &val, nil
}

Comment thread a2asrv/rest.go
Comment on lines +514 to +525
func parseStatusTimestampAfter(query url.Values) (*time.Time, error) {
statusTimestampAfterRaw := query.Get("statusTimestampAfter")
var statusTimestampAfter *time.Time
if statusTimestampAfterRaw != "" {
val, err := time.Parse(time.RFC3339Nano, statusTimestampAfterRaw)
if err != nil {
return nil, err
}
statusTimestampAfter = &val
}
return statusTimestampAfter, nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This helper function can be simplified by returning early when the query parameter is empty. This avoids declaring an unnecessary pointer variable and makes the logic more direct and readable.

func parseStatusTimestampAfter(query url.Values) (*time.Time, error) {
	raw := query.Get("statusTimestampAfter")
	if raw == "" {
		return nil, nil
	}
	val, err := time.Parse(time.RFC3339Nano, raw)
	if err != nil {
		return nil, err
	}
	return &val, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant