Skip to content
Snippets Groups Projects
Commit 4953ecb9 authored by antoine.blancy's avatar antoine.blancy
Browse files

body no longer empty

parent 6d4753d5
No related branches found
No related tags found
No related merge requests found
GET http://localhost:8080/api/v1/list/features/antwan
###
POST http://localhost:8080/api/v1/list/features/
content-type: application/json
{
"userName": "antwan",
"elementId": "bruh"
}
\ No newline at end of file
{
"antwan":
{
"spellList":[
"blink",
"dimension-door",
"reverse-gravity"
],
"monsterList":[
],
"featureList":[
]
},
"xioshiva" :
{
"spellList":[
"animal-shapes",
"confusion"
],
"monsterList":[
],
"featureList":[
]
},
"user" :
{
"spellList":[
"entangle",
"flesh-to-stone",
"haste"
],
"monsterList":[
],
"featureList":[
]
}
}
\ No newline at end of file
{"antwan":{"spellList":["blink","dimension-door","reverse-gravity"],"monsterList":[],"featureList":["bruh"]},"xioshiva":{"spellList":["animal-shapes","confusion"],"monsterList":[],"featureList":[]},"user":{"spellList":["entangle","flesh-to-stone","haste"],"monsterList":[],"featureList":[]}}
\ No newline at end of file
......@@ -37,8 +37,8 @@ function writeMonsterList(userName, monsterList){
function writeFeatureList(userName, featureList){
let file = fs.readFileSync('modules/data.json', 'utf-8');
let fileData = JSON.parse(file.toString());
fileData[username].featureList = featureList;
fs.writeFileSync('modules/data.json', fileData);
fileData[userName].featureList = featureList;
fs.writeFileSync('modules/data.json', JSON.stringify(fileData));
}
module.exports = { readSpellList, readMonsterList, readFeatureList,
......
......@@ -3,6 +3,13 @@ const express = require("express");
const path = require("path");
const app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
const db = require('./modules/dbInterface.js');
const auth = require('./modules/auth.js');
......@@ -12,6 +19,8 @@ const lst = require('./modules/list.js');
app.use("/static", express.static(path.resolve(__dirname, "../frontend", "static")));
//Tout les autres chemins vont rediriger vers index.html pour créer une Single Page Application
lst.addFeature("antwan", "archdruid" );
app.get("/api/v1/list/spells/:userName", (req, res) => {
if (auth.doesUserExist(req.params.userName)){
res.json(lst.getSpellList(req.params.userName));
......@@ -37,10 +46,12 @@ app.get("/api/v1/list/features/:userName", (req, res) => {
});
app.post("/api/v1/list/features/:userName/:featureId", (req, res) => {
if (auth.doesUserExist(req.params.userName)){
lst.addFeature(req.params.userName)
app.post("/api/v1/list/features/", (req, res) => {
console.log(req.body);
if (auth.doesUserExist(req.body["userName"])){
lst.addFeature(req.body["userName"],req.body["elementId"] );
res.json(lst.getFeatureList);
res.status(200).end();
}else{
res.status(422).end();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment