Skip to content

Commit

Permalink
add case studies endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Aug 7, 2024
1 parent fcca53a commit fe8f7a7
Show file tree
Hide file tree
Showing 5 changed files with 783 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/(static)/case-studies/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// TODO: define how to show the available filters for this entity: show enums, retrieve from data, smart filtering...
// i.e, location is an available filter but the prop is defined as a string as it is not clear which the available values are.

import { NextRequest, NextResponse } from 'next/server';

import { CaseStudyService } from '@/lib/case-studies.service';

import { CASE_STUDIES } from '@/data/case-studies';

export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;

const { filters, paginationFilters } = CaseStudyService.extractFilters(searchParams);
const caseStudyService = new CaseStudyService(CASE_STUDIES, filters, paginationFilters);
const result = caseStudyService.searchCaseStudies();

return NextResponse.json(result);
}
5 changes: 5 additions & 0 deletions src/app/(static)/news/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { NewsService } from '@/lib/news.service';
import NEWS from '@/data/news';

export async function GET(request: NextRequest) {
/**
* @note Following the underlying express engine's behavior, array query params must be sent as multiple query params with the same key.
* For example, to send the categories ['1', '2'], the query params should be `?categories=1&categories=2`.
* So we can properly parse the query params into an array using the native URLSearchParams API.
*/
const { searchParams } = request.nextUrl;

const { filters, paginationFilters } = NewsService.extractFilters(searchParams);
Expand Down
Loading

0 comments on commit fe8f7a7

Please sign in to comment.