Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Insomnia.json

Large diffs are not rendered by default.

19 changes: 1 addition & 18 deletions src/controllers/root.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
import { Request, Response } from 'express';
import endpointsJson from '../endpoints.json';

export function index(request: Request, response: Response) {
response.status(200).json({
success: true,
});
}

export function endpoints(request: Request, response: Response) {
const data = {};
endpointsJson.forEach((endpoint) => {
const copy = JSON.parse(JSON.stringify(endpoint));
delete copy.path;
Object.assign(data, {
[endpoint.path]: {
...copy,
},
});
});

response.status(200).json({
success: true,
data: data,
data: { endpoints: endpointsJson },
});
}
149 changes: 66 additions & 83 deletions src/endpoints.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
[
{
"path": "/api",
"description": "Index of API",
"method": "GET",
"authentication": "none",
"result": {
"success": true
}
},
{
"path": "/api/endpoints",
{
"/api": {
"description": "List all endpoints",
"method": "GET",
"authentication": "none",
Expand All @@ -25,74 +15,72 @@
}
}
},
{
"path": "/api/devices/create",
"description": "Register a new device",
"/api/cats/create": {
"description": "Register a new cat",
"method": "POST",
"authentication": "username",
"body": {},
"body": {
"name": "string, optional",
"description": "string, optional",
"picture_url": "string, optional"
},
"result": {
"success": true
"success": true,
"data": {}
}
},
{
"path": "/api/devices/update",
"description": "Update information <GPS DEVICE>",
"/api/cats/update": {
"description": "Update a cats social information",
"method": "PATCH",
"authentication": "device-uuid",
"authentication": "username",
"body": {
"id": "string",
"lat": "number",
"lon": "number"
"cat_id": "string",
"name": "string, optional",
"description": "string, optional",
"picture_url": "string, optional"
},
"result": {}
},
{
"path": "/api/users/:id/devices",
"description": "List all of a users devices",
"method": "GET",
"authentication": "none",
"result": {
"success": true,
"data": [
{
"id": "cm3owzqrd0001z4qlshsse6re",
"name": "GPS Device",
"uuid": "31ee122b-0bc3-446f-bf67-ea945cef4c1c",
"owner_id": "cm3op7iwu0000jrcqa60tc9kv",
"last_pulse_at": null,
"last_location": {},
"location_history": [],
"updated_at": "2024-11-19T20:36:00.698Z",
"created_at": "2024-11-19T20:36:00.698Z"
}
]
"data": {
"id": "cm3pz1t0v000308jka8bl7x25",
"name": "Daisy, Eater of Worlds",
"description": "Meow meow. Meow meow? Meow!",
"picture_url": "https://c8.alamy.com/comp/DBTJAD/a-closeup-picture-of-a-cats-face-on-a-white-background-DBTJAD.jpg",
"device_id": "cm3pz39ec0003110jpvg6mya6",
"owner_id": "cm3op7iwu0000jrcqa60tc9kv",
"updated_at": "2024-11-20T14:31:14.136Z",
"created_at": "2024-11-20T14:22:30.232Z",
"deleted_at": null
}
}
},
"/api/devices/create": {
"description": "Register a new device",
"method": "POST",
"authentication": "username",
"body": {},
"result": {
"success": true
}
},
{
"path": "/api/devices/delete",
"/api/devices/delete": {
"description": "Delete a device",
"method": "DELETE",
"authentication": "username",
"result": {}
},
{
"path": "/api/cats/create",
"description": "Register a new cat",
"method": "POST",
"authentication": "username",
"/api/devices/update": {
"description": "Update information <GPS DEVICE>",
"method": "PATCH",
"authentication": "device-uuid",
"body": {
"name": "string, optional",
"description": "string, optional",
"picture_url": "string, optional"
"id": "string",
"lat": "number",
"lon": "number"
},
"result": {
"success": true,
"data": {}
}
"result": {}
},
{
"path": "/api/users/:id/cats",
"/api/users/:id/cats": {
"description": "List all of a users cats",
"method": "GET",
"authentication": "none",
Expand All @@ -113,30 +101,25 @@
]
}
},
{
"path": "/api/cats/update",
"description": "Update a cats social information",
"method": "PATCH",
"authentication": "username",
"body": {
"cat_id": "string",
"name": "string, optional",
"description": "string, optional",
"picture_url": "string, optional"
},
"/api/users/:id/devices": {
"description": "List all of a users devices",
"method": "GET",
"authentication": "none",
"result": {
"success": true,
"data": {
"id": "cm3pz1t0v000308jka8bl7x25",
"name": "Daisy, Eater of Worlds",
"description": "Meow meow. Meow meow? Meow!",
"picture_url": "https://c8.alamy.com/comp/DBTJAD/a-closeup-picture-of-a-cats-face-on-a-white-background-DBTJAD.jpg",
"device_id": "cm3pz39ec0003110jpvg6mya6",
"owner_id": "cm3op7iwu0000jrcqa60tc9kv",
"updated_at": "2024-11-20T14:31:14.136Z",
"created_at": "2024-11-20T14:22:30.232Z",
"deleted_at": null
}
"data": [
{
"id": "cm3owzqrd0001z4qlshsse6re",
"name": "GPS Device",
"uuid": "31ee122b-0bc3-446f-bf67-ea945cef4c1c",
"owner_id": "cm3op7iwu0000jrcqa60tc9kv",
"last_pulse_at": null,
"last_location": {},
"location_history": [],
"updated_at": "2024-11-19T20:36:00.698Z",
"created_at": "2024-11-19T20:36:00.698Z"
}
]
}
}
]
}
5 changes: 2 additions & 3 deletions src/routes/root.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Router } from 'express';
import * as controller from '../controllers/root';
import { endpoints } from '../controllers/root';

const root: Router = Router();

root.get('/', controller.index);
root.get('/endpoints', controller.endpoints);
root.get('/', endpoints);

export default root;