neilscallywag / SupportMe

A smaller clone of change.org for learning purposes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SupportMe

Our implementation of a business logic similar to change.org using vanilla PHP, REST api design and content learned during "Operating System and Networking Module" in SMU.

Endpoints

1. Register

POST /register

Request

Attribute Type Required Description
firstname String Yes First name
lastname String No Last name
email String Yes Email
password String Yes Password
{
  "firstname": "sunset boulevard",
  "lastname": "test",
  "email": "mainuser@lol.com",
  "password": 1234
}

Response

{ "message": "Successfully registered" }

2. Login

POST /login

Request

Attribute Type Required Description
email String Yes Registered email
password String Yes Password
{
  "email": "mainuser@lol.com",
  "password": 1234
}

Response

{
  "message": "Login successful",
  "token": "JWT-TOKEN"
}

3. Create campaign

POST /campaign/create

Request

Attribute Type Required Description
user_id int Yes user id accessing website
campaign_title str Yes Title of campaign
campaign_description str Yes Description of campaign
campaign_picture str No Picture encoded in base64
{
  "user_id": 1243,
  "campaign_title": "title_here",
  "campaign_description": "description here",
  "campaign_picture": "picture in base64 string"
}

Response

{
  "message": "Campaign successfully created"
}

4. Fetch Campaign

POST /campaign/id/[:cid]

Request

Authorisation Header Required

Attribute Type Required Description
id Int Yes Campaign ID

Response - Success 200

{
  "user_id": "",
  "c_title": "",
  "c_description": "",
  "c_picture": "",
  "updatedAt": ""
}

Response - Fail 204

{
  "error": "No Such Campaign"
}

5. Search Campaign

GET /campaign/search/[*:str]

Request

Authorisation Header Required

Attribute Type Required Description
str string Yes String mathing campaign name

Response - Success 200

{
  "user_id": "",
  "c_title": "",
  "c_description": "",
  "c_picture": "",
  "updatedAt": ""
}

Response - Fail 204

{
  "message": "No Campaign Found"
}

6. Delete Campaign

GET /campaign/delete/[i:cid]

Request

Authorisation Header Required

Attribute Type Required Description
cid int Yes Campaign Identifier

Response - Success 200

{
  "message": "Campaign successfully deleted"
}

Response - Fail 401

{
  "error": "Campaign was not created by user/ is non-existent"
}

7. Edit Campaign

POST /campaign/edit/[i:cid]

Request

Authorisation Header Required

Attribute Type Required Description
cid int Yes Campaign Identifier
user_id int Yes user id accessing website
campaign_title str Yes Title of campaign
campaign_description str Yes Description of campaign
campaign_picture str No Picture encoded in base64
{
  "user_id": 1243,
  "campaign_title": "title_here",
  "campaign_description": "description here",
  "campaign_picture": "picture in base64 string"
}

Response - Success 200

{
  "message": "campaign successfully edited"
}

Response - Fail 400

{
  "error": "Campaign was not created by user/ is non-existent"
}

8. Fetch Campaigns by user

POST /user/campaigns

Request

Authorisation Header Required from which the user id is extracted

Response - Success 200

{
  "user_id": "",
  "c_title": "",
  "c_description": "",
  "c_picture": "",
  "updatedAt": ""
}

Response - Fail 204

{
  "message": "No Campaign Found"
}

9. Add Comments

POST /campaign/[i:cid]/add_comment

Request

Authorisation Header Required from which the user id is extracted

Attribute Type Required Description
cid int Yes Campaign Identifier
comment_text str Yes Comment Text

Response - Success 200

{
  "message": "Successfully added comment"
}

Response - Fail 400

{
  "error": ""
}

10. Edit Comments

POST /campaign/edit_comment/[i:coid]

Request

Authorisation Header Required from which the user id is extracted

Attribute Type Required Description
comment_id int Yes comment Identifier
comment_text str Yes Comment Text

Response - Success 200

{
  "message": "Successfully changed comment"
}

Response - Fail 400

{
  "error": ""
}

11. delete Comments

POST /campaign/delete_comment/[i:cid]

Request

Authorisation Header Required from which the user id is extracted

Attribute Type Required Description
comment_id int Yes comment Identifier

Response - Success 200

{
  "message": "Successfully deleted comment"
}

Response - Fail 400

{
  "error": ""
}

12. Get pledge count for a given campaign

POST /campaign/pledge_count/[*:cid]

Request

Authorisation Header Required from which the user id is extracted

Attribute Type Required Description
campaign_id int Yes campaign Identifier

Response - Success 200

{
  "pledge_count": 00
}

Response - Fail 400

{
  "error": ""
}

13. Get list of all pledgers for a given campaign

POST /campaign/pledge_list/[*:cid]

Request

Authorisation Header Required from which the user id is extracted

Attribute Type Required Description
campaign_id int Yes campaign Identifier

Response - Success 200

{
  "pledge_count": 00
}

Response - Fail 400

{
  "error": ""
}

14. Pledge to a given campaign

POST /campaign/pledge/[*:cid]

Request

Authorisation Header Required from which the user id is extracted

Attribute Type Required Description
campaign_id int Yes campaign Identifier

Response - Success 200

{
  "message": "Pledge successfully added"
}

Response - Fail 400

{
  "error": ""
}

15. Unpledge from a given campaign

POST /campaign/unpledge/[*:cid]

Request

Authorisation Header Required from which the user id is extracted

Attribute Type Required Description
campaign_id int Yes campaign Identifier

Response - Success 200

{
  "message": "Pledge deleted"
}

Response - Fail 400

{
  "error": ""
}

Installation

  1. Clone the repository
git clone https://github.com/neilscallywag/SupportMe.git
  1. Make sure you have Composer installed. Move to the directory where you have composer.json with the command prompt and run the following command:
composer install
  • Change the inc/config.php's private_key to your own private key and ISSUER to your own issuer.

Database Entity Relationship Schema

Database Schema

Testing Commands

Note : user_id do not need to be given as it is encoded in JWT

curl -i  -H "User-Agent: Chrome" -d "{ \"email\":\"mainuser@lol.com\",\"password\":1234 }" -X POST localhost/login
curl -i -X POST -d "{ \"firstname\":\"sunset boulevard\",\"lastname\":\"test\",\"email\":\"mainuser@lol.com\",\"password\":1234 }" localhost/register
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":6}" -i -X POST  localhost/campaign/id/1
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":6}" -i -X POST  localhost/campaign/search/save%20my
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8, \"campaign_title\":\"Let us eat cake\",\"campaign_description\":\"shit have flight eh\",\"campaign_picture\":\"base 64 string here\"}" -i -X POST  localhost/campaign/create
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8 }" -i -X POST  localhost/user/campaigns
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8 }" -i -X POST  localhost/campaign/comments/1
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8 }" -i -X POST  localhost/campaign/pledge_count/1

#note user id is not provided in the json

curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8, \"pledge_reason\": \"i love you\" }" -i -X POST  localhost/campaign/pledge/1
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{ \"comment_text\": \"i love you\" }" -i -X POST  localhost/campaign/edit_comment/1
curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8, \"campaign_title\":\"Let us eat cake\",\"campaign_description\":\"shit have flight eh\",\"campaign_picture\":\"base 64 string here\"}" -i -X POST  localhost/campaign/edit/1

About

A smaller clone of change.org for learning purposes


Languages

Language:PHP 100.0%