Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/code-du-travail-frontend/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SearchController } from "src/api";

export const dynamic = "force-dynamic";

export async function GET(request: Request) {
const controller = new SearchController(request);
return controller.get();
}
Comment on lines +1 to +8
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[IMPORTANT] New public route has no tests and no docstring

  • Per the coding guidelines, public functions must have concise docstrings explaining purpose and return values.
  • The new GET handler is a public API entry point with no test coverage. The guidelines require 100% coverage for critical code — an API route qualifies.
  • At minimum, tests should cover:
    • Happy path: valid ?q= returns 200 with results
    • Missing q param returns 400
    • ?pq=true vs default behaviour

Suggested docstring addition:

Suggested change
import { SearchController } from "src/api";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
const controller = new SearchController(request);
return controller.get();
}
import { SearchController } from "src/api";
export const dynamic = "force-dynamic";
/**
* GET /api/search
*
* Searches documents matching the given query.
* Query params: `q` (required) search term; `pq` (optional, default off) enable prequalified results.
* Returns a JSON response with matching documents and classification.
*/
export async function GET(request: Request) {
const controller = new SearchController(request);
return controller.get();
}

2 changes: 1 addition & 1 deletion packages/code-du-travail-frontend/app/recherche/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default async function SearchPage(props: SearchPageProps) {
};

if (query) {
items = await searchWithQuery(query, 25, true);
items = await searchWithQuery(query, 25, false);
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class SearchController {
const parsed = await searchWithQuery(
query,
DEFAULT_PRESEARCH_RESULTS_NUMBER,
true
false
).then((r) => ({
results: r.documents,
class: r.class,
Expand Down
Loading