Joshua : This project is my first software project.
- Learned about the MVC model and REST API MVC helped to organise our code and encapsulate logic, making it easier to collaborate and work on our respective parts
- Learned how to manage sessions using JSON WEB Token Session is still stored in the databse. This allows for a token access to be revoked if neccessary.
- Learned about how "router" work in context of REST API Learned how backend is commonly build upon HTTP protocol and how to design a simple CRUD API for campaigns
- If we were to write another API in PHP, we would use a different router, as Klien support of exception handling is lacking especially for SQL erors
- Image upload feature can be improved as currently the picture needs to be converted to a base 64 string before transmitted
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.
- SupportMe
- Endpoints
- 1. Register
- 2. Login
- 3. Create campaign
- 4. Fetch Campaign
- 5. Search Campaign
- 6. Delete Campaign
- 7. Edit Campaign
- 8. Fetch Campaigns by user
- 9. Add Comments
- 10. Edit Comments
- 11. delete Comments
- 12. Get pledge count for a given campaign
- 13. Get list of all pledgers for a given campaign
- 14. Pledge to a given campaign
- 15. Unpledge from a given campaign
- Installation
- Database Entity Relationship Schema
- Testing Commands
POST /register
| Attribute | Type | Required | Description |
|---|---|---|---|
firstname |
String | Yes | First name |
lastname |
String | No | Last name |
email |
String | Yes | |
password |
String | Yes | Password |
{
"firstname": "sunset boulevard",
"lastname": "test",
"email": "[email protected]",
"password": 1234
}{ "message": "Successfully registered" }POST /login
| Attribute | Type | Required | Description |
|---|---|---|---|
email |
String | Yes | Registered email |
password |
String | Yes | Password |
{
"email": "[email protected]",
"password": 1234
}{
"message": "Login successful",
"token": "JWT-TOKEN"
}POST /campaign/create
| 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"
}{
"message": "Campaign successfully created"
}POST /campaign/id/[:cid]
Authorisation Header Required
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
Int | Yes | Campaign ID |
{
"user_id": "",
"c_title": "",
"c_description": "",
"c_picture": "",
"updatedAt": ""
}{
"error": "No Such Campaign"
}GET /campaign/search/[*:str]
Authorisation Header Required
| Attribute | Type | Required | Description |
|---|---|---|---|
str |
string | Yes | String mathing campaign name |
{
"user_id": "",
"c_title": "",
"c_description": "",
"c_picture": "",
"updatedAt": ""
}{
"message": "No Campaign Found"
}GET /campaign/delete/[i:cid]
Authorisation Header Required
| Attribute | Type | Required | Description |
|---|---|---|---|
cid |
int | Yes | Campaign Identifier |
{
"message": "Campaign successfully deleted"
}{
"error": "Campaign was not created by user/ is non-existent"
}POST /campaign/edit/[i:cid]
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"
}{
"message": "campaign successfully edited"
}{
"error": "Campaign was not created by user/ is non-existent"
}POST /user/campaigns
Authorisation Header Required from which the user id is extracted
{
"user_id": "",
"c_title": "",
"c_description": "",
"c_picture": "",
"updatedAt": ""
}{
"message": "No Campaign Found"
}POST /campaign/[i:cid]/add_comment
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 |
{
"message": "Successfully added comment"
}{
"error": ""
}POST /campaign/edit_comment/[i:coid]
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 |
{
"message": "Successfully changed comment"
}{
"error": ""
}POST /campaign/delete_comment/[i:cid]
Authorisation Header Required from which the user id is extracted
| Attribute | Type | Required | Description |
|---|---|---|---|
comment_id |
int | Yes | comment Identifier |
{
"message": "Successfully deleted comment"
}{
"error": ""
}POST /campaign/pledge_count/[*:cid]
Authorisation Header Required from which the user id is extracted
| Attribute | Type | Required | Description |
|---|---|---|---|
campaign_id |
int | Yes | campaign Identifier |
{
"pledge_count": 00
}{
"error": ""
}POST /campaign/pledge_list/[*:cid]
Authorisation Header Required from which the user id is extracted
| Attribute | Type | Required | Description |
|---|---|---|---|
campaign_id |
int | Yes | campaign Identifier |
{
"pledge_count": 00
}{
"error": ""
}POST /campaign/pledge/[*:cid]
Authorisation Header Required from which the user id is extracted
| Attribute | Type | Required | Description |
|---|---|---|---|
campaign_id |
int | Yes | campaign Identifier |
{
"message": "Pledge successfully added"
}{
"error": ""
}POST /campaign/unpledge/[*:cid]
Authorisation Header Required from which the user id is extracted
| Attribute | Type | Required | Description |
|---|---|---|---|
campaign_id |
int | Yes | campaign Identifier |
{
"message": "Pledge deleted"
}{
"error": ""
}- Clone the repository
git clone https://github.com/neilscallywag/SupportMe.git- 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_keyto your own private key andISSUERto your own issuer.
Note : user_id do not need to be given as it is encoded in JWT
curl -i -H "User-Agent: Chrome" -d "{ \"email\":\"[email protected]\",\"password\":1234 }" -X POST localhost/logincurl -i -X POST -d "{ \"firstname\":\"sunset boulevard\",\"lastname\":\"test\",\"email\":\"[email protected]\",\"password\":1234 }" localhost/registercurl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":6}" -i -X POST localhost/campaign/id/1curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":6}" -i -X POST localhost/campaign/search/save%20mycurl -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/createcurl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8 }" -i -X POST localhost/user/campaignscurl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{\"user_id\":8 }" -i -X POST localhost/campaign/comments/1curl -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/1curl -H "Authorization: YOUR_ISSUER JWT_TOKEN" -H "User-Agent: Chrome" -d "{ \"comment_text\": \"i love you\" }" -i -X POST localhost/campaign/edit_comment/1curl -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