Skip to content

Commit

Permalink
Merge branch 'html-to-jsx' of https://github.com/Bashamega/WebDevTools
Browse files Browse the repository at this point in the history
…into html-to-jsx
  • Loading branch information
Bashamega committed Jul 23, 2024
2 parents d99359e + cbac1e9 commit 57e214a
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 344 deletions.
157 changes: 51 additions & 106 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 15 additions & 16 deletions src/app/api/posts/route.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import posts from '@/db/posts.json'
import { NextResponse } from 'next/server';

import posts from "@/db/posts.json";
import { NextResponse } from "next/server";

export async function GET(req) {
const { searchParams } = new URL(req.url);
let page = parseInt(searchParams.get('page'));
if(isNaN(page) || page < 1) {
page = 1;
}
const postsPerPage = 10;
const startIndex = (page - 1) * postsPerPage;
const { searchParams } = new URL(req.url);
let page = parseInt(searchParams.get("page"));
if (isNaN(page) || page < 1) {
page = 1;
}
const postsPerPage = 10;
const startIndex = (page - 1) * postsPerPage;

if (startIndex < 0 || startIndex >= posts.length) {
return NextResponse.json({ error: "Page not found" }, { status: 404 });
}
if (startIndex < 0 || startIndex >= posts.length) {
return NextResponse.json({ error: "Page not found" }, { status: 404 });
}

const paginatedPosts = posts.slice(startIndex, startIndex + postsPerPage);
return NextResponse.json(paginatedPosts, { status: 200 });
}
const paginatedPosts = posts.slice(startIndex, startIndex + postsPerPage);
return NextResponse.json(paginatedPosts, { status: 200 });
}
21 changes: 10 additions & 11 deletions src/app/api/users/[userId]/route.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import users from '@/db/users.json'
import { NextResponse } from 'next/server';
import users from "@/db/users.json";
import { NextResponse } from "next/server";


export async function GET(req, {params}) {
const userId = parseInt(params.userId);
const user = users.find(user => user.userId === userId);
if (!user) {
return NextResponse.json({error: 'user not found'}, { status: 404 });
}
return NextResponse.json(user, { status: 200 });
}
export async function GET(req, { params }) {
const userId = parseInt(params.userId);
const user = users.find((user) => user.userId === userId);
if (!user) {
return NextResponse.json({ error: "user not found" }, { status: 404 });
}
return NextResponse.json(user, { status: 200 });
}
31 changes: 15 additions & 16 deletions src/app/api/users/route.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import users from '@/db/users.json'
import { NextResponse } from 'next/server';

import users from "@/db/users.json";
import { NextResponse } from "next/server";

export async function GET(req) {
const { searchParams } = new URL(req.url);
let page = parseInt(searchParams.get('page'));
if(isNaN(page) || page < 1) {
page = 1;
}
const usersPerPage = 10;
const startIndex = (page - 1) * usersPerPage;
const { searchParams } = new URL(req.url);
let page = parseInt(searchParams.get("page"));
if (isNaN(page) || page < 1) {
page = 1;
}
const usersPerPage = 10;
const startIndex = (page - 1) * usersPerPage;

if (startIndex < 0 || startIndex >= users.length) {
return NextResponse.json({ error: "Page not found" }, { status: 404 });
}
if (startIndex < 0 || startIndex >= users.length) {
return NextResponse.json({ error: "Page not found" }, { status: 404 });
}

const paginatedUsers = users.slice(startIndex, startIndex + usersPerPage);
return NextResponse.json(paginatedUsers, { status: 200 });
}
const paginatedUsers = users.slice(startIndex, startIndex + usersPerPage);
return NextResponse.json(paginatedUsers, { status: 200 });
}
Loading

0 comments on commit 57e214a

Please sign in to comment.