diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..f5b17dba --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,29 @@ +module.exports = { + "env": { + "browser": true, + "commonjs": true, + "es2021": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 12 + }, + "rules": { + "indent": [ + "error", + 4 + ], + "linebreak-style": [ + "error", + "windows" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ] + } +}; diff --git a/backend/controllers/workshop.js b/backend/controllers/workshop.js new file mode 100644 index 00000000..6c5d7193 --- /dev/null +++ b/backend/controllers/workshop.js @@ -0,0 +1,65 @@ +const ejs = require("ejs"); + +const InMemoryWorkshop = require("../models/inMemoryWorkshop"); + +exports.createNewWorkshop = function (req, res) { + const name = req.body.name; + const description = req.body.description; + InMemoryWorkshop.addWorkshop(name, description).then(() => { + InMemoryWorkshop.getWorkshopList() + .then(() => { + res.redirect("/workshops"); + }); + }) + .catch(e =>res.send(e.message)); +}; + +exports.printWorkshops = function (req, res) { + InMemoryWorkshop.getWorkshopList() + .then(workshops => { + res.render("index", { + workshops: workshops + }); + }); +}; + +exports.getCreateWorkshopView = function (req, res) { + res.render("workshop"); +}; + +exports.removeWorkshop = function (req, res) { + const name = req.params.name; + InMemoryWorkshop.removeWorkshopByName(name) + .then(() => { + res.redirect("/workshops"); + }) + .catch(error => res.status(400).send(error.message)); +}; + +exports.updateWorkshop = function(req, res) { + InMemoryWorkshop.updateWorkshop(req.params.name, req.body.name, req.body.description) + .then(() => { + res.redirect("/workshops"); + }) + .catch(error => res.status(400).send(error.message)); +}; + +exports.getUpdateWorkshopView = function (req, res) { + const name = req.params.name; + InMemoryWorkshop.getWorkshopByName(name) + .then(workshop => { + res.render("updateWhorkshop", { + workshop: workshop + }); + }) + .catch(error => res.status(400).send(error.message + "ici")); +}; + +exports.getWorkshopViewByName = function (req, res) { + const workshopName = req.params.name; + InMemoryWorkshop.getWorkshopByName(workshopName) + .then(workshop => { + res.render("ejs/workshop", workshop); + }) + .catch(e =>ejs.send(e.message)); +}; \ No newline at end of file diff --git a/backend/models/inMemoryWorkshop.js b/backend/models/inMemoryWorkshop.js new file mode 100644 index 00000000..e896e293 --- /dev/null +++ b/backend/models/inMemoryWorkshop.js @@ -0,0 +1,77 @@ +let inMemoryWorkshop = []; +inMemoryWorkshop.push({name: "w1", description: "d1"}); +inMemoryWorkshop.push({name: "w2", description: "d2"}); +inMemoryWorkshop.push({name: "w3", description: "d3"}); + + +function getWorkshopList() { + return new Promise((resolve, ) => { + resolve(inMemoryWorkshop); + }); +} + +function getWorkshopByName(name) { + return new Promise((resolve, reject) => { + if (!name) { + reject(new Error("name parameter is required")); + } + resolve(inMemoryWorkshop.find(workshop => workshop.name === name)); + }); +} + +function addWorkshop(name, description) { + return new Promise((resolve, reject) => { + if (!name) { + reject(new Error("Workshop name required")); + } + if (!description) { + reject(new Error("Workshop description required")); + } + inMemoryWorkshop.push({ + name, + description + }); + resolve(); + }); +} + +function removeWorkshopByName(name) { + return new Promise((resolve, reject) => { + if (!name) { + reject(new Error("workshop name required")); + } + let i=0; + for (i=0; i { + if (!name) + reject(new Error("name is required for updating workshop")); + for (let i=0; i -Workshops - - - diff --git a/ejs/index.ejs b/ejs/index.ejs deleted file mode 100644 index 3ee3a884..00000000 --- a/ejs/index.ejs +++ /dev/null @@ -1,31 +0,0 @@ - - - - - <% include ./head %> - - - -
-

Workshops

-

here is the list of workshop

-
- -Create new workshop - - -<% workshops.forEach(function(workshop) { %> -
  • -
    -
    <%= workshop.name %>
    - <%= workshop.description %>
    -
  • -<% }); %> - - -
    - <% include ./footer %> -
    - - - diff --git a/css/bootstrap.min.css b/frontend/css/bootstrap.min.css similarity index 100% rename from css/bootstrap.min.css rename to frontend/css/bootstrap.min.css diff --git a/css/index.css b/frontend/css/index.css similarity index 100% rename from css/index.css rename to frontend/css/index.css diff --git a/css/workshop.css b/frontend/css/workshop.css similarity index 100% rename from css/workshop.css rename to frontend/css/workshop.css diff --git a/ejs/footer.ejs b/frontend/ejs/footer.ejs similarity index 100% rename from ejs/footer.ejs rename to frontend/ejs/footer.ejs diff --git a/frontend/ejs/head.ejs b/frontend/ejs/head.ejs new file mode 100644 index 00000000..7e23e3e8 --- /dev/null +++ b/frontend/ejs/head.ejs @@ -0,0 +1,6 @@ + +Workshops + + + + diff --git a/frontend/ejs/index.ejs b/frontend/ejs/index.ejs new file mode 100644 index 00000000..84d16990 --- /dev/null +++ b/frontend/ejs/index.ejs @@ -0,0 +1,36 @@ + + + + + <% include ./head %> + + + +
    +

    Workshops

    +

    here is the list of workshop

    +
    + +Create new workshop + + + +
    + <% include ./footer %> +
    + + + diff --git a/frontend/ejs/updateWhorkshop.ejs b/frontend/ejs/updateWhorkshop.ejs new file mode 100644 index 00000000..c370c785 --- /dev/null +++ b/frontend/ejs/updateWhorkshop.ejs @@ -0,0 +1,27 @@ + + + + + <% include ./head %> + + + +
    +
    + + +
    +
    + + +
    + + Cancel +
    + +
    + <% include ./footer %> +
    + + + diff --git a/ejs/workshop.ejs b/frontend/ejs/workshop.ejs similarity index 84% rename from ejs/workshop.ejs rename to frontend/ejs/workshop.ejs index 43ffe1f6..a90f0487 100644 --- a/ejs/workshop.ejs +++ b/frontend/ejs/workshop.ejs @@ -6,7 +6,7 @@ -
    +
    @@ -16,7 +16,7 @@
    - Cancel + Cancel