Giter Site home page Giter Site logo

fac-11 / thelibrary Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 412 KB

THE centralised resource of useful weblinks for FAC

Home Page: https://thefaclibrary.herokuapp.com/

License: GNU General Public License v3.0

HTML 9.74% JavaScript 60.19% PLpgSQL 20.56% CSS 9.52%

thelibrary's Introduction

theLibrary โšก

A centralised postgresql resource for FAC

Coverage: 90% Statements 18/20, 62.5% Branches 5/8, 100% Functions 0/0, 100% Lines 18/18

Requirements

  • Simple web app with a node server and a database
  • Your database comes with a schema, which should be documented in your readme (along with any other architectural decisions)
  • Database hosted on Heroku, or locally
  • Build script for your database
  • Security concerns appropriately considered (you must protect against script injections!)
  • Good test coverage both server- and client-side
  • Content dynamic, but DOM manipulation kept to a minimum
  • Mobile-first design
  • Clear user journey (even if you take one of our suggested ideas, document the user journey in your readme)

User story

I can pick a topic and find a bunch of rad online resources with an article title, print data and link ๐Ÿ”—

On load I can find out about the coolest articles peeps are raving about ๐Ÿ†’ ๐Ÿ†’ ๐Ÿ†’

Planning: architecture and flow

We planned out our flow as follows:

And wanted it to look like this:

Database Schema

resources ๐Ÿ“š

Column Type Modifier
id serial PRIMARY KEY
title VARCHAR(300) NOT NULL
link VARCHAR(300) NOT NULL
publish_month INTEGER
publish_year INTEGER
upvotes INTEGER DEFAULT 0

topics ๐Ÿ’ป

Column Type Modifier
id serial PRIMARY KEY
topic VARCHAR(300) NOT NULL
week INTEGER

resources_topics ๐Ÿ“‘

Column Type Modifier
resource_id INTEGER REFERENCES resources(id) ON UPDATE CASCADE
topic_id INTEGER REFERENCES topics(id) ON UPDATE CASCADE

What we decided on and how we decided to do it

Cool learnings

  • Turns out sql hates capital letters! You can't name databases with caps ๐Ÿ˜ฟ
  • ALSO atom is a thief! ๐Ÿš” And sometimes steals your letters from terminal
  • Writing tests within a foreach loop which take a callback ๐Ÿ˜จ
const topicArray = ['Javascript', 'CSS', 'Node', 'Databases', 'Accessibility', 'Git', 'TDD', 'HTTP', 'APIs', 'Callbacks', 'Software Architecture', 'Servers', 'Development Methodologies', 'HTML', 'UX'];
topicArray.forEach((topic) => {
  tape(`getTopic ${topic} query`, (t) => {
    getTopic(topic, (err, res) => {
      const actual = res[0].topic;
      const expected = topic;
      t.equals(actual, expected, `getTopic object output topic should be ${topic}`);
      t.end();
    });
  });
});
  • Pushing to heroku from a local branch:

git push heroku yourbranch:master

Good links

thelibrary's People

Contributors

ameliejyc avatar astroash avatar bartbucknill avatar maxgerber avatar

Watchers

 avatar  avatar  avatar

thelibrary's Issues

Set up file structure

Folder database

  • db_connection.js
  • db_build.js
  • db_build.sql

Folder public

  • style.css
  • index.html
  • dom.js
  • request.js
  • Folder assets > favicon.ico

Folder tests

  • Folder tests_ database (duplicate of database folder)
  • database.test.js
  • src.test.js
  • public.test.js

Folder src

  • server.js
  • router.js
  • handlers.js
  • get_topic.js
  • get_trending.js

In ROOT

  • .gitignore (config.env, node_modules, ds_store)
  • travis.yml
  • config.env
  • Procfile

Create index.html

Create html doc.

Mobile first!

Doc should have grabable id's for js

Another SG for you!

Another stretch goal would be to add all the existing books in there in a table with possibility to request renting them, plus seeing which ones exist but are currently rented and stuff :-)

Create handle_topic.js

Create file with getTopic function which takes a string and a callback.

Function will have to create a sql query with the string, then call dbConnection with the query string and pass the response to the callback

Add travis badge

They're cool :)
if you click on the badge that shows up on the travis site it will give you an image url you can add to your readme

Create dom.js

Dom function will take in an object and append each resource as a button.
It will clear the current content.
It will replace the title eg Trending will become css

RUN ISTANBUL

Do test coverage and add the badge to the readme <3

no description of how to run the database locally in your readme

This may not have been explicitly stated to you guys, but it's really important that you have instructions in your readme that explain how to run your project locally.

In the case where you have a database in your project, you want to instruct people on:

  • creating their database locally
  • what environment variables they need to set
  • what scripts they should run

etc.

Trending title no longer displayed

With the removal of topic titles, we no longer have a way of signifying the front page is the trending section.

I've no suggestions at the moment as the title removal looks great, but worth thinking about how to incorporate it into the design :)

refactor out DOM function

Currently the DOM function is very large! Some of the code can be refactored into separate functions eg setClassAttributes, and called inside for ease of reading.

Create XHR request function

in request.js create an xhr request function that take a string value and a callback as arguments.

The function will feed the string into the url and pass the response text to the callback.

Integrate with GitHub

This will allow us to make sure each individual only upvotes the one time amongst other things - possible integration with Gitter being one of them.

Set up node dependencies / dev dependencies

Project dependencies
env2
pg

Dev dependencies
tape
tap-spec
nodemon
istanbul
shot
eslint
travis

Add in scripts
tests: 'tape tests/*.test.js | tap-spec'
start: 'node ./src/server.js'
devstart: 'nodemon ./src/server.js'

move into `foundersandcoders` organisation

Given that you're building on this during biz dev time & intending for FAC to actually use this, could you move it into the foundersandcoders github organisation? ๐Ÿ™

Just go to Settings -> ("Danger Zone" at the bottom) -> Transfer ownership -> Type in theLibrary & foundersandcoders

Create handlers.js

Handlers will have 4 routes

  • handle home
  • handle public
  • handle topic
  • handle trending

Create event listener

When user clicks on a topic on the site, an event listener will call the xhr function and pass in the dropdown value string.

in tests: dbConnection.query is async

(me and Aisha discussed this)

Because .query is async, maybe each test should be inside the callback e.g.

dbConnection.query(sql, (err, res) => {
  if (err) return console.log(err);
  tape('SQL query case check', (t) => {
    getTopic('css', (err, res) => {
      const actual = res[0].topic;
      const expected = 'CSS';
      t.equals(actual, expected, 'getTopic object output topic should be "CSS" as the SQL query string is case insensitive');
      t.end();
    });
});
});

https://github.com/FAC-11/theLibrary/blob/master/tests/database.test.js#L8

Create router.js

Create a router which is server handlers according to endpoints.

allow upvoting

Add a like button to articles which updates the database and sends back the current state of database for the page you are on

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.