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

Migrated JSON Files to MongoDB. Abstracted Server functionality into MVC (Model & Controllers) #104

Closed
wants to merge 36 commits into from

Conversation

ssaryonjr
Copy link

Summary:

  • Migrated entire JSON resources file into MongoDB. Abstracted server code and moved into MVC-style architecture for easier debugging and modularity. Utilized mongoose for form validations.
  • NOTE: Please continue from this PR and connect api/resources/getResources to input form inside views > index.ejs in order for resource fetching functionality to work again.

Dependencies

  • Express Async Handler
  • Mongoose
  • Dotenv

Server.js

  • Deleted API Endpoint for keyword input search.
  • Added MongoDB to server.js
  • Created .env file
  • Added errorHandler middleware to assist in status errors when testing in Postman.

Routes & Controllers

  • getResources - Migrated original functionality for resource query results from Mongo Database.
  • createResource - Custom API Endpoint for easily adding new resources to Mongo Database. (A view will be needed to be created later on for this to be done in the UI. Currently only available through Postman).
  • Routes - Abstracted API Endpoints into the routes folder. Created a search params /api/resources/:keyword for returning resource results.

Model

  • Implemented resource schema for easier form validation when adding new data to MongoDB.
  • name - String & Required.
  • url - String & Required.
  • description - String & Required
  • keywords - Creates an array from a string sentence. Example: ["JavaScript", "Git"]

Config

  • Store your .env file inside the config folder for easier organization. Please include: MONGO_URI and PORT

Middleware

  • Added errorHandler middleware to assist in status errors when testing in Postman.

Closing #94

LucasMERN and others added 28 commits June 16, 2022 20:13
changed recieve to receive
change the heroku links out for the railway links
…d mongo database, added dotenv, added error handler function for api testing in postman
Copy link
Member

@20jasper 20jasper left a comment

Choose a reason for hiding this comment

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

I left some comments detailing some changes and some points of confusion. To fully migrate, I think you should also delete the "resources.js" file

@@ -6,7 +6,16 @@ Contributions are what make the open source community such an amazing place to l

<ins>Please make sure to follow our guidelines below before making any contributions.</ins>


- [Contributing](#contributing)
Copy link
Member

Choose a reason for hiding this comment

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

Did anything change here, or did this section just get formatted?

Suggested change
- [Contributing](#contributing)
- [Contributing](#contributing)
- [Understanding Coding-Resources-API branch structure](#understanding-coding-resources-api-branch-structure)
- [Permanent Branches](#permanent-branches)
- [Main](#main)
- [Test](#test)
- [Resources](#resources)
- [How often should I stage changes?](#how-often-should-i-stage-changes)
- [Where should I make my pull request to?](#where-should-i-make-my-pull-request-to)
- [Creating an Issue](#creating-an-issue)
- [How to make a PR](#how-to-make-a-pr)

controllers/resourceController.js Outdated Show resolved Hide resolved
@@ -24,22 +35,9 @@ app.get('/api', (req, res) => {
res.json(resources);
});

app.get('/api/:keyword', (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this route being deleted?

Copy link
Member

Choose a reason for hiding this comment

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

This is now located in the resourceRoutes, Jesse had just updated the endpoint

@jesseranon
Copy link

jesseranon commented Oct 12, 2022

These commits fix the get matches functions in js/main.js and handle resource searches through MongoDB.


server.js

  • changed /api/resources base endpoint to /api to maintain legacy endpoints

js/main.js

  • changed line 35 to fetch /api/:keyword endpoint to connect to database
  • removed data.filter() as resourceController would handle filtering

controllers/resourceController.js

  • changed Resource.find() parameters to use case-insensitive, partial matches for keyword

views/index.ejs

  • changed endpoint urls to point to the current railway url

Closing #105

@schneedotdev schneedotdev deleted the AmazingFeature branch October 13, 2022 01:25
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.

7 participants