Skip to content

Commit

Permalink
feat: startups list in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudambro committed Aug 7, 2023
1 parent 55456ac commit 305e995
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/app/api/startups/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NextResponse } from "next/server"
import type { Incubator } from "@/types/incubator"
import type { Startup } from "@/types/startup"

interface BetaGouvStartupsData {
links: {
self: string
}
data: Startup[]
included: Incubator[]
}

export async function GET() {
const res = await fetch("https://beta.gouv.fr/api/v2.5/startups.json", {
cache: "no-store",
})

const betaGouvData: BetaGouvStartupsData = await res.json()

const ourStartups = betaGouvData.data
.filter((startup) => {
return startup.relationships.incubator.data.id === "sgmas"
})
.map((startup) => {
// remove the incubator relationship
// delete startup.relationships
// delete startup.attributes?.content_url_encoded_markdown
const { relationships, attributes, ...rest } = startup
const { content_url_encoded_markdown, ...restAttributes } = attributes
return {
...rest,
attributes: restAttributes,
}
})

return NextResponse.json({ data: ourStartups })
}
22 changes: 20 additions & 2 deletions src/app/startups/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { fr } from "@codegouvfr/react-dsfr"

export default function Startups() {
async function getData() {
const res = await fetch("http://localhost:3000/api/startups")
// The return value is *not* serialized
// You can return Date, Map, Set, etc.

if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
throw new Error("Failed to fetch data")
}

return res.json()
}

export const revalidate = 3600 // revalidate at most every hour

export default async function Recrutement() {
const data = await getData()

return (
<section>
<h1 className={fr.cx("fr-h1")}>Nos startups</h1>
<h1 className={fr.cx("fr-h1")}>Recrutement</h1>
<pre>{JSON.stringify(data, null, 2)}</pre>
</section>
)
}
11 changes: 11 additions & 0 deletions src/types/incubator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface Incubator {
id: string
type: string
attributes: {
title: string
owner: string
website: string
github: string
contact: string
}
}
46 changes: 46 additions & 0 deletions src/types/startup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export interface Startup {
id: string
type: string
attributes: {
name: string
pitch: string
stats_url?: string
budget_url?: string
link?: string
repository?: string
contact: string
content_url_encoded_markdown: string
events: StartupEvent[]
phases: StartupPhase[]
analyse_risques?: string
analyse_risques_url?: string
dashlord_url?: string
accessibility_status?: string
}
relationships: {
incubator: {
data: {
type: "incubator"
id: string
}
}
}
}

interface StartupEvent {
name: string
date: string
comment: string
}

interface StartupPhase {
name:
| "acceleration"
| "alumni"
| "construction"
| "investigation"
| "success"
| "transfer"
start: string
end: string
}

0 comments on commit 305e995

Please sign in to comment.