Skip to content

Kickstarter-Success/Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kickstarter Success - Backend Code by Timothy M. McGowen

Project Description
An application that takes machine learning data and inputs from the user to give reliable percentages of success for a potential Kickstarter project. 1. Created the backend using nodeJS, Express, Knex, MySQLite for development and PostgreSQL for deployment. 2. Took data from the front end and the data machine learning API and parsed it into readable data for the user. 3. Assisted in the front end state management and the construction of the marketing site.

Users

Get User by ID
https://kickstarter-backend.herokuapp.com/api/auth/:id
Get All Users
https://kickstarter-backend.herokuapp.com/api/auth/
Register A User
https://kickstarter-backend.herokuapp.com/api/auth/register
Login A User
https://kickstarter-backend.herokuapp.com/api/auth/login
Change A Password
https://kickstarter-backend.herokuapp.com/api/auth/update/:id
Remove A User
https://kickstarter-backend.herokuapp.com/api/auth/delete/:id

Kickstarter

Get A Single Kickstarter by ID
https://kickstarter-backend.herokuapp.com/api/kickstarter/:id
Get A Users Kickstarter by ID
https://kickstarter-backend.herokuapp.com/api/kickstarter/user/:id
Get All Kickstarters
https://kickstarter-backend.herokuapp.com/api/kickstarter/all
Adds a Kickstarter when Given a User_id
https://kickstarter-backend.herokuapp.com/api/kickstarter/user/:id
Update A Single Kickstarter by ID
https://kickstarter-backend.herokuapp.com/api/kickstarter/:id
Removes A Single Kickstarter by ID
https://kickstarter-backend.herokuapp.com/api/kickstarter/:id

Register

If you need to Register a User use the following information.

URL : https://kickstarter-backend.herokuapp.com/api/auth/register

Method : POST

Auth required : NO

Data constraints

{
    "username": "[A unique username]",
    "password": "[password in plain text]"
}

Data example

{
    "username": "admin",
    "password": "password"
}

Success Response

Code : 201 Created

Content example

The password that is returned is a hash and not a representation of something that you should use.

{
    "id": 2,
    "username": "[username]",
    "password": "93144b288eb1fdccbe46d6fc0f241a51766ecd3d"
}

Error Response

Condition : If 'username' is already taken.

Code : 500 BAD REQUEST

Content :

{
    
    "name": "error",
    "length": 212,
    "severity": "ERROR",
    "code": "23505",
    "detail": "Key (username)=([username]) already exists.",
    "schema": "public",
    "table": "users",
    "constraint": "users_username_unique",
    "file": "nbtinsert.c",
    "line": "534",
    "routine": "_bt_check_unique"

}

Error Response

Condition : If 'username' and 'password' combination isn't send.

Code : 500 BAD REQUEST

Content :

{
    "error"
}

Login

If you need to log a User in use the following information.

URL : https://kickstarter-backend.herokuapp.com/api/auth/login/

Method : POST

Auth required : NO

Data constraints

{
    "username": "[valid username]",
    "password": "[password in plain text]"
}

Data example

{
    "username": "admin",
    "password": "password"
}

Success Response

Code : 200 OK

Content example

{
    "message": "Welcome [username]!",
    "token": "93144b288eb1fdccbe46d6fc0f241a51766ecd3d"
}

Error Response

Condition : If 'username' and 'password' combination is wrong.

Code : 401 BAD REQUEST

Content :

{
    "message": "Invalid Credentials"
}

Change a Password

If you need to change a password use the following information. Use the id of the user that is currently logged in to make the change.

URL : https://kickstarter-backend.herokuapp.com/api/auth/update/:id

Method : PUT

Auth required : YES

Data constraints

{
    "username": "[Valid username that has not been changed]",
    "password": "[New Password]"
}

Data example

{
    "username": "admin",
    "password": "newPassword"
}

Success Response

Code : 200 OK

Content example

1

Error Response

Condition : If token isn't valid or you sent an invalid login pair.

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Delete a User

If you need to change remove a user for any reason.

URL : https://kickstarter-backend.herokuapp.com/api/auth/delete/:id

Method : DELETE

Auth required : YES

Data constraints

{
    "username": "[Valid username that has not been changed]",
    "password": "[New Password]"
}

Data example

{
    "username": "admin",
    "password": "newPassword"
}

