Skip to content

Commit

Permalink
Added get and get total posts request for a new asylum-refugees front…
Browse files Browse the repository at this point in the history
…-end (#37)
  • Loading branch information
ama-cantabile authored May 13, 2024
1 parent 4f9db3b commit 9dc567a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/app/api/job-posting/asylum-refugees/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { NextResponse } from 'next/server';
import {
getPaginationParams,
fetchJobPostings,
handleError,
} from '../siteRequestUtils';

export async function GET(req) {
try {
//Todo: Update the site5 name to asylum-refugees
const siteCriteria = { site5: true };

// Extract pagination parameters
const { skip, pageSize } = getPaginationParams(req);

// Query job postings with pagination
const jobPostings = await fetchJobPostings(siteCriteria, skip, pageSize);

if (jobPostings.length === 0) {
return NextResponse.json(
{ message: 'Not Found - No job postings found on this page' },
{ status: 404 }
);
}

// Return success response with the paginated job postings
return NextResponse.json({ jobPostings }, { status: 200 });
} catch (error) {
// Handle errors
return handleError(error);
}
}
22 changes: 22 additions & 0 deletions src/app/api/job-posting/asylum-refugees/total-posts/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextResponse } from 'next/server';
import { getTotalNumberOfPostings, handleError } from '../../siteRequestUtils';

export async function GET() {
try {
const siteCriteria = { site5: true };

let jobPostings = await getTotalNumberOfPostings(siteCriteria);

if (jobPostings < 1) {
return NextResponse.json(
{ message: 'Not Found - No job postings found on this page' },
{ status: 404 }
);
}

return NextResponse.json({ jobPostings }, { status: 200 });
} catch (error) {
// Handle errors
return handleError(error);
}
}

0 comments on commit 9dc567a

Please sign in to comment.