/week8-pbok

See FAC's BiblioTech!

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

FAC BiblioTech

by PBOK



So you want to install me??

  • clone repo
  • run npm install
  • ask us for the super secret env deets
  • run npm start

TRAV IS WHO???

codecov


HEROKU

  • Heroku tries to run npm start
  • we already had a start script in our package.json


  • to override this, we created a Procfile

  • with the below bit of code:


SCHEMA


ACCESSIBILITY


WIREFRAMES


USER FLOW


DESIGN


MVC ARCHITECTURE


SERVER ARCHITECTURE


CONTROLLA

// post request to add new resource to database library
exports.post = (request, response) => {
    let { title, language, description, link } = request.body;
    db.addResource(title, language, description, link, (err, res) => {
        if (err) {
            throw err;
        }
})
response.redirect('/');
};)

ADD RESOURCE TO LIBRARY

const addResource = (title, language, description, link, cb) => {
  db.query(`INSERT INTO resources(title, language, description, link) VALUES ($1, $2, $3, $4)`,
  [title, language, description, link],
  (err, result) => {
    if (err) return cb(err);
    cb(null, result);
  });
}

module.exports = {
  getAll,
  filterByLanguage,
  addResource
};

FILTERING BY LANG

router.post('/filter-language', (req, res) => {
    res.redirect(`/library/${req.body.language}`);
});
router.get('/library/:language', library.filterLanguage);
exports.filterLanguage = (request, response) => {
    let language = request.params.language;
    filterByLanguage(language, (err, res) => {
        if (err) console.log(err);
        const filterRows = res;
        response.render("filter", { filterRows });
    })
};

const filterByLanguage = (language, cb) => {
  db.query(`SELECT * FROM resources WHERE language=$1`,
  [language],
  (err, result) => {
    if (err) return cb(err);
    cb(null, result.rows);
  });
}
{{#each filterRows}}
    <tr>
        <td class="table-data">{{language}}</td>
        <td class="table-data">{{title}}</td>
        <td class="table-data">{{description}}</td>
        <td class="table-data"><a href="{{link}}" alt="link to resource" target="_blank" title="{{link}}">{{link}}</a></td>
    </tr>
{{/each}}

DATABASE AND ROUTE TESTING


NICE THINGS WE'VE ACHIEVED:

  • Mobbing + working as a team
  • No HTML pages at all
  • Filtering option!
  • Modularise our code (a bit...)

IF WE WERE TO DO IT AGAIN

or continue working on it

  • Create and use custom helpers
  • Do more tests
  • Keep up the team work (woohoo!)