Git Product home page Git Product logo

scoop-backend's Introduction

SCOOP

Scoop is your window to the heartbeat of campus life. Engage, explore, and uncover the latest campus insights in real-time. This is your space to share and discover news that truly matters.

Tech Stack

  • NodeJS
  • ExpressJS
  • MongoDB
  • React

πŸš€ Features

  1. News Unleashed:

    • Scoop is your go-to platform for breaking campus news. Share the latest updates, events, and noteworthy happenings with the community. Your news, your voice.
  2. Upvote Power

    • Every user has the ability to shape the narrative. Upvote the most relevant and impactful news, ensuring that the most significant stories rise to the top.
  3. Verified Badge Prestige:

    • Become a recognized campus news authority. The user with the most upvoted news profile earns a prestigious verified badge, symbolizing their influence and commitment to delivering quality information.
  4. Chronicle Rankings:

    • Scoop doesn’t just share news; it prioritizes the most impactful stories. The most upvoted news articles secure a prime position at the top, ensuring that the campus community stays informed with the best content.
  5. Admin Dashboard:

    • An admin will have the authority to delete or edit news shared by regular user.
  6. Community Informed

    • Engage in meaningful discussions around the latest news. Foster a sense of community by sharing opinions, insights, and reactions to the stories that matter most.

Join The Scoop Revolution

Scoop is a revolution in campus journalism. Together, let's elevate the way we share, consume, and engage with campus news. Your insights, your influence - let the Scoop revolution begin!

Setup Guide

  1. Create a .env file in the root directory.
  2. Add your mongodb uri in the .env file (refer env.example file).
  npm install 
  npm run dev

Make sure you have required enviornment variables saved in the .env file in the root of the project. A file .env.example is attached for reference.

Claim an issue

Comment on the issue. In case of no activity on the issue even after 2 days, the issue will be reassigned. If you have difficulty approaching the issue, feel free to ask on our discord channel.

Communication

Whether you are working on a new feature or facing a doubt please feel free to ask us on our discord channel. We will be happy to help you out.

Guidlines

Please help us follow the best practice to make it easy for the reviewer as well as the contributor. We want to focus on the code quality more than on managing pull request ethics.

  • People before code: If any of the following rules are violated, the pull-requests must not be rejected. This is to create an easy and joyful onboarding process for new programmers and first-time contributors.

  • Single commit per pull request and name the commit as something meaningful, example: Adding <-your-name-> in students/mentors section.

  • Reference the issue numbers in the commit message if it resolves an open issue. Follow the PR Template Issue: < ISSUE NUMBER >

  • Provide the link to live gh-pages from your forked repository or relevant screenshot for easier review.

  • Pull Request older than 3 days with no response from the contributor shall be marked closed.

  • Do not make PR which is not related to any issues. You can create an issue and solve it once we approve them.

  • Avoid duplicate PRs, if need be comment on the older PR with the PR number of the follow-up (new PR) and close the obsolete PR yourself.

  • Be polite: Be polite to other community members.

API endpoints

Users Routes:

  • POST /api/users/:userId/upvote: Upvote a user. (auth required)
  • POST /api/users/:userId/downvote: Downvote a user. (auth required)
  • GET /api/users/allUsers: Get details of all users (admin access (isAdmin = 1) and auth required)
  • GET /api/user/:userId: Get details of a user (auth required)
  • GET /api/user/:userId: Get details of a user (auth required)
  • GET /api/user/:userId: Get details of a user (auth required)
  • DELETE /api/user/delete/:userId: Delete User Details (auth required with isAdmin=1)

News Routes:

  • POST /api/scoop/post: Allow users to post news (auth required)
  • POST /api/scoop/:scoopId/upvote: Upvote a news. (auth required)
  • GET /api/scoop/:scoopId: Get news details
  • DELETE /api/scoop/delete/:userId: Delete news (auth required with admin access)
  • PATCH /api/scoop/:scoop: Get details of a user (auth required)

Home Routes:

  • GET /api/scoop/home/top: Top 5 news sorted based on most number of upvotes on news
  • GET /api/scoop/home/credible: Latest news of top 5 profiles sorted based on most number of upvotes on profile
  • GET /api/scoop/home/categories: Out of all the news in the database, return an array of all the tags used in all news. Ensure the array does not have duplicate entries
  • GET /api/scoop/home/latest: Out of all the news in the database, return 5 latest news