Success Response

Code : 204 No Content

Content example

None

Error Response

Condition : If token isn't valid or you sent an invalid login pair.

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Get User by ID

If you need to Register a User use the following information.

URL : https://kickstarter-backend.herokuapp.com/api/auth/:id

Method : GET

Auth required : YES

Success Response

Code : 200 OK

Content example

Grabbing a single User will also give you their kickstarters.

{
    "id": 1,
    "username": "admin",
    "password": "$2a$08$1E8f0RFjlf30c2CL0SRD5eSWJ6EcSvAI5lTsq.GyLacwT8/2iZQkm",
    "kickstarter": [
        {
            "id": 1,
            "user_id": 1,
            "campaignName": "Test_Project_1",
            "categories": "Games",
            "description": "Put the decription here and bla bla bla.",
            "monetaryGoal": 100000,
            "duration": 30,
            "country": "USA"
        },
        {
            "id": 2,
            "user_id": 1,
            "campaignName": "Test_Project_2",
            "categories": "Games",
            "description": "Put the decription here and bla bla bla.",
            "monetaryGoal": 100000,
            "duration": 30,
            "country": "CHINA"
        },
        {
            "id": 3,
            "user_id": 1,
            "campaignName": "Test_Project_3",
            "categories": "Games",
            "description": "Put the decription here and bla bla bla.",
            "monetaryGoal": 100000,
            "duration": 30,
            "country": "RUSSIA"
        },
        {
            "id": 4,
            "user_id": 1,
            "campaignName": "Test_Project_4",
            "categories": "Games",
            "description": "Put the decription here and bla bla bla.",
            "monetaryGoal": 100000,
            "duration": 30,
            "country": "JAPAN"
        }
    ]
}

Error Response

Condition : If an incorrect ID is give.

Code : 500 BAD REQUEST

Content : None, Working on that.

Error Response

Condition : If token isn't valid or you sent an invalid login pair.

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Get a list of all Users

If you need to Register a User use the following information.

URL : https://kickstarter-backend.herokuapp.com/api/auth/

Method : GET

Auth required : YES

Success Response

Code : 201 OK

Content example

Grabbing a single User will also give you their kickstarters.

{
 [  
    {
        "id": 1,
        "username": "admin",
        "password": "$2a$08$1E8f0RFjlf30c2CL0SRD5eSWJ6EcSvAI5lTsq.GyLacwT8/2iZQkm"
    },
    {
        "id": 4,
        "username": "Test2",
        "password": "$2a$08$nauzqJ4ZHsWcPG9148fmS.uBrLE0G3VTJUvVg8FkmxLlQzaFxb3F6"
    },
    {
        "id": 5,
        "username": "Test3",
        "password": "$2a$08$1tGRKflHEVqEhfJq2lZZn.PM/jcDEYAKNRzcYzmmdUGCaU0IEvsoO"
    },
    {
        "id": 6,
        "username": "Test4",
        "password": "$2a$08$AIXiylnFh/kJVPxQE15soOQ6fPrFCh99HPeJ04I7I3QHtr/gL0R2e"
    }
   ]
}

Error Response

Condition : If token isn't valid or you sent an invalid login pair.

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Kickstarter Data

Get Requests

Get a single Kickstarter by ID

URL : https://kickstarter-backend.herokuapp.com/api/kickstarter/:id

Method : GET

Auth required : YES

Data constraints

{
    "username": "[A unique username]",
    "password": "[password in plain text]"
}

Data example

{
    "username": "admin",
    "password": "password"
}

Success Response

Code : 201 Created

Content example

The password that is returned is a hash and not a representation of something that you should use.

{
    "id": 1,
    "user_id": 1,
    "campaignName": "Test_Project_1",
    "categories": "Games",
    "description": "Put the decription here and bla bla bla.",
    "monetaryGoal": 100000,
    "duration": 30,
    "country": "USA"
}

Error Response

Condition : If Token is missing

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Error Response

Condition : If an invalid ID is used.

Code : 404 Not Found

Content :

{
    "message": "Could not find kickstarters with that ID"
}

Get all kickstarters for a single User ID

URL : https://kickstarter-backend.herokuapp.com/api/kickstarter/user/:id

Method : GET

Auth required : YES

Data example

Success Response

Code : 200 OK

Content example

