Skip to content

build-week-apis/a-to-z-experiences

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A to Z Backend

Backend for A to Z build week project

Deployed Backend

https://bw-a-to-z-experiences.herokuapp.com/

Technologies

Production
  • Express: Fast, unopinionated, minimalist web framework for Node.js
  • Bcryptjs: Allows you to store passwords securely in your database
  • Jsonwebtoken: Generate and verify json web tokens to maintain a stateless api
  • Knex: Knex.js is a "batteries included" SQL query builder for Postgres, MSSQL, MySQL, MariaDB, SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use
  • Sqlite3: Asynchronous, non-blocking SQLite3 bindings for Node.js.
  • Morgan: HTTP request logger middleware for Node.js
  • Cors: CORS is a Node.js package for providing a Connect/Express middleware that can be used to enable CORS
  • Helmet: Helmet helps you secure your Express apps by setting various HTTP headers
  • Dotenv: Dotenv is a zero-dependency module that loads environment variables from a .env file
Developer
  • Nodemon: nodemon is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected

Setup

(# <--- signifies comment) In your terminal run:

# Install dependencies
npm install

# Starts express server using nodemon
npm run server

Table of Contents

AUTH ROUTES

REGISTER

Registers a user

Method Url: /api/register

HTTP method: [POST]

Headers

name type required description
Content-Type String Yes Must be application/json

Body

name type required description
username String Yes Must be unique
password String Yes
first_name String Yes
last_name String Yes
email String No
city String No

example:


{
  "username": "username"
  "password": "password123",
  "first_name": "First Name",
  "last_name": "Last Name",
  "email": "[email protected]",
  "city": "NYC",
}

Response

201 (Created)

If you successfully register a user the endpoint will return an HTTP response with a status code 201,message, and a token as below.

example:

{
  "message": "Welcome user! You have been successfully registered!"
},
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI3IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTQ0MzM1NjUxLCJleHAiOjE1NzU4OTMyNTF9.uqd2OHBYkGQpwjLTPPiPWYkYOKlG7whQDFkk46xFXoX"
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while registering"
}


LOGIN

Logs a user in

Method Url: /api/login

HTTP method: [POST]

Headers

name type required description
Content-Type String Yes Must be application/json

Body

name type required description
username String Yes Must match a username in the database
password String Yes Must match a password in the database corresponding to email above

example:

{
  "message": "Welcome, user!"
},
{
  "username": "username"
  "password": "password123",
}

Response

200 (OK)

If you successfully login, the endpoint will return an HTTP response with a status code 200, message, and a token as below.

example:


{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MDwiaWF0IjoxNTQ0MzM1NjUxLCJleHAuOjE1NzU4OTMyNTF9.uqd2OHBYkGQpwjLTPPiPWYkYOKlG7whQDFkk46xGXnE",
}

401 (Unauthorized)

If you fail to login, the endpoint will return an HTTP response with a status code 401 which indicates the username and/or password entered is not valid.

example:


{
  message: "Wrong username or password. Try again."
}

500 (Bad Request)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while logging in"
}

USERS ROUTES

GET USER

Get all users

Method Url: /api/users

HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Response

200 (OK)

The endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "id": 1,
  "username": "username"
  "first_name": "First Name",
  "last_name": "Last Name",
  "email": "[email protected]",
  "city": "NYC"
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Error getting users"
}

GET USER BY ID

Get user profile by user id

Method Url: /api/users/:id

HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No JSON Web Token

Response

200 (OK)

If the user profile is found in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "id": 1,
  "username": "username"
  "first_name": "First Name",
  "last_name": "Last Name",
  "email": "[email protected]",
  "city": "NYC"
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while getting that user profile"
}

UPDATE USER

Update a user by user id

Method Url: /api/users/:id

HTTP method: [PUT]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Parameters

name type required description
id Integer Yes ID of a specific seeker

Body

name type required description
username String No
first_name String No
last_name String No
email String No
city String No

example:


{
  "username": "username",
  "name": "First Last",
  "first_name": "First Name",
  "last_name": "Last Name",
  "email": "[email protected]",
  "city": "NYC"
}

Response

200 (OK)

If a seeker with the specified ID in the URL parameters is updated successfully in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "message": `Your profile has been successfully updated`
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while updating that profile"
}

DELETE USER

Delete a USER by user id

Method Url: /api/users/:id

HTTP method: [DELETE]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Parameters

name type required description
id Integer Yes ID of a specific seeker

Response

200 (OK)

If a seeker with the specified ID in the URL parameters is deleted successfully in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "message": "1 user was successfully deleted"
}

500 (Bad Request)

If you send in invalid fields, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while deleting that user"
}

GET EXPERIENCES USERS ATTENDING

Get the experiences your user has RSVPed for and will be attending

The user_id is reserved for the user who created the experience

Method Url: /api/users/:id/experiences_attending

HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Response

200 (OK)

If the users experiences are found in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "user_id": 18,
  "experience_id": 1,
  "id": 1,
  "title": "Arts",
  "date": "date",
  "location": "location",
  "price": "$20",
  "description": "Art lessons for all ages"
}