Authentication Routes:

  • POST /api/auth/register: Register a new user.
  • POST /api/auth/login: Authenticate and log in a user

General Routes:

  • GET /api/scoop/top: Sort all news according to most number of upvotes
  • GET /api/scoop/credible: Sort news according to highest upvotes in the profile of the user who uploaded it
  • GET /api/scoop/latest: Sort according to date and return the latest news

Comments Routes:

  • GET /api/scoop/:scoopId/comments: Get comments for a news article (Auth req.)
  • POST /api/scoop/:scoopId/comments: Add a new comment to a news article (auth required)
  • PATCH /api/scoop/:scoopId/comments/:commentId: Edit a comment (auth required)

scoop-backend's People

Contributors

0mbudsman avatar coderatiiita avatar dikshantk2004 avatar harshal5167 avatar jarviss77 avatar nivedh-biju avatar pranavbansal21 avatar rnavaneeth992 avatar thedivineaurora avatar vihaan-19 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

scoop-backend's Issues

Create Comment Routes

Description

I would like to request the addition of new API endpoints for managing comments on news articles:

  • Endpoint: GET /api/scoop/:scoopId/comments

    • Description: Get comments for a news article.
    • Authentication Required: Yes
  • Endpoint: POST /api/scoop/:scoopId/comments

    • Description: Add a new comment to a news article.
    • Authentication Required: Yes
  • Endpoint: PATCH /api/scoop/:scoopId/comments/:commentId

    • Description: Edit a comment.
    • Authentication Required: Yes

Additional Requirements

  • Error Handling:

    • Use the responseCodes in utils directory for code consistency.
  • Security Considerations:

    • Ensure proper authentication and authorization mechanisms are in place for authenticated endpoints.
  • Data Validation:

    • Validate incoming data to ensure it meets expected formats and constraints.
  • Testing:

    • Ensure you have tested the code before submitting a pull request.
  • Consistency:

    • Ensure a consistent response format across all endpoints.
    • Maintain consistency in naming conventions and coding style.

Create Home Routes

Implement Home Endpoints

Create Endpoints

  • Endpoint: GET /api/scoop/home/top

  • Description: Retrieve the top 5 news sorted based on the most number of upvotes on news.

  • Endpoint: GET /api/scoop/home/credible

  • Description: Retrieve the latest news of the top 5 profiles sorted based on the most number of upvotes on profiles.

  • Endpoint: GET /api/scoop/home/categories

  • Description: Return an array of all tags used in all news without duplicate entries.

  • [ ]Endpoint: GET /api/scoop/home/latest

  • Description: Retrieve the 5 latest news.

Additional Information

  • Error Handling:

    • Ensure robust error handling for each endpoint, providing clear and informative error messages (use the responseCodes in utils directory).
  • Data Validation:

    • Validate incoming data to ensure it meets expected formats and constraints.
    • Handle edge cases gracefully and provide appropriate responses.
  • Testing:

  • Make sure you have tested the endpoints before sending a pull request.

  • Consistency:

    • Ensure a consistent response format across all endpoints.
    • Maintain consistency in naming conventions and coding style.
  • Maintainability:

    • Implement code in a modular and maintainable way for future updates.

Implement Multer and Cloudinary for User Image Upload in Registration Controller

Issue Title:

"Implement Multer and Cloudinary for User Image Upload"

Deadline:

24 hours

Description:

Objective:

Implement Multer middleware to handle file uploads during user registration and utilize Cloudinary to store and retrieve image URLs.

Tasks:

Task 1: Multer Middleware

  1. Description:
    Create a Multer middleware (multerMiddleware.js) to handle image file uploads during user registration.

  2. File Handling:

    • Configure Multer to handle image files.
    • Implement logic to store uploaded image files locally.

Task 2: Cloudinary Integration

  1. Description:
    Integrate Cloudinary into the application to handle image storage and retrieval.

  2. Upload to Cloudinary:

    • Use the Cloudinary SDK for Node.js to upload image files to Cloudinary.
    • Ensure secure and authenticated communication with the Cloudinary API.

Task 3: Update User Registration Controller

  1. Description:
    Modify the user registration controller (user.controllers.js) to handle user images in the form of URLs.

  2. Image URL Handling:

    • Utilize the Multer middleware to handle file uploads.
    • Use Cloudinary URLs in the user registration process to store image references.

