mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-05-03 17:29:50 -04:00
add basic API
This commit is contained in:
parent
89c1742515
commit
b980608f86
49
src/api.ts
Normal file
49
src/api.ts
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import { Router } from 'express';
|
||||||
|
import { getGroupByID, getPostByID, getUserByID } from './data';
|
||||||
|
|
||||||
|
export const router = Router();
|
||||||
|
|
||||||
|
router.get('/user', (req, res) => {
|
||||||
|
if (typeof req.query.userID != 'string') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let userID = req.query.userID;
|
||||||
|
let user = getUserByID(userID);
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
res.json({ status: 'success', data: user });
|
||||||
|
} else {
|
||||||
|
res.json({ status: 'error', error: 'not_found' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/post', (req, res) => {
|
||||||
|
if (typeof req.query.postID != 'string') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let postID = req.query.postID;
|
||||||
|
let post = getPostByID(postID);
|
||||||
|
|
||||||
|
if (post) {
|
||||||
|
res.json({ status: 'success', data: post });
|
||||||
|
} else {
|
||||||
|
res.json({ status: 'error', error: 'not_found' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/group', (req, res) => {
|
||||||
|
if (typeof req.query.groupID != 'string') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let groupID = req.query.groupID;
|
||||||
|
let group = getGroupByID(groupID);
|
||||||
|
|
||||||
|
if (group) {
|
||||||
|
res.json({ status: 'success', data: group });
|
||||||
|
} else {
|
||||||
|
res.json({ status: 'error', error: 'not_found' });
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user