Skip to content

PiroAvni/florin_server

Repository files navigation

Florin County API

Description

This project is an API built for our solution to this brief

Installation & Usage

Installation

  1. Open up GitBash terminal and navigate to the directory you wish to store the project in
  2. Clone the repo to your folder using this command
git clone git@github.com:yrossan/florin_server.git
  1. Navigate to the florin-server folder using this command
cd florin_server/
  1. Install required packages using this command
npm install
  1. Create a SQL server and and get the connection URL we would reccomend elephantSQL but you can use another method
  2. Open your code editor by running this command in your GitBash terminal
code .
  1. Create a .env file in the florin_server/ add your connection URL in a DB_URL variable and the port you wish the server to listen on in a PORT variable as shown below
DB_URL='postgres://username:password@horton.db.elephantsql.com/dbname'
PORT=3000
  1. Setup the database with mock data by running this command in your GitBash terminal
npm run setup-db
  1. Now you can run the server with this command
npm run dev
  1. You are now ready to start using the API endpoints

Usage

API Endpoints

posts/

  • GET /posts = All posts
  • GET /posts/:id = Find post by id
  • GET /posts/services = All posts with ‘Services’ category
  • GET /posts/events = All posts with ‘Events’ category
  • GET /posts/jobs = All posts with ‘Jobs’ category
  • GET /posts/voluntary = All posts with ‘Voluntary Work’ category
  • GET /posts/announcements = All posts with ‘Announcements’ category
  • GET /posts/clubs = All posts with ‘Clubs’ category

Requires authentication

  • DELETE /posts/:id = delete a post by id
  • POST /posts = create a new post with POST request

POST /posts required request body to create new post

 {
    "title": "Title", // Post title
    "content": "Main content for post", // Main section of the post
    "category": "Services", // must be one of preset categories from GET/posts/... routes
    "author_id": 1, // must be user_id of current user
    "post_date": "2023-05-11" // must be in YYY-MM-DD format
  }

users/

  • POST /users/register = register user

POST /users/register required request body to to register a user

{
    "username": "User1", // The users username
    "password": form.get("password"), // The users password
    "isAdmin": isAdminResult, // Optional must be 1 or 0 for true and false respectively
    "isBusiness": isBusinessResult, // Optional must be 1 or 0 for true and false respectively
}
  • POST /users/login = login user

POST /users/register required request body to to register a user

{
      "username": "username", // The users Username
      "password": "password", // The users password
}

Requires authentication

  • DELETE /users/logout = removes all tokens from database where user_id matches current users token user_id

comments/

  • GET /comments/:id = All comments with post_id = id

Technologies

Dependencies

  • express
  • bcrypt
  • cors
  • dotenv
  • morgan
  • pg
  • uuid

Dev Dependencies

  • jest
  • nodemon
  • supertest

Bugs

  • No known bugs

License

MIT License: see the LICENSE file.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published