-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from FlorentMr/main
Final Version
- Loading branch information
Showing
94 changed files
with
27,379 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
# Projet Web 2020 : Electrip | ||
# Projet Web 2020/2021 : Electrip | ||
|
||
## Présentation | ||
|
||
Electrip à pour objectif de pouvoir organiser son emploi du temps incluant des trajets en voiture électrique. | ||
|
||
Quelques fonctionnalités : | ||
|
||
- Calcul d'arrêt en station de charge en fonction de l'autonomie | ||
- Sauvegarde et affichage des trajets et évènements dans un calendrier | ||
- Visualisation des trajets et des stations de charge associées sur une carte | ||
|
||
## Installation | ||
|
||
### Via Docker | ||
|
||
Une fois **Docker** installé sur votre machine, allez à la racine du projet puis : | ||
|
||
```shell | ||
sh start-docker.sh | ||
``` | ||
|
||
ou | ||
|
||
```shell | ||
docker-compose up --build --force-recreate | ||
``` | ||
|
||
Puis accès à l'application sur l'adresse : | ||
|
||
```http | ||
http://localhost:8080 | ||
``` | ||
|
||
Pour stopper l'application : | ||
|
||
```shell | ||
sh stop-docker.sh | ||
```` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM node:12 | ||
|
||
#Create app directory | ||
WORKDIR /usr/src/app/activities | ||
|
||
# Install app dependencies | ||
# A wildcard is used to ensure both package.json AND package-lock.json are copied | ||
# where available (npm@5+) | ||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
# If you are building your code for production | ||
# RUN npm ci --only=production | ||
|
||
COPY . . | ||
|
||
EXPOSE 7777 | ||
|
||
CMD [ "npm","run","serve"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const bodyParser = require('body-parser'); | ||
const express = require('express'); | ||
const mongoose = require('mongoose'); | ||
|
||
const app = express(); | ||
const activities = require('./routes/activities'); | ||
|
||
const DBNAME = "activities"; | ||
const HOST = "mongo_activities:27077"; | ||
const HOST_LOCAL = "localhost:27017"; | ||
|
||
mongoose.connect(`mongodb://${HOST}/${DBNAME}`, | ||
{ useNewUrlParser: true, | ||
useUnifiedTopology: true }) | ||
.then(() => console.log('Connexion à MongoDB réussie !')) | ||
.catch(() => console.log('Connexion à MongoDB échouée !')); | ||
|
||
app.use((req, res, next) => { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content, Accept, Content-Type, Authorization, x-access-token'); | ||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); | ||
next(); | ||
}); | ||
|
||
app.use(bodyParser.json()); | ||
|
||
app.use('/activities', activities); | ||
|
||
module.exports = app; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const Activity = require('../models/activities'); | ||
|
||
exports.getActivity = (req, res, next) => { | ||
Activity.findById(req.params.id) | ||
.then(things => res.status(200).json(things)) | ||
.catch(error => res.status(400).json({ error })); | ||
} | ||
|
||
exports.getActivities = (req, res, next) => { | ||
let userId = req.userId; | ||
Activity.find({userId: userId}) | ||
.then(activities => res.status(200).json(activities)) | ||
.catch(error => res.status(400).json({ error })); | ||
} | ||
|
||
exports.createActivity = (req, res, next) => { | ||
delete req.body._id; | ||
const activityJSON = {...req.body}; | ||
activityJSON['userId'] = req.userId; | ||
const activity = new Activity(activityJSON); | ||
activity.save() | ||
.then(() => res.status(201).json(activity)) | ||
.catch(error => res.status(400).json({ error })); | ||
} | ||
|
||
exports.modifyActivity = (req, res, next) => { | ||
Activity.findByIdAndUpdate(req.params.id, | ||
{ name: req.body.name, description: req.body.description, start: req.body.start, end: req.body.end, | ||
category: req.body.category, userId: req.body.userId}, {new: true}, | ||
function (err, result) { | ||
if (err) | ||
return res.status(400).json(err); | ||
else | ||
return res.status(201).json(result); | ||
} | ||
); | ||
}; | ||
|
||
exports.deleteActivity = (req, res, next) => { | ||
Activity.findByIdAndDelete(req.params.id, (err, result) => { | ||
if (err) | ||
return res.status(400).json(err); | ||
else | ||
return res.status(201).json({ message: "event successfully deleted!", result }); | ||
}) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const jwt = require('jsonwebtoken'); | ||
|
||
module.exports = (req, res, next) => { | ||
let token = req.headers["x-access-token"]; | ||
|
||
if (!token) { | ||
return res.status(403).send({ | ||
message: "No token provided!" | ||
}); | ||
} | ||
jwt.verify(token, 'SHINGEKINOKYOJIN',(err, decoded) => { | ||
if (err) { | ||
return res.status(401).send({ | ||
message: "Unauthorized!" | ||
}); | ||
} | ||
req.userId = decoded; | ||
next(); | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const activitySchema = mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: false }, | ||
start: { type: String, required: true }, | ||
end: { type: String, required: false }, | ||
category: { type: String, required: true }, | ||
userId: { type: String, required: true }, | ||
}); | ||
|
||
module.exports = mongoose.model('Activity', activitySchema); |
Oops, something went wrong.