Refactor/route separation #21

Merged
KevinMidboe merged 26 commits from refactor/routeSeparation into master 2020-09-06 14:00:12 +00:00
KevinMidboe commented 2020-08-26 22:43:46 +00:00 (Migrated from github.com)

Idea

The idea here is to make it more clear what routes we have and what functions they depend on. This moves routers for each endpoint from server.js and replaces it with apiRouter where all routes are explicitly defined with the functions they use in a single place.

Example

/api/router.js should define :

const lottery = require(__dirname + "lottery.js");

router.get("/lottery/by-name/:name", lottery.byName);
router.get("/lottery/by-date/:date", lottery.byEpochDate);

and lottery.js defined and exports it's functions by:

const byName = (req, res) => { ... };
const byEpochDate = (req, res) => { ... };

module.exports = { byName, byEpochDate };

Progress

  • app.js for storing all api endpoints and map to their respective file functions.
  • No longer export Routers in /api/*.js files, but functions that are used in the unified app.js router.
    • updateApi (/api/update.js)
    • retrieveApi (/api/retrieve.js)
    • wineInfoApi (/api/wineinfo.js)
    • lotteryApi (/api/lottery.js)
    • virtualRegistrationApi (/api/virtualRegistration.js)

Changes

Backend

  • /api/router.js is a single file for apiRoutes, all other js files in /api now only return functions. 51a7107, a6a84e4, ec80aa8, 262efa0 & 1d714d1
  • More ways to submit lottery (by wine, lottery or winners). 7e08e2d
  • io is not registered globally w/ app.set('socketio'). fd17e11
  • Removed deprecated npm package requests. f6c1e35 & 20dd638
  • Api calls in /api/messages.js no longer use requests npm package, but node's built in https, also messages has clearer function names and always return Promises. 4f054a0.

Frontend

  • New positioning.scss for alignment. Currently only defines .flex and .flex-column. 8268efe
  • New global.scss css class for using .column with .button-container for alignment. 7684fde
  • Frontend router moved from /src/routes/vinlottisRouter.js to /src/router.js. a30dc2a
  • Renamed /api.js endpoints to reflect changes in backend. 6dc4c90
  • Vin buttons text aligned better. ef035d3
  • Winners are flex wrapped to not overflow on smaller screens. 55b3552
  • Winner selecting wine page now has some padding to give more air between screen and elements. c1f0a1b
  • Adding attendees now show toast, instead of alert. ec1685d
  • /src/utils.js w/ function for converting date to given format (YY-MM-DD) using Intl.DateTimeFormat. a7f4f9a
## Idea The idea here is to make it more clear what routes we have and what functions they depend on. This moves routers for each endpoint from `server.js` and replaces it with apiRouter where all routes are explicitly defined with the functions they use in a single place. ## Example `/api/router.js` should define : ```js const lottery = require(__dirname + "lottery.js"); router.get("/lottery/by-name/:name", lottery.byName); router.get("/lottery/by-date/:date", lottery.byEpochDate); ``` and `lottery.js` defined and exports it's functions by: ```js const byName = (req, res) => { ... }; const byEpochDate = (req, res) => { ... }; module.exports = { byName, byEpochDate }; ``` ## Progress - [x] app.js for storing all api endpoints and map to their respective file functions. - [x] No longer export Routers in /api/*.js files, but functions that are used in the unified app.js router. - [x] `updateApi` (/api/update.js) - [x] `retrieveApi` (/api/retrieve.js) - [x] `wineInfoApi` (/api/wineinfo.js) - [x] `lotteryApi` (/api/lottery.js) - [x] `virtualRegistrationApi` (/api/virtualRegistration.js) ## Changes ### Backend - `/api/router.js` is a single file for apiRoutes, all other js files in `/api` now only return functions. [51a7107](https://github.com/KevinMidboe/vinlottis/commit/51a7107802b263232d7b07cbceeb6af249a4bef7), [a6a84e4](https://github.com/KevinMidboe/vinlottis/commit/a6a84e4b293c9b2fda4af95f1834dc0479ca0285), [ec80aa8](https://github.com/KevinMidboe/vinlottis/commit/ec80aa8bccdd9c83cb941af358160233b70240eb), [262efa0](https://github.com/KevinMidboe/vinlottis/commit/262efa03807bc69b398855964d74551ee8291a4a) & [1d714d1](https://github.com/KevinMidboe/vinlottis/commit/1d714d1e5a62c9437a53645af722470c58438cc8) - More ways to submit lottery (by wine, lottery or winners). [7e08e2d](https://github.com/KevinMidboe/vinlottis/commit/7e08e2d62888820298f2a6be117bae6e8142e259) - `io` is not registered globally w/ `app.set('socketio')`. [fd17e11](https://github.com/KevinMidboe/vinlottis/commit/fd17e11e8703b9ea96464562b881282131fff6bb) - Removed deprecated npm package `requests`. [f6c1e35](https://github.com/KevinMidboe/vinlottis/commit/f6c1e351802526a0d93d6d21e30a529e30f05732) & [20dd638](https://github.com/KevinMidboe/vinlottis/commit/20dd63813302a7dcfa9fd6903b7da198e260e6c4) - Api calls in `/api/messages.js` no longer use `requests` npm package, but node's built in `https`, also messages has clearer function names and always return Promises. [4f054a0](https://github.com/KevinMidboe/vinlottis/commit/4f054a0437ac4c85f865b7525dba1694b5f7d219). ### Frontend - New `positioning.scss` for alignment. Currently only defines `.flex` and `.flex-column`. [8268efe](https://github.com/KevinMidboe/vinlottis/commit/8268efe62519b456f2e42c25c8d0b30968ba1c93) - New global.scss css class for using `.column` with `.button-container` for alignment. [7684fde](https://github.com/KevinMidboe/vinlottis/commit/7684fde8e5705f8e07a0ea35446114a5b12b8826) - Frontend router moved from `/src/routes/vinlottisRouter.js` to `/src/router.js`. [a30dc2a](https://github.com/KevinMidboe/vinlottis/commit/a30dc2a4195e64ae76ee48887a20af3c85c9292a) - Renamed `/api.js` endpoints to reflect changes in backend. [6dc4c90](https://github.com/KevinMidboe/vinlottis/commit/6dc4c9080eafe4d883eb8f9116b2c99027d56aae) - Vin buttons text aligned better. [ef035d3](https://github.com/KevinMidboe/vinlottis/commit/ef035d3c44ff151a34df4e941e03f263dd60b74f) - Winners are flex wrapped to not overflow on smaller screens. [55b3552](https://github.com/KevinMidboe/vinlottis/commit/55b3552786fae2422f8c9565f61dfadf5905d7ef) - Winner selecting wine page now has some padding to give more air between screen and elements. [c1f0a1b](https://github.com/KevinMidboe/vinlottis/commit/c1f0a1b7f38a581fe8b3ca9ff661c2f5a57d7f0b) - Adding attendees now show toast, instead of alert. [ec1685d](https://github.com/KevinMidboe/vinlottis/commit/ec1685dfa8abe83371a278f1b940321840d2443c) - `/src/utils.js` w/ function for converting date to given format (YY-MM-DD) using `Intl.DateTimeFormat`. [a7f4f9a](https://github.com/KevinMidboe/vinlottis/commit/a7f4f9af272be03a6f0b1443a17ff22e3659b321)
Sign in to join this conversation.
No description provided.