This commit is contained in:
Aelita4 2024-06-18 21:42:23 +02:00
parent 26125be066
commit 8c5cfc9e65
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
1 changed files with 81 additions and 2 deletions

81
API.md
View File

@ -1,3 +1,83 @@
# Table of contents
- [Table of contents](#table-of-contents)
- [1. Description of custom types](#1-description-of-custom-types)
- [AccessToken](#accesstoken)
- [Building](#building)
- [Planet](#planet)
- [Research](#research)
- [Resource](#resource)
- [User](#user)
- [2. API endpoints](#2-api-endpoints)
- [/generateAccessToken](#generateaccesstoken)
- [/testAccessToken](#testaccesstoken)
- [/planets/getPlanet](#planetsgetplanet)
- [/planets/getAllPlanets](#planetsgetallplanets)
- [/research/getResearch](#researchgetresearch)
- [/research/performResearch](#researchperformresearch)
- [/build/createBuilding](#buildcreatebuilding)
# 1. Description of custom types
## AccessToken
```ts
_id: ObjectId // (MongoDB)
type: "A" | "S" | "X" // Auth, Spy, Master
user: ObjectId | null // master token has this field empty
entropy: string // random bytes
createdAt: Date
expiresAt: Date | null // null for "never expires"
createdFrom: string
```
## Building
```ts
id: string
level: number
```
## Planet
```ts
_id: ObjectId,
owner: User,
name: string,
fields: number,
resources: Array<Resource>,
buildings: Array<Building>,
ships: Array<Ship>,
```
## Research
```ts
id: string
level: number
```
## Resource
```ts
name: string
amount: number
lastUpdated: Date
perHourMiningRate: number
```
## User
```ts
_id: ObjectId
username: string
email: string
password: string // hashed with argon2
lastLogin: Date
research: Array<Research>
planets: { // getting user planets requires second call to DB
partial: boolean; // so by default "partial" is true, and "data" is empty
data: Array<Planet> // unless specified otherwise in code
}
createdAt: Date
updatedAt: Date
```
# 2. API endpoints
## /generateAccessToken ## /generateAccessToken
**URL: POST** /generateAccessToken **URL: POST** /generateAccessToken
@ -160,4 +240,3 @@
"message": "OK" "message": "OK"
} }
``` ```