Commit 12f40a50 authored by jeremy.gobet's avatar jeremy.gobet
Browse files

Fixed MR reviews and added documentation

parent 93f462d0
......@@ -96,16 +96,16 @@ Une authentification sans mot de passe permet l'identification de l'utilisateur
### Interface REST API
Voici l'API REST CRUD exposée par le backend
| Verbe HTTP | Endpoint | Données | Description |
|:-----------|:-------------------------|:------------|:------------|
| GET | emails/ | | Retourne la liste des mails des utilisateurs |
| GET | evaluated-jokes/ | | Retourne les blagues les mieux notées |
| GET | evaluated-jokes/*:email* | email* | Retourne les blagues notées par l'utilisateur |
| POST | evaluated-jokes/ | email*, id* | Ajout d'une nouvelle note à la blague (id) |
| PUT | evaluated-jokes/ | email*, id* | Modification de la note de la blague (id) |
| DELETE | evaluated-jokes/ | email*, id* | Suppression de la note de la blague (id) |
Voici l'API REST CRUD exposée par le backend sur /api/v1/
| Verbe HTTP | Endpoint | Données | Description |
|:-----------|:-----------------------------|:----------------------|:------------|
| GET | emails/ | | Retourne la liste des mails des utilisateurs |
| GET | jokes/:limit | | Retourne les blagues les mieux notées |
| GET | jokes/*:userEmail*/:limit | | Retourne les blagues notées par l'utilisateur |
| POST | jokes/ | userEmail\*, jokeId\* | Ajout d'une nouvelle note à la blague (jokeId) |
| DELETE | jokes/ | userEmail\*, jokeId\* | Suppression de la note de la blague (jokeId) |
| GET | likes/*:userEmail*/*:jokeId* | | Retourne la note d'une blague (jokeId) |
\* Obligatoire
......
......@@ -9,18 +9,42 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static('../frontend'))
/*
* API Documentation
*/
app.get('/api', function(request, response) {
response.setHeader('Content-Type', 'text/plain');
response.send('Documentation de l\'API à venir...');
})
response.send(`
Voici l'API REST CRUD exposée par le backend sur /api/v1/
| Verbe HTTP | Endpoint | Données | Description |
|:-----------|:-----------------------------|:--------------------|:-----------------------------------------------|
| GET | emails/ | | Retourne la liste des mails des utilisateurs |
| GET | jokes/:limit | | Retourne les blagues les mieux notées |
| GET | jokes/*:userEmail*/:limit | | Retourne les blagues notées par l'utilisateur |
| POST | jokes/ | userEmail\*, jokeId\* | Ajout d'une nouvelle note à la blague (jokeId) |
| DELETE | jokes/ | userEmail\*, jokeId\* | Suppression de la note de la blague (jokeId) |
| GET | likes/*:userEmail*/*:jokeId* | | Retourne la note d'une blague (jokeId) |
`);
});
/*
* Best jokes
* params limit the number of jokes returned
*/
app.get('/api/v1/jokes/:limit?', function(request, response) {
console.log('Best jokes', request.params);
response.json(jokes.getBestJokes());
})
const limit = request.params.limit ? request.params.limit : 10;
response.json(jokes.getBestJokes(limit));
});
/*
* Best jokes of specific users
* params userEmail* user's e-mail
* params limit the number of jokes returned
*/
app.get('/api/v1/jokes/:userEmail/:limit?', function(request, response) {
console.log('My jokes', request.params);
......@@ -31,8 +55,13 @@ app.get('/api/v1/jokes/:userEmail/:limit?', function(request, response) {
}
response.status(400).end(); // Bad request
})
});
/*
* Like a joke
* params userEmail* user's e-mail
* params jokeId* joke id to like
*/
app.post('/api/v1/jokes', function(request, response) {
console.log('Like joke', request.body);
......@@ -47,8 +76,14 @@ app.post('/api/v1/jokes', function(request, response) {
}
response.status(400).end(); // 400: Bad request
})
});
/*
* Dislike a joke
* params userEmail* user's e-mail
* params jokeId* joke id to dislike
*/
app.delete('/api/v1/jokes', function(request, response) {
console.log('Dislike', request.body);
......@@ -64,7 +99,12 @@ app.delete('/api/v1/jokes', function(request, response) {
response.status(400).end(); // 400: Bad request
});
/*
* Is specific joke liked or not by specific user
* params userEmail* user's e-mail
* params jokeId* joke id to retreive
*/
app.get('/api/v1/likes/:userEmail/:jokeId', function(request, response) {
console.log('Get like', request.params);
......@@ -73,7 +113,7 @@ app.get('/api/v1/likes/:userEmail/:jokeId', function(request, response) {
let result = jokes.getJokeFor(request.params.jokeId, request.params.userEmail);
response.status(200).send(result); // 200: Ok
response.status(200).json({ isLiked: result }); // 200: Ok
}
response.status(400).end(); // 400: Bad request
......
......@@ -54,6 +54,7 @@ header > .container {
header > .container > img {
height: 100%;
margin: 0 54px;
}
header > .container > span {
......@@ -71,6 +72,18 @@ header > .container h1 {
font-size: 2em;
}
@media (max-width: 800px) {
header > .container h1 {
font-size: 1em;
}
}
@media (max-width: 500px) {
header > .container img {
display: none;
}
}
/* NAVIGATION */
.console {
......@@ -95,6 +108,24 @@ header > .container h1 {
margin: 0 var(--content-padding);
}
@media (max-width: 600px) {
.console-content {
flex-direction: column;
}
.console-content > input, .console-content button {
height: 32px;
}
.console-content > input {
margin: 0;
}
.console-content button {
width: 100%;
}
}
#console-error {
color: red;
}
......@@ -152,6 +183,16 @@ div.joke {
}
}
@media (max-width: 600px) {
nav {
flex-direction: column;
}
nav > button {
height: 32px;
}
}
/* FOOTER */
body {
......
......@@ -32,7 +32,6 @@ function displayUserConnected(data) {
document.getElementById('user-disconnected').style.display = 'none';
document.getElementById('user-connected').style.display = 'flex';
// document.getElementById('my-jokes').disabled = false;
document.getElementById('welcome-user').innerHTML = 'Connecté: ' + data.userEmail;
changeDisabledPropertyForAllLikeBtn(false);
......@@ -48,8 +47,6 @@ function displayUserDisconnected() {
document.getElementById('user-connected').style.display = 'none';
document.getElementById('user-disconnected').style.display = 'flex';
// document.getElementById('my-jokes').disabled = true;
changeDisabledPropertyForAllLikeBtn(true);
}
......
......@@ -12,9 +12,7 @@ const JOKES_LIMIT = 10;
export default {
init: () => {
// TODO events.listen(events.MY_JOKES_BTN_CLICKED, retreiveMyJokes);
events.listen([events.RANDOM_JOKES_BTN_CLICKED, events.LOGIN_SUCCEED], retreiveRandomJokes);
// TODO events.listen(events.BEST_JOKES_BTN_CLICKED, retreiveBestJokes);
events.listen(events.LAST_JOKES_BTN_CLICKED, retreiveLastJokes);
events.listen(events.LIKE_JOKE_BTN_CLICKED, likeJoke);
events.listen(events.DISLIKE_JOKE_BTN_CLICKED, dislikeJoke);
......@@ -90,9 +88,9 @@ function checkLike(data) {
const userEmail = login.getConnectedUserEmail();
data.forEach(joke => {
return fetch('//localhost:8080/api/v1/likes/' + userEmail + '/' + joke.id)
.then(response => response.text())
.then(response => response.json())
.then(result => {
if(result === 'true') {
if(result.isLiked) {
events.send(events.RETREIVE_LIKE_SUCCEED, { jokeId: joke.id});
}
});
......
......@@ -20,7 +20,6 @@ export default {
function login(data) {
console.log('Connecting...');
// TODO regex for mail
if (validateEmail(data.userEmail)) {
userEmail = data.userEmail;
events.send(events.LOGIN_SUCCEED, data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment