mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-09 10:30:17 +01:00
changement du stockage des notes autres
This commit is contained in:
@@ -2,6 +2,8 @@ import { Auteur, Review } from './structures.js';
|
||||
import conn from '../database.js';
|
||||
import {getSourceId} from '../utils.js';
|
||||
|
||||
//TODO: Changer la manière dont les notes autres son stoquées, avoir une table qui a la liste des notes, une table avec les enregistrements
|
||||
|
||||
/**
|
||||
* Ajoute un nouvel auteur de commentaire a la BDD, auteur doit être une instance de Auteur
|
||||
* @param {Auteur} author L'auteur a ajouter
|
||||
@@ -20,6 +22,21 @@ const addAuteur = (author) => {
|
||||
})
|
||||
}
|
||||
|
||||
//Ajoute une note sur un critère spécifique
|
||||
const addSpecificRating = (reviewId, label, value) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const sql = "INSERT INTO borne_notes_autre(critere_id, avis_id, valeur) VALUES ((SELECT id FROM borne_criteres WHERE borne_criteres.nom = ?), ?, ?)"
|
||||
console.log(sql);
|
||||
conn.query(sql, [label,reviewId, value], (err, res) => {
|
||||
if(err) {
|
||||
reject(err);
|
||||
}else {
|
||||
resolve(res.insertId);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//Ajoute un avis a la base de donnée
|
||||
/**
|
||||
@@ -31,8 +48,8 @@ const addAuteur = (author) => {
|
||||
*/
|
||||
const addReview = (review, authorId, sourceId) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const sql = "INSERT INTO borne_auteurs (id_auteur, note_principale, notes_autre, commentaire, source_id) VALUES (?);"
|
||||
conn.query(sql, [[authorId, review.note, JSON.stringify(review.notesAutre), review.commentaire, sourceId]], (err, res) => {
|
||||
const sql = "INSERT INTO borne_avis (id_auteur, note_principale, commentaire, source_id) VALUES (?);"
|
||||
conn.query(sql, [[authorId, review.note, review.commentaire, sourceId]], (err, res) => {
|
||||
if(err) {
|
||||
reject(err)
|
||||
}else {
|
||||
@@ -59,7 +76,10 @@ export const addReviewFromRequest = async (req,res) => {
|
||||
const review = new Review(author, req.body.note, req.body.source, req.body.commentaire, notes_autre)
|
||||
let authorId = await addAuteur(author);
|
||||
let sourceId = await getSourceId(review.source);
|
||||
await addReview(review, authorId, sourceId );
|
||||
let reviewId = await addReview(review, authorId, sourceId );
|
||||
for(let label in review.notesAutre) {
|
||||
await addSpecificRating(reviewId, label, review.notesAutre[label]);
|
||||
}
|
||||
res.send("success")
|
||||
}catch(err) {
|
||||
res.status(500).send("Error : " + err.message)
|
||||
|
||||
@@ -5,12 +5,12 @@ avis = {
|
||||
"source": "borne",
|
||||
#Optionel
|
||||
"auteur_age": 20,
|
||||
"notes_autre": '{"service":8,"accueil":10}',
|
||||
"notes_autre": '{"proprete":8,"calme":10}',
|
||||
"auteur_sexe": 'f',
|
||||
"commentaire": "Commentaire"
|
||||
}
|
||||
|
||||
# res = requests.post("http://localhost:8080/add_review", data=avis)
|
||||
res = requests.post("http://localhost:8080/add_review", data=avis)
|
||||
# print(res.text)
|
||||
|
||||
#Exemple ajout d'un commentaire trouvé sur les réseaux sociaux
|
||||
@@ -25,5 +25,5 @@ avis = {
|
||||
"auteur_lien": "https://instagram.com/michel",
|
||||
}
|
||||
|
||||
res = requests.post("http://localhost:8080/add_social_review", data=avis)
|
||||
# res = requests.post("http://localhost:8080/add_social_review", data=avis)
|
||||
print(res.text)
|
||||
@@ -3,7 +3,7 @@
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: localhost:3306
|
||||
-- Generation Time: Dec 25, 2022 at 06:12 PM
|
||||
-- Generation Time: Dec 25, 2022 at 09:49 PM
|
||||
-- Server version: 8.0.31-0ubuntu0.20.04.1
|
||||
-- PHP Version: 7.4.3
|
||||
|
||||
@@ -45,13 +45,45 @@ CREATE TABLE `borne_avis` (
|
||||
`id_auteur` int NOT NULL,
|
||||
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`note_principale` tinyint NOT NULL,
|
||||
`notes_autre` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'Notes spécifiques au format JSON',
|
||||
`commentaire` text NOT NULL,
|
||||
`source_id` int NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `borne_criteres`
|
||||
--
|
||||
|
||||
CREATE TABLE `borne_criteres` (
|
||||
`id` int NOT NULL,
|
||||
`nom` text NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `borne_criteres`
|
||||
--
|
||||
|
||||
INSERT INTO `borne_criteres` (`id`, `nom`) VALUES
|
||||
(1, 'proprete'),
|
||||
(2, 'calme'),
|
||||
(3, 'attente');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `borne_notes_autre`
|
||||
--
|
||||
|
||||
CREATE TABLE `borne_notes_autre` (
|
||||
`id` int NOT NULL,
|
||||
`critere_id` int NOT NULL,
|
||||
`avis_id` int NOT NULL,
|
||||
`valeur` int NOT NULL COMMENT 'Note sur 10'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `reseaux_sociaux_auteurs`
|
||||
--
|
||||
@@ -125,12 +157,12 @@ CREATE TABLE `stats_annee` (
|
||||
CREATE TABLE `stats_jour` (
|
||||
`id` int NOT NULL,
|
||||
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`moyenne_globale` float NOT NULL,
|
||||
`moyenne_site` float NOT NULL,
|
||||
`moyenne_borne` float NOT NULL,
|
||||
`moyenne_autres` text NOT NULL COMMENT 'Nombres séparés par des ; => moyennes spécifiques',
|
||||
`dist_age` text NOT NULL COMMENT 'Distribution de l''age des auteurs',
|
||||
`dist_sexe` text NOT NULL COMMENT 'Distribution du sexe des auteurs'
|
||||
`moyenne_globale` float DEFAULT NULL,
|
||||
`moyenne_site` float DEFAULT NULL,
|
||||
`moyenne_borne` float DEFAULT NULL,
|
||||
`moyenne_autres` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Nombres séparés par des ; => moyennes spécifiques',
|
||||
`dist_age` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Distribution de l''age des auteurs',
|
||||
`dist_sexe` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Distribution du sexe des auteurs'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
@@ -183,6 +215,18 @@ ALTER TABLE `borne_auteurs`
|
||||
ALTER TABLE `borne_avis`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `borne_criteres`
|
||||
--
|
||||
ALTER TABLE `borne_criteres`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `borne_notes_autre`
|
||||
--
|
||||
ALTER TABLE `borne_notes_autre`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `reseaux_sociaux_auteurs`
|
||||
--
|
||||
@@ -241,6 +285,18 @@ ALTER TABLE `borne_auteurs`
|
||||
ALTER TABLE `borne_avis`
|
||||
MODIFY `id` int NOT NULL AUTO_INCREMENT;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `borne_criteres`
|
||||
--
|
||||
ALTER TABLE `borne_criteres`
|
||||
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `borne_notes_autre`
|
||||
--
|
||||
ALTER TABLE `borne_notes_autre`
|
||||
MODIFY `id` int NOT NULL AUTO_INCREMENT;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `reseaux_sociaux_auteurs`
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user