Giter Club home page Giter Club logo

se701-t5 / backend Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 18.0 162 KB

Heroku deployed Node.js backend server developed by Team-5 for the UniForum project associated with the University of Auckland SOFTENG 701 course

Home Page: https://uni-forum.herokuapp.com/

License: MIT License

TypeScript 99.49% JavaScript 0.45% Shell 0.06%
nodejs-server mongodb-database heroku-deployment express-middleware mern-stack project-management university-project documentation team-development github-ci

backend's Introduction

UniForum Server

This is a Heroku deployed Node.js backend server developed by Team-5 using the MERN stack for the UniForum project associated with the University of Auckland SOFTENG 701 course. To view the deployment of the server from this repository, visit: https://uni-forum.herokuapp.com/

More Information

For more information, visit the repository Wiki

To view the UniForum frontend repository, visit: SE701-T5/Frontend

Requirements

The following are required to run the application

  • MongoDB
  • Heroku

The following is required to be installed for running the application locally

  • Node.js

Environment Variables

To run this application, environment variables are required to be set as GitHub repository Action Secrets, and as system variables when run locally.

Application

The following environment variable is required for running the application

PORT = <port>

Database

The following environment variables are required for connecting the application to a MongoDB account

DATABASE_USER = <database-username>
DATABASE_PW = <database-password>
DATABASE_NAME = <application-database-name>
DATABASE_TEST_NAME = <test-database-name>

It is recommended to use a different test-database-name for repository forks and local testing

Deployment

The following environment variables are required for deploying the application using a Heroku account

HEROKU_EMAIL = <heroku-email>
HEROKU_API_KEY = <heroku-api-key>
HEROKU_APP_NAME = <heroku-application-name>

Local Development

Install

The following instruction can be used to install npm dependencies

npm install

Test

The following instruction can be used to test the application

npm test

Run

The following instruction can be used to run the application

npm start

The application should be running locally at http://localhost:<port>

The following instruction can be used to run the application with automatic restarts for local changes

npm dev

Deploy

The following instructions can be used to locally deploy the application to Heroku

heroku create <application-name>
git push heroku main
heroku open

Contributing

To contribute to this project, refer to the instructions laid out in the Contributing Guidelines and Code of Conduct

Further Reading

backend's People

Contributors

alexmiao7 avatar christopher-alba avatar fishmonger45 avatar hiin3d55 avatar j-chad avatar justcrossheaven avatar kimslor avatar oscarli00 avatar r055a avatar

Stargazers

 avatar  avatar

Watchers

 avatar

backend's Issues

Implement request for database resample

This issue won't be fixed for the 1st assignment

This task is for adding sample data to the database on API request.
Sample data will require being created and stored in the backend, like in config/ somewhere, for example.

There is an existing route for this in routes/db.server.routes.js:

app.route('/api/v1/resample')
    .post(database.resampleDB);

While database.resampleDB can be found in controllers/db.server.controller.js

Fix CI/CD for main repository

FIx the continuous integration workflow pipeline for pushes and manual workflow dispatches to the main branch in the main repository.

The conditional statement checks if the GITHUB_REF environment vairable is 'main' when it should check if the GITHUB_REF_NAME environment variable is 'main'.

The following fix requires being applied to line 110 in .github/workflows/node.js.yml:

if: github.event_name != 'pull_request_target' && github.repository == 'SE701-T5/Backend' && github.ref_name == 'main'

Until this is fix is implemented the CI and CD for the main branch in the main repository will be skipped.

Add CODE_OF_CONDUCT.md

Add the Code of Conduct as a markdown file named CODE_OF_CONDUCT.md in /.github directory for GitHub to link to (refer to the bottom right of Issues when creating them).

This Code of Conduct uses the Citizen Code of Conduct template.

This issue and subsequent Pull Request are intended for the team to review and approve the contribution guidelines before @R055A merges them.

Fix Pull Request CI Workflow

Currently the automated continuous integration workflow is not accessing secrets for pull requests when they are opened. This causes the CI tests to fail as the environment variables stored as secrets are required for successfully running and passing the automated tests. This can be misleading if the changes in the pull requests are not failing the same CI workflow tests in the development branches.

Add database resample feature

This feature should reset and resample a database with a sample dataset in response to a HTTP POST request to
/api/v1/resample

Refactor test suite to use mock data instead of the database

Currently, much of the existing test suite is using a test database and is consistently deleting all data in the database before each test case. This can cause conflict between test cases executed in parallel sharing the same test database resources. This is why the CI workflow is sequentially executing automated testing.

To remove the requirement of a database from the test suite would allow parallel workflow testing, would optimise test performance time, and would resolve the chance of push and pull request event driven CI workflows failing because of conflict between workflows executed by separate events that could share the same resources, such as a commit push event starting a new workflow before another workflow from a prior push event to the same repository branch has completed.

To remove sequential CI testing following removing the requirement of a database for testing, remove occurences of
max-parallel: 1 from the .github/workflows/node.js.yml

Implement user authentication

Implement user authentication and login functionality for creating, editing and deleting forum post data, and for editing and deleting forum user data.

