Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/collection pages refactor #215

Merged
merged 13 commits into from
Aug 19, 2021

Conversation

alexanderleegs
Copy link
Contributor

This PR introduces a new set of endpoints for collection pages, as part of our ongoing refactor for the CMS.

Introduced in this PR:

  • Addition of Joi library for request body schema validation
  • Set of v2 endpoints for collection page CRUD operations
    • In V2, the route layer only parses requests and passes the parameters to a Controller class
  • A CollectionController class, which handles both third nav and collection page operations
  • Individual CollectionPage and ThirdNavPage service classes which handle the actual implementation details of page operations
  • Github operations have been moved into a separate service class which interacts with github api
  • Util functions and classes for markdown files and collection.yml files

@kwajiehao kwajiehao self-requested a review August 10, 2021 07:31

const GitHubService = require("@services/db/GitHubService")
const CollectionPageService = require("@services/fileServices/MdPageServices/CollectionPageService")
const ThirdNavPageService = require("@services/fileServices/MdPageServices/ThirdNavPageService")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename ThirdNavPageService to SubCollectionPageService for clarity? What do y'all think?

Copy link
Contributor

@kwajiehao kwajiehao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

I have a slightly unrelated comment: the current refactor document is sprawling and it's a little hard to see what the plan is, and thus whether we're implementing this according to our plan - I was thinking that having a new document with our finalized backend structure + diagram with the updated controller hierarchy might be helpful. What do y'all think? @prestonlimlianjie @alexanderleegs

@prestonlimlianjie
Copy link
Contributor

Lgtm!

I have a slightly unrelated comment: the current refactor document is sprawling and it's a little hard to see what the plan is, and thus whether we're implementing this according to our plan - I was thinking that having a new document with our finalized backend structure + diagram with the updated controller hierarchy might be helpful. What do y'all think? @prestonlimlianjie @alexanderleegs

Let's do it!

alexanderleegs and others added 13 commits August 19, 2021 11:47
* Refactor: Githubservice into class

* Refactor: dependency injection for services

* Refactor: dependency injection for controller

* Refactor: router into class

* Refactor: initialisation of services in server

* Fix: standardise returned object parameter names in third nav page service

* Refactor: use axiosInstance as a dependency injection for githubService

* Fix: standardise new files being added to top of the order

* Fix: allow empty page body in schema

* Fix: retrieve router

* Fix: throw appropriate error for bad requests

* Fix: change expected request body for create and update to match object returned

* Fix: update rename collection and third nav pages to not reorder collection.yml

* Fix: update schema to allow blank new name

* Chore: suppress log statements in test environment

* Nit: rename third nav to subcollection

* fix: small change in RequestSchema structure