[
    {
        "id": 1,
        "user_id": 1,
        "campaignName": "Test_Project_1",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "USA"
    },
    {
        "id": 2,
        "user_id": 1,
        "campaignName": "Test_Project_2",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "CHINA"
    },
    {
        "id": 3,
        "user_id": 1,
        "campaignName": "Test_Project_3",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "RUSSIA"
    },
    {
        "id": 4,
        "user_id": 1,
        "campaignName": "Test_Project_4",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "JAPAN"
    }
]

Error Response

Condition : If Token is missing

Code : 404 Not Found

Content :

{
    "message": "Could not find kickstarters with that ID"
}

Error Response

Condition : If Token is missing

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Get all Kickstarters

URL : https://kickstarter-backend.herokuapp.com/api/kickstarter/all

Method : GET

Auth required : YES

Data example

Success Response

Code : 200 OK

Content example

[
    {
        "id": 1,
        "user_id": 1,
        "campaignName": "Test_Project_1",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "USA"
    },
    {
        "id": 2,
        "user_id": 2,
        "campaignName": "Test_Project_2",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "CHINA"
    },
    {
        "id": 3,
        "user_id": 3,
        "campaignName": "Test_Project_3",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "RUSSIA"
    },
    {
        "id": 4,
        "user_id": 4,
        "campaignName": "Test_Project_4",
        "categories": "Games",
        "description": "Put the decription here and bla bla bla.",
        "monetaryGoal": 100000,
        "duration": 30,
        "country": "JAPAN"
    }
]

Error Response

Condition : If Token is missing

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Add a Kickstart

It is important to look at how the data is sent. You must include a vaid user_id as a part of the data and in the URL request.

URL : https://kickstarter-backend.herokuapp.com/api/kickstarter/user/:id

Method : POST

Auth required : YES

Data constraints

        { 
	        "user_id": [an ID that matches an existing user],
	        "campaignName": [Unique Kickstarter Name],
	        "monetaryGoal": [Interger],
	        "description": [String],
	        "duration": [Interger],
	        "categories": [String],
	        "country": [String] 
        }

Content example

        { 
	        "user_id": 5,
	        "campaignName": "Test_Project_8",
	        "monetaryGoal": 100000,
	        "description": "Put the decription here and bla bla bla.",
	        "duration": "30",
	        "categories": "Games",
	        "country": "JAPAN" 
        }

Success Response

Code : 201 Created

Content example

{
    "id": 6,
    "user_id": 5,
    "campaignName": "Test_Project_8",
    "categories": "Games",
    "description": "Put the decription here and bla bla bla.",
    "monetaryGoal": 100000,
    "duration": 30,
    "country": "JAPAN"
}

Error Response

Condition : If Invalid user ID is given

Code : 401 Unauthorized

Content :

{
    "message": "The UserID that you sent much match the user_id"
}

Error Response

Condition : If Token is missing

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Update a Kickstart

Updating is just like Posting except that you need to send the KICKSTARTER ID in the URL and not the user you want to attach it to.

URL : https://kickstarter-backend.herokuapp.com/api/kickstarter/:id

Method : PUT

Auth required : YES

Data constraints

        { 
	        "user_id": [an ID that matches an existing user],
	        "campaignName": [Unique Kickstarter Name],
	        "monetaryGoal": [Interger],
	        "description": [String],
	        "duration": [Interger],
	        "categories": [String],
	        "country": [String] 
        }

Content example

0 - [Means nothing was changed]
1 - [Means something was changed]

Error Response

Condition : If Invalid user ID is given

Code : 404 Not Found

Content :

{
    "message": "The UserID that you sent much match the user_id"
}

Error Response

Condition : If Token is missing

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

Delete a Kickstart

Updating is just like Posting except that you need to send the KICKSTARTER ID in the URL and not the user you want to attach it to.

URL : https://kickstarter-backend.herokuapp.com/api/kickstarter/:id

Method : DELETE

Auth required : YES

Data constraints

None, just send the request while logged in.

Content example

Condition : If Successful

Code : 204

Error Response

Condition : If Invalid user ID is given

Code : 404 Not Found

Content :

{
    "message": "Kickstarter not found"
}

Error Response

Condition : If Token is missing

Code : 401 Unauthorized

Content :

{
    "message": "Invalid Login or Token Expired."
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •