Add some API endpoints for reading group info (#707)
This commit is contained in:
parent
0819c3918f
commit
ec84245dd4
|
@ -46,6 +46,24 @@ Gets a user by their unique ID. Many other API endpoints return this as the `use
|
|||
|
||||
Requires no authorization.
|
||||
|
||||
### `GET /v0/groups`
|
||||
|
||||
Gets all groups, in no particular order.
|
||||
|
||||
Requires no authorization.
|
||||
|
||||
### `GET /v0/groups/[slug]`
|
||||
|
||||
Gets a group by its slug.
|
||||
|
||||
Requires no authorization.
|
||||
|
||||
### `GET /v0/groups/by-id/[id]`
|
||||
|
||||
Gets a group by its unique ID.
|
||||
|
||||
Requires no authorization.
|
||||
|
||||
### `GET /v0/markets`
|
||||
|
||||
Lists all markets, ordered by creation date descending.
|
||||
|
|
18
web/pages/api/v0/group/[slug].ts
Normal file
18
web/pages/api/v0/group/[slug].ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getGroupBySlug } from 'web/lib/firebase/groups'
|
||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
||||
const { slug } = req.query
|
||||
const group = await getGroupBySlug(slug as string)
|
||||
if (!group) {
|
||||
res.status(404).json({ error: 'Group not found' })
|
||||
return
|
||||
}
|
||||
res.setHeader('Cache-Control', 'no-cache')
|
||||
return res.status(200).json(group)
|
||||
}
|
18
web/pages/api/v0/group/by-id/[id].ts
Normal file
18
web/pages/api/v0/group/by-id/[id].ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getGroup } from 'web/lib/firebase/groups'
|
||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
||||
const { id } = req.query
|
||||
const group = await getGroup(id as string)
|
||||
if (!group) {
|
||||
res.status(404).json({ error: 'Group not found' })
|
||||
return
|
||||
}
|
||||
res.setHeader('Cache-Control', 'no-cache')
|
||||
return res.status(200).json(group)
|
||||
}
|
15
web/pages/api/v0/groups.ts
Normal file
15
web/pages/api/v0/groups.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { listAllGroups } from 'web/lib/firebase/groups'
|
||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
||||
|
||||
type Data = any[]
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
||||
const groups = await listAllGroups()
|
||||
res.setHeader('Cache-Control', 'max-age=0')
|
||||
res.status(200).json(groups)
|
||||
}
|
Loading…
Reference in New Issue
Block a user