Add get_persons_by_nickname with pagination to TahrirDatabase#263
Add get_persons_by_nickname with pagination to TahrirDatabase#263Daniel-1600 wants to merge 1 commit intofedora-infra:developfrom
Conversation
sdglitched
left a comment
There was a problem hiding this comment.
Thank you for working on this.
Please make the requested changes, along with signing the commit and following the 50-character rule for commit messages.
Also, specify the AI usage as per ACP and explain what your thought process was during the development as per the latest decision.
| :type limit: int | ||
| :param limit: Max results per page, capped at 100 (default 100). | ||
| """ | ||
| safe_limit = min(limit, 100) |
There was a problem hiding this comment.
Good job fixing the highest limit 👍
| "id": person.id, | ||
| "nickname": person.nickname, | ||
| "avatar": person.avatar, | ||
| "rank": person.rank, |
There was a problem hiding this comment.
Why are only these particular fields fetched and not the other ones?
Please check the current implementation in https://github.com/fedora-infra/tahrir/blob/d9a22d25e6d47ced5b4225bfff833ab02b8cd6c7/tahrir/endpoints/users.py#L33-L41 and add the rest of the fields.
|
|
||
| def test_get_persons_by_nickname(api): | ||
| api.add_person("alice@test.com", nickname="alice_wonder") | ||
| api.add_person("bob@test.com", nickname="bob_builder") | ||
| api.add_person("charlie@test.com", nickname="charlie_choc") | ||
|
|
||
| result = api.get_persons_by_nickname("alice") | ||
| assert result["total"] == 1 | ||
| assert result["users"][0]["nickname"] == "alice_wonder" | ||
|
|
||
| def test_get_persons_by_nickname_partial_match(api): | ||
| api.add_person("dave@test.com", nickname="dave_test") | ||
| api.add_person("diana@test.com", nickname="diana_test") | ||
| api.add_person("evan@test.com", nickname="evan_other") | ||
|
|
||
| result = api.get_persons_by_nickname("test") | ||
| assert result["total"] == 2 | ||
|
|
||
| def test_get_persons_by_nickname_pagination(api): | ||
| for i in range(5): | ||
| api.add_person(f"user{i}@test.com", nickname=f"user_{i}") | ||
|
|
||
| result = api.get_persons_by_nickname("user", begin=0, limit=2) | ||
| assert len(result["users"]) == 2 | ||
| assert result["total"] == 5 | ||
| assert result["begin"] == 0 | ||
| assert result["limit"] == 2 | ||
|
|
||
| def test_get_persons_by_nickname_no_match(api): | ||
| api.add_person("test@test.com", nickname="test_user") | ||
|
|
||
| result = api.get_persons_by_nickname("zzznomatch") | ||
| assert result["total"] == 0 | ||
| assert result["users"] == [] | ||
|
|
||
| def test_get_persons_by_nickname_case_insensitive(api): | ||
| api.add_person("upper@test.com", nickname="UpperCase") | ||
|
|
||
| result = api.get_persons_by_nickname("uppercase") | ||
| assert result["total"] == 1 |
There was a problem hiding this comment.
Add the test cases in a new commit.
|
Also, make sure the test runs successfully. |
Add
get_persons_by_nicknamemethod toTahrirDatabaseto support paginated user search by nickname.This moves the user search and pagination logic from the tahrir frontend into the API layer where it belongs. The method accepts a search string, begin offset, and limit, and returns a dict with the matching users, total count, and pagination info.