Add Brief Project Description to Repository

Add a brief description of the project to the About section on the repository main page, including the team name and a note that the project is associated with the University of Auckland SOFTENG 701.

Implement a password hashing method

Create a password hashing method that will intake a plaintext password given by the user and return a hashedPassword.
This method will be used for user creation, login, and other verifications.

Create Wiki

Create a wiki to share detailed, long-form information about our project.

  • Contains descriptions of what our product does
  • A list of technologies and architectures used
  • Contact information if support is required
  • Any relevant links
  • Version numbers/descriptions of different builds we have (if applicable)

Connect to Database

Connect to the MongoDB database in server.js using config/db.server.config.js

If connection is unsuccessful:

  • an error message should be printed to console
  • the process should be terminated with process.exit(1)

If connection is successful:

  • a message should be printed to console with any relevant information

Dependent on Issue #13

Fix pull_request_template.md Broken Link

The link to the Contributions Guideline at the bottom of the pull_request_template.md file is broken.

It will be replaced with:

For more information, refer to the Contributing Guidelines and Code of Conduct links at the bottom of this page.

Add Node.js Continuous Integration workflow

Create and add a Node.js continuous integration (CI) workflow that is automated using GitHub actions for:

  • clean install of dependencies
  • building the Backend project
  • running automated testing

CI workflow automation is run when triggered:

  • by changes pushed to any remote branch in any forked repo
  • by pull requests to the main branch in the main repository
  • manually using the GitHub website for the repository
  • on schedule every day at 5 am NZT (or 4 pm UTC)

Implement request for database reset

This task is for removing all data from the database on API request.

There is an existing route for this in routes/db.server.routes.js:

app.route('/api/v1/reset')
    .post(database.resetDB);

While database.resetDB can be found in controllers/db.server.controller.js

Setup Backend Server

Setup the backend server:

  • create MVC layout with module files
  • setup empty MongoDB database

Dependent on Issue #5

Randomly generate forum user's name

Change the forum user's DB schema to make the name field optional.
Implement when creating a user, randomly generate their default name. (e.g. User0001)

Add CODEOWNERS

A CODEOWNERS file is used by GitHub to define who is automatically requested to review pull requests with changes to code they are responsible for.

The CODEOWNERS file in the SE701-T5/Backend repository will define the @SE701-T5/backend team as responsible by default for all changes with exception to:

  • README.md
  • LICENSE
  • .github/*

which all the @SE701-T5/team5 is responsible for as these are documents and changes to these are team-related.

The CODEOWNERS file will be located in the .github/ directory.

Fix CI/CD Workflow for Main Repository

There is a missing statement for setting sequential testing that should be in line 118 in .github/workflows/node.js.yml:

max-parallel: 1

This is the result from hours of trying different strategies for deploying to Heroku when push and manual workflows dispatch events are triggered in the main branch of the main repository while also keeping different strategies for pull request events to the main branch in the main repository and for push events to any branch in fork repositories.

Implement post request for creating a forum post

Implement adding a new forum post to the database by API request and returning a status code for success or failure

The new forum post HTTP POST request body being sent from the client:

{
  userID: string,
  title: string,
  communityID: string,
  text: string,
  images: [string]
}

Add pull_request_template.md

Add a pull request (PR) template to the ./github directory so contributors can automatically see the expected contents for the project in a new PR body.

The PR template will be based on these linked examples provided by @axolo-co but modified to better suit this project.

Implement the forum post category feature

Currently, forum posts are associated with a category ID, but this is just represented as a string. The category feature is yet to be developed. The category ID will be a mongoDB document ID and there will be a document for each category that each forum post is associated with. Refer to the frontend respository for more information regarding forum post categories.

Fix main repo for demonstration

The most recent merge caused the CI to fail. This is although the CI for the pull request passed. It is unknown why this has happened. There was no indication in the pull request that the merge was going to fail. Even if it could have been seen there was no option provided on GitHub to fix the merge issue.

  • Fix the failing testing for logging out a user
  • Fix the CI workflow for forked repositories
  • Add missing documentation

Update README file.

Add Project information, requirements and instructions for running the server locally and in a repository, including instructions for connecting to the MongoDB database and for deploying to Heroku.

Update/edit forum post comment data feature

This feature should update the field(s) of a forum post comment that has a matching document ID to an ID passed as a parameter in response to a HTTP PATCH request to /api/v1/posts/:id/comments/:id

Update forum post DB schema

Add in a communityID field which would be of string type to indicate which community the post will categorize into.

This task was created during discussion with the front team regarding task #15 when it was in progress. Because this task was resolved for completing task #15 when it was in progress, this task has been labelled duplicate and wontfix.

Add CONTRIBUTING.md

Add the contribution guideline as a markdown file named CONTRIBUTING.md in /.github directory for GitHub to link to (refer to the bottom right of Issues when creating them).

This issue and subsequent Pull Request are intended for the team to review and approve the contribution guidelines before @christopher-alba merges them, and also as an example on how to make and use an Issue and Pull Request using a GitHub Kanban project board.

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.