Skip to content

Commit

Permalink
movies
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-Scetbon committed Nov 14, 2021
0 parents commit a70091d
Show file tree
Hide file tree
Showing 1,290 changed files with 173,988 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
1 change: 1 addition & 0 deletions .~lock.a_lire.odt#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,fabien,fabien-zenbook,11.11.2021 11:16,file:///home/fabien/snap/libreoffice/236/.config/libreoffice/4;
Binary file added JS_Ajax.pdf
Binary file not shown.
Binary file added a_lire.odt
Binary file not shown.
96 changes: 96 additions & 0 deletions db_connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Tuto ici : https://expressjs.com/en/starter/hello-world.html
// https://www.w3schools.com/nodejs/nodejs_mysql.asp

var express = require('express')
var app = express()

var mysql = require('mysql')
var con = mysql.createConnection({
host: 'localhost',
user: 'fabino',
password: 'MonopolI',
database: 'movies',
})

con.connect(function (err) {
if (err) throw err
console.log('Connected!')
})

var cors = require('cors')
app.use(
cors({
origin: "*",
})
);

// respond with "hello world" when a GET request is made to the homepage
app.get('/', function (req, res) {
res.send('hello world')
})

// get 20 first movies
app.get('/api/movies', function (req, res) {
con.query(
'SELECT * FROM movies LIMIT 20;',
function (err, result) {
if (err) throw err
res.send(result);

}
)
})

// get all movies for search in
app.get('/api/allmovies', function (req, res) {
con.query('SELECT * FROM movies;', function (err, result) {
if (err) throw err
res.send(result)
})
})


app.get('/api/genres', function (req, res) {
con.query(
'SELECT * FROM genres;',
function (err, result) {
if (err) throw err
res.send(result);
}
)
})

app.get('/api/producers', function (req, res) {
con.query(
'SELECT id,name FROM producers;',
function (err, result) {
if (err) throw err
res.send(result);
}
)
})

app.get('/api/movies/:id', function (req, res) {
con.query("SELECT * FROM movies WHERE id =" + req.params['id'], function (err, result) {
if (err) throw err;
res.send(result);
});
})

app.get('/api/movies/:id/genres', function (req, res) {
con.query("SELECT name FROM genres WHERE id IN (SELECT genre_id FROM movies WHERE id = " + req.params['id'] + " );", function (err, result) {
if (err) throw err;
res.send(result);
});
})

app.get('/api/movies/:id/producers', function (req, res) {
con.query("SELECT name FROM producers WHERE id IN (SELECT producer_id FROM movies WHERE id = " + req.params['id'] + " );", function (err, result) {
if (err) throw err;
res.send(result);
});
})

app.listen(8000, () => {
console.log("Serveur à l'écoute")
})
26 changes: 26 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css"/>
<title>Movies App</title>
</head>
<body>

<header>
<h1 class="title">My Movies</h1>
<form id="form">
<input type="text" id="search" class="search" placeholder="Search">
</form>
</header>
<div class="decal"></div>

<main id="main">

</main>

<script type= "text/javascript" src="script.js"></script>
</body>
</html>
Loading

0 comments on commit a70091d

Please sign in to comment.