-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'html-to-jsx' of https://github.com/Bashamega/WebDevTools …
…into html-to-jsx
- Loading branch information
Showing
6 changed files
with
317 additions
and
344 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
Oops, something went wrong.