500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Error getting users attending experiences"
}

RSVP USER TO EXPERIENCE

RSVP to the experiences your user would like to attend

The user_id is reserved for the user who created the experience

Method Url: /api/experiences/attend

HTTP method: [POST]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Body

name type required description
user_id String Yes Must be unique
experience_id String Yes

example:


{
  "user_id": 18,
  "experience_id": 1
}

Response

200 (OK)

If the user is RSVPed for experience, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
    "message": "You have successfully registered for this experience! See you there!"
}



500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, there was an error registering for the experience"
}

**DELETE EXPERIENCE USERS ATTENDING **

** Un-RSVPs user from an experience they are attending **

*STILL BUGGY!*

Method Url: /api/users/:id/experiences_attending

HTTP method: [DELETE]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Parameters

name type required description
id Integer Yes ID of a specific seeker

Response

200 (OK)

If a user with the specified ID in the URL parameters is deleted successfully in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "message": "You are no longer attending this experience"
}

500 (Bad Request)

If you send in invalid fields, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while deleting that experience."
}

EXPERIENCE ROUTES

GET EXPERIENCES

Get all experiences

Method Url: /api/experiences

HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json

Response

200 (OK)

The endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "experiences": [
        {
            "id": 1,
            "user_id": 1,
            "title": "Arts & crafts",
            "date": "9/2/19",
            "location": "Brooklyn, NY",
            "price": "$20",
            "description": "Art lessons for all ages"
        }
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, Theres been an error getting experiences"
}

GET EXPERIENCE BY ID

Get experience by experience id

Method Url: /api/experiences/:id

HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No JSON Web Token

Response

200 (OK)

If the experience is found in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
   "id": 1,
    "user_id": 1,
    "title": "Arts & crafts",
    "date": "9/2/19",
    "location": "Brooklyn, NY",
    "price": "$20",
    "description": "Art lessons for all ages"
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while getting that experience"
}

GET EXPERIENCE ADDED BY HOST USER

Get all experiences added by a particular host user

Method Url: /api/users/:id/host_experiences

HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Response

200 (OK)

The endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "id": 1,
  "username": "new",
  "first_name": "First Name",
  "last_name": "Last Name",
  "email": "[email protected]",
  "city": "NYC"
  "experiences": [
    {
        "id": 1,
        "user_id": 1,
        "title": "Arts & crafts",
        "date": "9/2/19",
        "location": "Brooklyn, NY",
        "price": "$20",
        "description": "Art lessons for all ages"
    }
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while getting that hosts experiences"
}

ADD EXPERIENCE

Adds new experiences

Method Url: /api/experiences

HTTP method: [POST]

Headers

name type required description
Content-Type String Yes Must be application/json

Body

name type required description
user_id Int No
title String Yes Must be unique
date String Yes
location String Yes
price String No
description String No

example:


{
  "user_id": 1,
  "title": "Arts & crafts",
  "date": "9/2/19",
  "location": "Brooklyn, NY",
  "price": "$20",
  "description": "Art lessons for all ages"
}

Response

201 (Created)

If you successfully post an experience the endpoint will return an HTTP response with a status code 201 and a body as below.

example:

{
  "id": 1,
  "user_id": 1,
  "title": "Arts & crafts",
  "date": "9/2/19",
  "location": "Brooklyn, NY",
  "price": "$20",
  "description": "Art lessons for all ages"
}

404 (Not Found)

If the user has not provided a title, date, or location, the endpoint will return an HTTP response with a status code 404 and a body as below.

example:


{
  "message": "Sorry, all new experiences require a title, date, and location."
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while added the experience"
}

UPDATE EXPERIENCE

Update an experience by experience id

Method Url: /api/experiences/:id

HTTP method: [PUT]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Parameters

name type required description
id Integer Yes ID of a specific seeker

Body

name type required description
user_id Int No
title String No Must be unique
date String No
location String No
price String No
description String No

example:


{
  "user_id": 1,
  "title": "Arts & crafts",
  "date": "9/2/19",
  "location": "Brooklyn, NY",
  "price": "$20",
  "description": "Art lessons for all ages"
}

Response

200 (OK)

If an experience with the specified ID in the URL parameters is updated successfully in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:

{ message: "Your experience has been successfully update" }
{
  "user_id": 1,
  "title": "Arts & crafts",
  "date": "9/2/19",
  "location": "Brooklyn, NY",
  "price": "$20",
  "description": "Art lessons for all ages"
}

500 (Internal Server Error)

If there is a server or database error, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while updating that experience"
}

DELETE EXPERIENCE

Delete a experience by experience id

Method Url: /api/experiences/:id

HTTP method: [DELETE]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String Yes JSON Web Token

Parameters

name type required description
id Integer Yes ID of a specific seeker

Response

200 (OK)

If an experience with the specified ID in the URL parameters is deleted successfully in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.

example:


{
  "message": "1 experience was successfully deleted"
}

500 (Bad Request)

If you send in invalid fields, the endpoint will return an HTTP response with a status code 500 and a body as below.

example:


{
  "message": "Sorry, but something went wrong while deleting that experience"
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published