This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I find weird to copy/past real content of my Linux install and make it public. | |
| Therefore I am limiting this exercice to executing the 3 commands into my WCS folder... | |
| vmalep@L390Y:~/Documents/study/WildCodeSchool$ cd quests/ | |
| vmalep@L390Y:~/Documents/study/WildCodeSchool/quests$ ls | |
| hello-world my-super-website wild-git | |
| vmalep@L390Y:~/Documents/study/WildCodeSchool/quests$ pwd | |
| /home/vmalep/Documents/study/WildCodeSchool/quests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vmalep@L390Y:~/Documents/study/WildCodeSchool/quests/planets$ find | |
| . | |
| ./fictional | |
| ./fictional/coruscant.jpeg | |
| ./fictional/arrakis.jpeg | |
| ./fictional/cybertron.jpeg | |
| ./real | |
| ./real/terrestrial | |
| ./real/terrestrial/earth.jpeg | |
| ./real/terrestrial/neptune.jpeg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http') | |
| const url = require('url') | |
| const port = 8000 | |
| const requestHandler = (request, response) => { | |
| console.log(request.url) | |
| const current_url = new URL(request.url, 'http://localhost:8000') | |
| const search_params = current_url.searchParams | |
| const name = search_params.get('name') | |
| const city = search_params.get('city') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mysql> USE wild_db_quest; | |
| Reading table information for completion of table and column names | |
| You can turn off this feature to get a quicker startup with -A | |
| Database changed | |
| mysql> INSERT INTO school (name, country, capacity) | |
| -> VALUES ('Beauxbatons Academy of Magic', 'France', 550), | |
| -> ('Castelobruxo', 'Brazil', 380), | |
| -> ('Durmstrang Institute', 'Norway', 570), | |
| -> ('Hogwarts School of Witchcraft and Wizardry', 'United Kingdom', 450), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post('/api/users', (req, res) => { | |
| const { firstname, lastname, email } = req.body | |
| connection.promise().query( | |
| 'INSERT INTO users(firstname, lastname, email) VALUES (?, ?, ?)', | |
| [firstname, lastname, email],) | |
| .then(result=>res.status(201).send('User successfully saved') | |
| .catch(err=>res.status(500).send('Error saving the user')) | |
| ) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.put('/api/movies/:id', (req, res) => { | |
| const movieId = req.params.id | |
| const moviePropsToUpdate = req.body | |
| connection.promise().query( | |
| 'UPDATE movies SET ? WHERE id = ?', | |
| [moviePropsToUpdate, movieId],) | |
| .then(result=>res.status(200).send('Movie updated successfully 🎉')) | |
| .catch(err=>{ | |
| console.log(err) | |
| res.status(500).send('Error updating a movie') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.delete('/api/movies/:id', (req, res) => { | |
| const movieId = req.params.id; | |
| connection.promise().query( | |
| 'DELETE FROM movies WHERE id = ?', | |
| [movieId],) | |
| .then(result=>res.status(200).send('🎉 Movie deleted!')) | |
| .catch(err=>{ | |
| console.log(err) | |
| res.status(500).send('😱 Error deleting an movie') | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get('/api/movies', (req, res) => { | |
| let sql = 'SELECT * FROM movies' | |
| if(req.query.color === '1') { | |
| sql += ' WHERE color = 1' | |
| } | |
| if(req.query.max_duration){ | |
| const maxDuration = parseInt(req.query.max_duration) | |
| sql.includes('WHERE') ? sql += ' AND ' : sql += ' WHERE' | |
| sql += ` duration <= ${maxDuration}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post('/api/movies', (req, res) => { | |
| const { title, director, year, color, duration } = req.body | |
| connection.promise().query( | |
| 'INSERT INTO movies(title, director, year, color, duration) VALUES (?, ?, ?, ?, ?)', | |
| [title, director, year, color, duration]) | |
| .then(result => { | |
| const id = result.insertId | |
| const createdMovie = { id, title, director, year, color, duration } | |
| res.status(201).json(createdMovie) | |
| res.redirect('Movie successfully saved') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Queries: | |
| SELECT w.lastname, w.firstname, p.role, t.name | |
| FROM player AS p | |
| JOIN wizard AS w ON p.wizard_id=w.id | |
| JOIN team AS t ON p.team_id=t.id | |
| ORDER BY t.name, p.role, w.lastname, w.firstname; | |
| SELECT w.lastname, w.firstname | |
| FROM player AS p | |
| JOIN wizard AS w ON p.wizard_id=w.id |
OlderNewer