Task 4: Integration

  1. Description:
    Integrate the Multer and Cloudinary middleware into the user registration process.

  2. Middleware Flow:

    • Ensure the Multer middleware is invoked to handle file uploads.
    • Confirm that Cloudinary is used to store and retrieve image URLs.

Additional Information:

  • Multer will be used for handling file uploads locally.
  • Cloudinary will be used for long-term storage and retrieval of image URLs.
  • Implement appropriate error handling for unsuccessful file uploads or Cloudinary interactions.

Create PATCH Route for Updating User Details

Issue: Create PATCH Route for Updating User Details

Description

Problem

We need to implement a backend functionality that takes a user token as input, generates user details from the token, locates the corresponding user in the database, and updates their information.

Goal

The goal is to allow users to update their details securely by providing a token for verification.

Tasks

  1. Create PATCH Route:

    • Implement a new PATCH route in the backend for updating user details.
  2. Token Input:

    • Ensure that the route accepts a user token as input, typically sent in the request headers or body.
  3. Generate User Details:

    • Implement logic to generate user details (userid to be precise) using the provided token.
  4. Locate User in Database:

    • Query the database to find the user based on that userid.
  5. Update User Details:

    • Update the user's information in the database.
  6. Error Handling:

    • Implement proper error handling for cases where the token is invalid or the user is not found.

Additional Information

If you have any questions or need clarification, feel free to comment on this issue. Get this done in 24 hours

Thank you for your contribution!

Create User Controllers

Implement user-related endpoints for upvoting, downvoting, retrieving user details, and deleting user accounts.

Create Endpoints:

  • - Create POST /api/users/:userId/upvote endpoint for upvoting a user (user auth required).

  • - Create GET /api/users/allUsers endpoint for retrieving details of all users (user auth required, accessible only by admin users).

  • - Create GET /api/users/:userId endpoint for retrieving details of a specific user.

  • - Create DELETE /api/users/delete/:userId endpoint for deleting user details (user auth required, accessible only by admin users).

  • Create controllers for each endpoint.

  • Ensure user authentication for required endpoints.

  • Add authorisation checks where necessary (e.g., isAdmin check for admin-specific endpoints).

  • Ensure proper error handling.

Create Auth Middleware

Our webpage requires an authentication middleware to ensure that the user is authenticated, which is required for several routes
(refer README.md).

  • Implement a module to generate JWT tokens upon successful user authentication.
  • Include essential user information in the token payload.
  • Develop middleware function to verify JWT tokens for routes that require authentication.
  • Ensure the middleware is modular and can be easily integrated into relevant routes.
  • Include meaningful error messages for better debugging.

Pilot

Make User Model, News Model, Comments Model in different files
Use MongoDB for database and its' functionalities for the same
There are many courses available on the web for mongo, you can refer to the same
Once you have created a database, paste its link in env file with name MONGO_URI
**THE FOLLOWING IS THE SCHEMA FOR USER AND NEWS **

  1. User Schema:
  • First Name (String)
  • Last Name (String)
  • Username (String, unique)
  • Profile Image (String - URL)
  • Email (String)
  • Password (String, encrypted)
  • isAdmin (Boolean)
  • myUpvotes (Array of User references)
  • News[ ] (Array of News references)
  1. News Schema:
  • Headline (String)
  • Location (String - URL)
  • Description (String - HTML)
  • Tags (String[ ])
  • Upvotes Count (Int)
  • User (Reference to User)
  • Comments[ ] (Array of Comment references)
  1. Comments Schema:
  • News (Reference to News)
  • User (Reference to User)
  • Date
  • Comment (String)

Create News Controllers

Implement news-related endpoints for posting, upvoting, retrieving news details, and deleting news.

Create Endpoints

  • - POST /api/scoop/post: Allow users to post news (auth required)
  • - POST /api/scoop/:scoopId/upvote: Upvote a news. (auth required)
  • - GET /api/scoop/:scoopId:Get news details.
  • - DELETE /api/scoop/delete/:scoopId: Delete news. (auth required with admin access)
  • Create controllers for each endpoint.
  • Ensure user authentication for required endpoints. (using the auth middleware
  • Add authorisation checks where necessary (using the isAdmin middleware).
  • Ensure proper error handling.

Create Admin Middleware

Create a new middleware, isAdmin, to check if a user has admin privileges. This middleware will be essential for controlling access to admin-specific routes and functionalities.

  • If the user is an admin, allow the request to proceed; otherwise, return a 403 status with an appropriate error message.

  • The isAdmin middleware is created to check admin privileges based on the user model.

  • Error handling is implemented for non-admin users attempting to access admin-specific routes.

Implement Controllers and Routes for Fetching Top and Credible Scoop

Issue Title:

"Implement Controllers and Routes for Fetching Top and Credible Scoop" (Refer already created model for schema)

Description:

Objective:

Implement controllers and routes to handle requests for fetching top scoop (news) and credible scoop based on user profiles.

Tasks:

Task 1: Fetching Top Scoop

  1. Description:
    Create a controller and route that fetches top scoop (news) from the database, sorted according to the most number of upvotes.

  2. Acceptance Criteria:

    • The route should invoke the corresponding controller for fetching top scoop.
    • Ensure that the response includes the sorted list of news articles based on the most upvotes.

Task 2: Fetching Credible Scoop

  1. Description:
    Create a controller and route that fetches credible scoop (news) from the database, sorted according to the latest news from users with the highest upvotes.

  2. Acceptance Criteria:

    • The route should invoke the corresponding controller for fetching credible scoop.
    • Verify that the response includes the latest news articles from users with the highest upvotes in their profiles.

Additional Information:

  • Use the existing models and database schema for news articles and user profiles.
  • Ensure error handling in case of database queries or other issues.
  • The controllers and routes should be integrated with the existing Express.js application.
  • Test the controller by feeding dummy data into your database,and attach those details along with your PR.

Verify Token Signature in Backend Controller

Issue: Verify Token Signature in Backend Controller

Description

Problem

We currently lack a backend controller to verify the signature of user tokens. Verifying the token signature is crucial for ensuring the integrity and authenticity of the token. Make necessary routes required for it

Goal

Implement a backend controller that verifies the signature of user tokens.

Tasks

  1. Create Backend Controller:

    • Implement a new backend controller dedicated to verifying the signature of user tokens.
  2. Token Input:

    • Ensure that the controller accepts a user token as input, typically sent in the request headers or body.
  3. Verify Token Signature:

    • Implement logic to verify the signature of the user token.
  4. Error Handling:

    • Implement proper error handling for cases where the token signature verification fails.

Deadline: 24 hours

Additional Information

If you have any questions or need clarification, feel free to comment on this issue.

Thank you for your contribution!

Implement Authentication Routes

1. Register New User Endpoint

  • Route: POST /api/auth/register
  • Description: Implement a route to register a new user.

Requirements:

  • Accept user details (refer User model) (e.g., username, email, password, etc).
  • Validate input data.
  • Hash the password securely.
  • Save user information to the database.
  • Return appropriate response and handle errors.

2. Login User Endpoint

  • Route: POST /api/auth/login
  • Description: Implement a route to authenticate and log in a user.

Requirements:

  • Accept login credentials (refer User model) (e.g., username/email and password, etc).
  • Validate input data.
  • Verify user credentials against stored data.
  • Generate and return an authentication token upon successful login.
  • Implement error handling for unsuccessful login attempts.

Additional Guidelines:

  • Include comprehensive error messages to aid debugging and user feedback.
  • Ensure compatibility with the existing user database.

Note: This issue encompasses the initial implementation of user registration and login routes. Future enhancements, such as password recovery and account management, can be addressed in separate issues.

Implement Controllers and Routes for Fetching Latest News

Issue Title:

"Implement Controllers and Routes for Fetching Latest News"

Description:

Objective:

Create controllers and routes to handle requests for fetching the latest news from the database, sorted by date.

###Time Limit : 24 hours

Tasks:

Task 1: Fetching Latest News

  1. Description:
    Create a controller and route that fetches the latest news articles from the database, sorted by date.

  2. Acceptance Criteria:

    • The route should invoke the corresponding controller for fetching the latest news.
    • Ensure that the response includes the list of news articles sorted by date, with the latest articles appearing first.

Additional Information:

  • Use the existing models and database schema for news articles.
  • Consider the format of the date in the response (e.g., ISO format).
  • Ensure error handling in case of database queries or other issues.
  • Integrate the controllers and routes with the existing Express.js application.
  • Test the same by feeding dummy data in your database

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.