Add Users API endpoint (#547)
* add users endpoint to API * docs, url * tweak docs
This commit is contained in:
parent
5e768aa57c
commit
fa86f5e89a
|
@ -398,6 +398,65 @@ Requires no authorization.
|
||||||
```
|
```
|
||||||
- Response type: A `FullMarket` ; same as above.
|
- Response type: A `FullMarket` ; same as above.
|
||||||
|
|
||||||
|
### `GET /v0/users`
|
||||||
|
|
||||||
|
Lists all users.
|
||||||
|
|
||||||
|
Requires no authorization.
|
||||||
|
|
||||||
|
- Example request
|
||||||
|
```
|
||||||
|
https://manifold.markets/api/v0/users
|
||||||
|
```
|
||||||
|
- Example response
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id":"igi2zGXsfxYPgB0DJTXVJVmwCOr2",
|
||||||
|
"createdTime":1639011767273,
|
||||||
|
"name":"Austin",
|
||||||
|
"username":"Austin",
|
||||||
|
"url":"https://manifold.markets/Austin",
|
||||||
|
"avatarUrl":"https://lh3.googleusercontent.com/a-/AOh14GiZyl1lBehuBMGyJYJhZd-N-mstaUtgE4xdI22lLw=s96-c",
|
||||||
|
"bio":"I build Manifold! Always happy to chat; reach out on Discord or find a time on https://calendly.com/austinchen/manifold!",
|
||||||
|
"bannerUrl":"https://images.unsplash.com/photo-1501523460185-2aa5d2a0f981?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1531&q=80",
|
||||||
|
"website":"https://blog.austn.io",
|
||||||
|
"twitterHandle":"akrolsmir",
|
||||||
|
"discordHandle":"akrolsmir#4125",
|
||||||
|
"balance":9122.607163564959,
|
||||||
|
"totalDeposits":10339.004780544328,
|
||||||
|
"totalPnLCached":9376.601262721899,
|
||||||
|
"creatorVolumeCached":76078.46984199001
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Response type: Array of `LiteUser`
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// Basic information about a user
|
||||||
|
type LiteUser = {
|
||||||
|
id: string // user's unique id
|
||||||
|
createdTime: number
|
||||||
|
|
||||||
|
name: string // display name, may contain spaces
|
||||||
|
username: string // username, used in urls
|
||||||
|
url: string // link to user's profile
|
||||||
|
avatarUrl?: string
|
||||||
|
|
||||||
|
bio?: string
|
||||||
|
bannerUrl?: string
|
||||||
|
website?: string
|
||||||
|
twitterHandle?: string
|
||||||
|
discordHandle?: string
|
||||||
|
|
||||||
|
// Note: the following are here for convenience only and may be removed in the future.
|
||||||
|
balance: number
|
||||||
|
totalDeposits: number
|
||||||
|
totalPnLCached: number
|
||||||
|
creatorVolumeCached: number
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### `POST /v0/bet`
|
### `POST /v0/bet`
|
||||||
|
|
||||||
Places a new bet on behalf of the authorized user.
|
Places a new bet on behalf of the authorized user.
|
||||||
|
|
|
@ -3,7 +3,9 @@ import { Answer } from 'common/answer'
|
||||||
import { getOutcomeProbability, getProbability } from 'common/calculate'
|
import { getOutcomeProbability, getProbability } from 'common/calculate'
|
||||||
import { Comment } from 'common/comment'
|
import { Comment } from 'common/comment'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
|
import { User } from 'common/user'
|
||||||
import { removeUndefinedProps } from 'common/util/object'
|
import { removeUndefinedProps } from 'common/util/object'
|
||||||
|
import { ENV_CONFIG } from 'common/envs/constants'
|
||||||
|
|
||||||
export type LiteMarket = {
|
export type LiteMarket = {
|
||||||
// Unique identifer for this market
|
// Unique identifer for this market
|
||||||
|
@ -143,3 +145,61 @@ function augmentAnswerWithProbability(
|
||||||
probability,
|
probability,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LiteUser = {
|
||||||
|
id: string
|
||||||
|
createdTime: number
|
||||||
|
|
||||||
|
name: string
|
||||||
|
username: string
|
||||||
|
url: string
|
||||||
|
avatarUrl?: string
|
||||||
|
|
||||||
|
bio?: string
|
||||||
|
bannerUrl?: string
|
||||||
|
website?: string
|
||||||
|
twitterHandle?: string
|
||||||
|
discordHandle?: string
|
||||||
|
|
||||||
|
balance: number
|
||||||
|
totalDeposits: number
|
||||||
|
totalPnLCached: number
|
||||||
|
creatorVolumeCached: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toLiteUser(user: User): LiteUser {
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
createdTime,
|
||||||
|
name,
|
||||||
|
username,
|
||||||
|
avatarUrl,
|
||||||
|
bio,
|
||||||
|
bannerUrl,
|
||||||
|
website,
|
||||||
|
twitterHandle,
|
||||||
|
discordHandle,
|
||||||
|
balance,
|
||||||
|
totalDeposits,
|
||||||
|
totalPnLCached,
|
||||||
|
creatorVolumeCached,
|
||||||
|
} = user
|
||||||
|
|
||||||
|
return removeUndefinedProps({
|
||||||
|
id,
|
||||||
|
createdTime,
|
||||||
|
name,
|
||||||
|
username,
|
||||||
|
url: `https://${ENV_CONFIG.domain}/${username}`,
|
||||||
|
avatarUrl,
|
||||||
|
bio,
|
||||||
|
bannerUrl,
|
||||||
|
website,
|
||||||
|
twitterHandle,
|
||||||
|
discordHandle,
|
||||||
|
balance,
|
||||||
|
totalDeposits,
|
||||||
|
totalPnLCached,
|
||||||
|
creatorVolumeCached,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
17
web/pages/api/v0/users.ts
Normal file
17
web/pages/api/v0/users.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// Next.js API route support: https://vercel.com/docs/concepts/functions/serverless-functions
|
||||||
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||||
|
import { listAllUsers } from 'web/lib/firebase/users'
|
||||||
|
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
||||||
|
import { toLiteUser } from './_types'
|
||||||
|
|
||||||
|
type Data = any[]
|
||||||
|
|
||||||
|
export default async function handler(
|
||||||
|
req: NextApiRequest,
|
||||||
|
res: NextApiResponse<Data>
|
||||||
|
) {
|
||||||
|
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
||||||
|
const users = await listAllUsers()
|
||||||
|
res.setHeader('Cache-Control', 'max-age=0')
|
||||||
|
res.status(200).json(users.map(toLiteUser))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user