-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (83 loc) · 2.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const express = require("express");
const { v4: uuidv4 } = require("uuid");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json({ limit: "500mb" }));
const { api_port } = require("./environment");
const create_userLogic = require("./logic/create_user");
const create_gameLogic = require("./logic/create_game");
const dealLogic = require("./logic/deal");
app.get("/", (req, res) => {
res.send(res.statusCode);
});
app.post("/api/v1/create_user", async (req, res) => {
var { name, coins } = req.query;
const create_userLogicResponse = await create_userLogic(name, coins);
res.send(create_userLogicResponse);
});
app.post("/api/v1/create_game", async (req, res) => {
var { players, decks } = req.body;
try {
const create_gameLogicResponse = await create_gameLogic(players, decks);
res.send(create_gameLogicResponse);
} catch (err) {
res.send(err.message);
}
});
app.post("/api/v1/deal", (req, res) => {
var { game_id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/insurance", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/hit", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/stand", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/double_down", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/split", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/game_status", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/winner", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.post("/api/v1/finish_game", (req, res) => {
var { id, coins } = req.body;
const dealResponse = dealLogic(game_id, coins);
const gameId = "G_" + uuidv4();
res.send(gameId);
});
app.listen(api_port, () => {
console.log(`Example app listening at http://localhost:${api_port}`);
});