-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add /api/projects
endpoints
#34
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
993a4e4
add route handler for `/api/stub/project_ids`
swellander f9b932f
move /api/stub/project_ids => /api/projects/ids
swellander 4ff58c2
add `getProjectIds()` util function
swellander c00da51
add `getProjectIds()` project service util func
swellander e1df200
pull project ids from db
swellander 02fd1ad
update `generateStaticParams()` to use correct service
swellander b6f0aa3
update seed.sample with agora project data
swellander 9577db6
update db service helper methods
swellander ffb349c
update projectService methods
swellander 2392b4d
add /api/projects/detail/{ID} route
swellander cabdf50
add /api/projects route
swellander 2a11c70
rename `getPaginatedProjects` => `getAllProjects`
swellander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { convertProjectToDto } from ".."; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { getProjectById } from "~~/services/database/projects"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "GET") { | ||
return res.status(405).json({ message: "Method not allowed." }); | ||
} | ||
const id = req.query.id as string | undefined; | ||
if (!id) return res.status(400).json({ message: "Must include project ID" }); | ||
try { | ||
const projectDetail = await getProjectById(id); | ||
const projectDetailDto = convertProjectToDto(projectDetail); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The request from the project page needs more than the dto version. It needs the whole Project. |
||
res.status(200).json(projectDetailDto); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ message: "Internal Server Error" }); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { getProjectIds } from "~~/services/database/projects"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "GET") { | ||
return res.status(405).json({ message: "Method not allowed." }); | ||
} | ||
try { | ||
const ids = await getProjectIds(); | ||
res.status(200).json(ids); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ message: "Internal Server Error" }); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { Project } from "~~/app/types/data"; | ||
import { getProjects } from "~~/services/database/projects"; | ||
|
||
type ProjectDto = Pick< | ||
Project, | ||
"id" | "name" | "profileAvatarUrl" | "description" | "socialLinks" | "proejctCoverImageUrl" | ||
>; | ||
|
||
export const convertProjectToDto = ({ | ||
id, | ||
proejctCoverImageUrl, | ||
name, | ||
profileAvatarUrl, | ||
description, | ||
socialLinks, | ||
}: Project): ProjectDto => ({ | ||
id, | ||
proejctCoverImageUrl, | ||
name, | ||
profileAvatarUrl, | ||
description, | ||
socialLinks, | ||
}); | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "GET") { | ||
return res.status(405).json({ message: "Method not allowed." }); | ||
} | ||
try { | ||
const projects = await getProjects(); | ||
const projectDtos = projects.map(convertProjectToDto); | ||
res.status(200).json(projectDtos); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ message: "Internal Server Error" }); | ||
} | ||
} |
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
24 changes: 16 additions & 8 deletions
24
packages/nextjs/services/onchainImpactDashboardApi/projectService.ts
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,21 +1,29 @@ | ||
import { Project } from "../database/schema"; | ||
|
||
export const ProjectService = () => { | ||
const baseURL = `${process.env.NEXT_PUBLIC_API_URL}/stub/projects`; | ||
const getPaginatedProjects = async () => { | ||
const response = await fetch(`${baseURL}?limit=100`); | ||
const data = await response.json(); | ||
return data.data as Project[]; | ||
const baseURL = process.env.NEXT_PUBLIC_API_URL; | ||
|
||
const getAllProjects = async () => { | ||
const response = await fetch(`${baseURL}/projects`); | ||
const allProjects = await response.json(); | ||
return allProjects as Project[]; | ||
}; | ||
|
||
const getProjectById = async (id: string) => { | ||
const response = await fetch(`${baseURL}?id=${id}`); | ||
const { data }: { data: Project } = await response.json(); | ||
const response = await fetch(`${baseURL}/projects/detail/${id}`); | ||
const project: Project = await response.json(); | ||
return project; | ||
}; | ||
|
||
const getProjectIds = async () => { | ||
const response = await fetch(`${baseURL}/projects/ids`); | ||
const data: string[] = await response.json(); | ||
return data; | ||
}; | ||
|
||
return { | ||
getPaginatedProjects, | ||
getAllProjects, | ||
getProjectById, | ||
getProjectIds, | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file won't display for me due to lines 43-56 where
[...data?.github, ...data?.packages]
. If the project doesn't havegithub
orpackages
properties then the spread operator is trying to act upon undefined causing this error:Error: (intermediate value) is not iterable
.We should check for the existence of
github
andpackages
before using the spread operator.