* style: convert to camel case (#253)

* style: move file to validators folder

* style: rename GitHubService methods to camel case

* style: rename CollectionYmlService methods to camel case

* style: rename NavYmlService methods to camel case

* style: rename SubcollectionPageService methods to camel case

* style: rename CollectionPageService methods to camel case

* style: rename CollectionController methods to camel case

* style: rename collectionPages methods to camel case

* style: update import alias for validators

* style: renaming method that was previously missed

* Chore: install auto-bind

* Fix: replace manual binding with autoBind

* Fix: remove unused variables in GItHubService

* style: remove unnecessary imports (#254)

* Fix: handle update when no sha is provided correctly

* Fix: reference to axios instance in githubservice

* style: update comment to reflect code (#260)

Code now obtains the index of first file in collection/subcollection using `_.findIndex`

* Refactor: collection page tests (#259)

* fix: get module alias to work with jest and install new packages

* Chore: move directory of tests

* Fix: add checks for test environment

* Feat: add collection controller tests

* Feat: add collection and third nav page tests

* Feat: add collectionYmlService tests

* Fix: update collection and third nav tests

* Feat: add collection page route tests

* Nit: rename third nav to subcollection

* Style: change called methods to camelCase

* Fix: missing camel case change

* Fix: update module alias for jest

* Feat: add githubService tests

* Fix: change test name for github service

* Fix: remove unused code

* Fix: correct test name for specified index

* Fix: check that deleteItemFromOrder is called for delete tests

* Fix: capitalise test names and use path alias

Co-authored-by: Alexis <gweiying@gmail.com>
Co-authored-by: Preston Lim <prestonlimlianjie@gmail.com>
@alexanderleegs alexanderleegs force-pushed the refactor/collection-pages-refactor branch from f3c0eb3 to fd9530d Compare August 19, 2021 03:51
@alexanderleegs alexanderleegs merged commit 4e52687 into develop Aug 19, 2021
lamkeewei added a commit that referenced this pull request Aug 23, 2021
* develop: (24 commits)
  Refactor/collection pages refactor (#215)
  build(deps): bump dompurify from 2.3.0 to 2.3.1 (#264)
  Introduce standard issue templates (#58)
  build(deps): bump cookie-parser from 1.4.4 to 1.4.5 (#261)
  build(deps): bump path-parse from 1.0.6 to 1.0.7 (#255)
  build(deps-dev): bump eslint-plugin-prettier from 3.3.1 to 3.4.0 (#229)
  build(deps-dev): bump lint-staged from 11.0.0 to 11.1.2 (#251)
  build(deps): bump morgan from 1.9.1 to 1.10.0 (#228)
  build(deps-dev): bump eslint-plugin-import from 2.22.1 to 2.23.4 (#223)
  build(deps): bump moment-timezone from 0.5.31 to 0.5.33 (#221)
  fix: upgrade bluebird from 3.7.0 to 3.7.2 (#239)
  fix: upgrade http-errors from 1.6.3 to 1.8.0 (#238)
  fix: upgrade js-base64 from 2.5.1 to 2.6.4 (#237)
  build(deps): bump dotenv from 8.1.0 to 10.0.0 (#219)
  fix: upgrade query-string from 6.8.3 to 6.14.1 (#235)
  [develop] fix: update logout (#252)
  feat: validate and sanitize media files (#249)
  Fix: update path to netlify.toml (#248)
  fix: add helmet for security (#243)
  fix: upgrade dependencies (#242)
  ...
lamkeewei added a commit that referenced this pull request Aug 23, 2021
…token-middleware

* feat/identity/database-models: (25 commits)
  feat: add github_id column to user model
  Refactor/collection pages refactor (#215)
  build(deps): bump dompurify from 2.3.0 to 2.3.1 (#264)
  Introduce standard issue templates (#58)
  build(deps): bump cookie-parser from 1.4.4 to 1.4.5 (#261)
  build(deps): bump path-parse from 1.0.6 to 1.0.7 (#255)
  build(deps-dev): bump eslint-plugin-prettier from 3.3.1 to 3.4.0 (#229)
  build(deps-dev): bump lint-staged from 11.0.0 to 11.1.2 (#251)
  build(deps): bump morgan from 1.9.1 to 1.10.0 (#228)
  build(deps-dev): bump eslint-plugin-import from 2.22.1 to 2.23.4 (#223)
  build(deps): bump moment-timezone from 0.5.31 to 0.5.33 (#221)
  fix: upgrade bluebird from 3.7.0 to 3.7.2 (#239)
  fix: upgrade http-errors from 1.6.3 to 1.8.0 (#238)
  fix: upgrade js-base64 from 2.5.1 to 2.6.4 (#237)
  build(deps): bump dotenv from 8.1.0 to 10.0.0 (#219)
  fix: upgrade query-string from 6.8.3 to 6.14.1 (#235)
  [develop] fix: update logout (#252)
  feat: validate and sanitize media files (#249)
  Fix: update path to netlify.toml (#248)
  fix: add helmet for security (#243)
  ...
lamkeewei added a commit that referenced this pull request Aug 23, 2021
…/email-login

* feat/identity/site-token-middleware: (25 commits)
  feat: add github_id column to user model
  Refactor/collection pages refactor (#215)
  build(deps): bump dompurify from 2.3.0 to 2.3.1 (#264)
  Introduce standard issue templates (#58)
  build(deps): bump cookie-parser from 1.4.4 to 1.4.5 (#261)
  build(deps): bump path-parse from 1.0.6 to 1.0.7 (#255)
  build(deps-dev): bump eslint-plugin-prettier from 3.3.1 to 3.4.0 (#229)
  build(deps-dev): bump lint-staged from 11.0.0 to 11.1.2 (#251)
  build(deps): bump morgan from 1.9.1 to 1.10.0 (#228)
  build(deps-dev): bump eslint-plugin-import from 2.22.1 to 2.23.4 (#223)
  build(deps): bump moment-timezone from 0.5.31 to 0.5.33 (#221)
  fix: upgrade bluebird from 3.7.0 to 3.7.2 (#239)
  fix: upgrade http-errors from 1.6.3 to 1.8.0 (#238)
  fix: upgrade js-base64 from 2.5.1 to 2.6.4 (#237)
  build(deps): bump dotenv from 8.1.0 to 10.0.0 (#219)
  fix: upgrade query-string from 6.8.3 to 6.14.1 (#235)
  [develop] fix: update logout (#252)
  feat: validate and sanitize media files (#249)
  Fix: update path to netlify.toml (#248)
  fix: add helmet for security (#243)
  ...
@alexanderleegs alexanderleegs deleted the refactor/collection-pages-refactor branch February 4, 2022 08:32
harishv7 pushed a commit that referenced this pull request Feb 17, 2023
* Chore: update import paths

* Feat: add base github service

* Feat: add util service classes

* Feat: add collection and third nav page services

* Create CollectionController.js

* Feat: add new routes for collection pages

* Feat: add new v2 collection page routes

* Feat: add new endpoints for v2

* Chore: install packages

* Feat: add page request schemas

* Feat: add schema validation in route

* Fix: update name of returned object to pageBody

* Refactor/dependency injection conversion (#234)

* Refactor: Githubservice into class

* Refactor: dependency injection for services

* Refactor: dependency injection for controller

* Refactor: router into class

* Refactor: initialisation of services in server

* Fix: standardise returned object parameter names in third nav page service

* Refactor: use axiosInstance as a dependency injection for githubService

* Fix: standardise new files being added to top of the order

* Fix: allow empty page body in schema

* Fix: retrieve router

* Fix: throw appropriate error for bad requests

* Fix: change expected request body for create and update to match object returned

* Fix: update rename collection and third nav pages to not reorder collection.yml

* Fix: update schema to allow blank new name

* Chore: suppress log statements in test environment

* Nit: rename third nav to subcollection

* fix: small change in RequestSchema structure

* style: convert to camel case (#253)

* style: move file to validators folder

* style: rename GitHubService methods to camel case

* style: rename CollectionYmlService methods to camel case

* style: rename NavYmlService methods to camel case

* style: rename SubcollectionPageService methods to camel case

* style: rename CollectionPageService methods to camel case

* style: rename CollectionController methods to camel case

* style: rename collectionPages methods to camel case

* style: update import alias for validators

* style: renaming method that was previously missed

* Chore: install auto-bind

* Fix: replace manual binding with autoBind

* Fix: remove unused variables in GItHubService

* style: remove unnecessary imports (#254)

* Fix: handle update when no sha is provided correctly

* Fix: reference to axios instance in githubservice

* style: update comment to reflect code (#260)

Code now obtains the index of first file in collection/subcollection using `_.findIndex`

* Refactor: collection page tests (#259)

* fix: get module alias to work with jest and install new packages

* Chore: move directory of tests

* Fix: add checks for test environment

* Feat: add collection controller tests

* Feat: add collection and third nav page tests

* Feat: add collectionYmlService tests

* Fix: update collection and third nav tests

* Feat: add collection page route tests

* Nit: rename third nav to subcollection

* Style: change called methods to camelCase

* Fix: missing camel case change

* Fix: update module alias for jest

* Feat: add githubService tests

* Fix: change test name for github service

* Fix: remove unused code

* Fix: correct test name for specified index

* Fix: check that deleteItemFromOrder is called for delete tests

* Fix: capitalise test names and use path alias

Co-authored-by: Alexis <gweiying@gmail.com>
Co-authored-by: Preston Lim <prestonlimlianjie@gmail.com>

Co-authored-by: Alexis <gweiying@gmail.com>
Co-authored-by: Preston Lim <prestonlimlianjie@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants