Skip to content

A project that bridges technology and environmental consciousness! ThinkGreenly is a full-stack platform designed where you can share on sustainable practices, connect eco-conscious communities, track personal carbon footprints, and many more ideas.

Notifications You must be signed in to change notification settings

khaledssbd/ThinkGreenly-apis

Repository files navigation

🌱 ThinkGreenly (Backend)

License: MIT PRs Welcome

πŸ“Œ Overview

RESTful API for the ThinkGreenly, built with Node.js, Express, and PostgreSQL. Handles authentication, idea moderation, and payments.

🌍 Live URL

πŸ“‚ Repository Link

πŸ› οΈ Features

  • Database: PostgreSQL with Prisma ORM.
  • JWT Authentication: Secure member/admin login.
  • CRUD Operations: Manage ideas, comments, and votes.
  • Admin Endpoints: Approve/reject ideas with feedback.

πŸ—οΈ Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: PostgreSQL
  • ORM: Prisma
  • Payment API: SSLCommerz.
  • Auth: JWT, bcrypt

πŸƒβ€β™‚οΈ Getting Started

Prerequisites

  • Node.js β‰₯18.x
  • PostgreSQL β‰₯16.x

Installation

  1. Clone the repo:

    git clone https://github.com/khaledssbd/ThinkGreenly-apis.git
    cd ThinkGreenly-apis
  2. Install dependencies

    npm install --legacy-peer-deps
  3. Set up environment variables in a .env file:

    NODE_ENV="development"
    PORT=5000
    
    DATABASE_URL="postgresql://postgres:postgres@localhost:5432/ThinkGreenly?schema=public"
    
    JWT_SECRET=""
    JWT_EXPIRATION="15d"
    JWT_REFRESH=""
    JWT_REFRESH_EXPIRATION="7d"
    RESET_PASSWORD_SECRET=""
    RESET_PASSWORD_EXPIRATION="10m"
    RESET_PASSWORD_LINK="http://localhost:5000/auth/reset-password"
    RESEND_API_KEY=""
    
    BCRYPT_SALT_ROUNDS=12
    SMTP_HOST="smtp.gmail.com"
    SMTP_PORT=587
    SMTP_USER=""
    
    
    CLOUDINARY_CLOUD_NAME=""
    CLOUDINARY_API_KEY=
    CLOUDINARY_API_SECRET=""
  4. Set up database

    npx prisma migrate dev
  5. Start the server

    npm run dev

API Endpoints

Auth APIs

βœ…οΈ POST  /api/v1/auth/login                    Login User
βœ…οΈ POST  /api/v1/auth/send-email             Send Email (e.g., reset link)
βœ…οΈ POST  /api/v1/auth/reset-password         Reset Password
βœ…οΈ POST  /api/v1/auth/refresh-token          Generate Refresh Token
βœ…οΈ PATCH  /api/v1/auth/change-password        Change Password

User APIs

βœ…οΈ POST  /api/v1/users                     Create User
βœ…οΈ PATCH  /api/v1/users/:id/status          Update User Status/Role (Admin)
βœ…οΈ GET   /api/v1/users/me                Get My Profile
βœ…οΈ GET   /api/v1/users/:id                Get Single User
βœ…οΈ PATCH  /api/v1/users/:id/profile         Update Profile

Admin APIs

βœ…οΈ GET   /api/v1/admin/ideas              Get All Ideas (Admin View)
βœ…οΈ GET   /api/v1/admin/users              Get All Users
βœ…οΈ PATCH  /api/v1/admin/ideas/:id/status    Update Idea Status (Approve/Reject)
βœ…οΈ PATCH  /api/v1/admin/users/:id/status   Update User Status (e.g., isActive)

Idea APIs

βœ…οΈ POST  /api/v1/ideas/drafts             Draft an Idea
βœ…οΈ GET   /api/v1/ideas                   Get All Ideas (Public)
βœ…οΈ GET   /api/v1/ideas/:id               Get an Idea
βœ…οΈ PUT   /api/v1/ideas/:id               Update an Idea
βœ…οΈ DELETE  /api/v1/ideas/:id              Delete an Idea
βœ…οΈ POST  /api/v1/ideas                   Create an Idea (Submit for Review)
βœ…οΈ GET   /api/v1/ideas/me                Get All Own Ideas

Payment APIs

βœ…οΈ POST  /api/v1/payments                Create a Payment (Paid Ideas)
βœ…οΈ GET   /api/v1/payments                Get All Payments (Admin)
βœ…οΈ GET   /api/v1/payments/me             Get Member Payments
βœ…οΈ GET   /api/v1/payments/:id            Get Payment Details
βœ…οΈ PATCH  /api/v1/payments/:id/validate   Validate a Payment

Comment APIs

βœ…οΈ POST  /api/v1/comments                Create Comment
βœ…οΈ GET   /api/v1/comments/:id            Get Comment
βœ…οΈ DELETE  /api/v1/comments/:id           Delete Comment

Category APIs

βœ…οΈ POST  /api/v1/categories              Create Category (Admin)
βœ…οΈ GET   /api/v1/categories              Get All Categories

Vote APIs

βœ…οΈ POST  /api/v1/votes             Register Vote (Upvote/Downvote)
βœ…οΈ DELETE  /api/v1/votes/:id          Remove Vote
βœ…οΈ GET   /api/v1/votes/me           Get Current User’s Vote for an Idea
βœ…οΈ GET   /api/v1/ideas/sorted-by-votes   	Get All Ideas Sorted by Votes
βœ…οΈ GET   /api/v1/votes/stats          Get Upvote/Downvote Stats

πŸ‘₯ Contributors


alt text

License

MIT (do whatever you want to do πŸ˜„ )

About

A project that bridges technology and environmental consciousness! ThinkGreenly is a full-stack platform designed where you can share on sustainable practices, connect eco-conscious communities, track personal carbon footprints, and many more ideas.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 8