Course project for comsw4156
Team Name: Alohomora
python
pip3 install -r requirements.txt
flask run
coverage run -m unittest discover
coverage html
The flake8 and coverage reports have been stored in the report
folder.
When the master branch is changed, CI will deploy the code to the host below automatically:
https://w4156-alohomora.herokuapp.com/
ci reports can be found by clicking details
:
This API is used for new user registration
-
body should follow form-encoded request bodies (x-www-form-urlencoded):
-
Example:
email:[email protected]
password:123412345
name:testtestuser
mobile_phone:8148888477
zipcode:10026
-
status code: 201
-
output:
{"error": ""}
-
status code: 400
-
output:
{"Input error": form.errors}
-
example:
{"Input error": {"email": ["Invalid email address."]}}
-
status code: 500
-
output:
{"error": "db error: **"}
-
example:
{"error": "db error: UNIQUE constraint failed: User.email"}
This API is used by user to post a new furniture on the platform.
- body should respect the following json schema:
{
"type": "object",
"required": ["title", "labels", "image_url", "description"],
"properties": {
"title": {"type": "string"},
"labels": {"type": "string"},
"image_url": {"type": "string"},
"description": {"type": "string"},
}
}
- Example:
{
"title": "iPhone 12",
"labels": "like new, phone",
"image_url": "https://www.google.com/url?sa=i&url=https%3A%2F%2Funsplash.com%2Fs%2Fphotos%2Fiphone&psig=AOvVaw0_LC7YH4CTStenQE3A95aw&ust=1637075168411000&source=images&cd=vfe&ved=0CAsQjRxqFwoTCNi2n7HSmvQCFQAAAAAdAAAAABAG",
"description": "This is a brand new iphone 12 with box"
}
-
status code: 200
-
output:
{"error": ""}
-
status code: 400
-
output:
{"error": "invalid input"}
-
status code: 500
-
output:
{"error": "Internal error"}
Search funiture items based on user input(furniture labels)
- Example:
GET /furniture?keyword="monitor"
{
"furniture": [
{
"fid": 1,
"owner": Bob,
"title": "Alienware Gaming Monitors",
"labels": "monitor",
"status": "init",
"image_url": "",
"description": "This is a monitor"
}
}
Get user's profile page
- Example:
GET /profile?keyword="[email protected]"
{
"email": "[email protected]",
"name": "rick",
"zipcode": 100000,
"phone_number": 123123
}
-
status code: 201
-
output:
{"error": ""}
-
status code: 400
-
output:
{"error": "input invalid."}
-
status code: 500
-
output:
{"error": "internal error"}
User login
- Example:
{
"email": "[email protected]",
"passowrd": "password"
}
-
status code: 200
-
output:
{"error": ""}
-
status code: 400
-
output:
{"error": "invalid input"}
-
status code: 400
-
output:
{"error": "No such email [email protected]"}
-
status code: 400
-
output:
{"error": "wrong password [email protected]"}
-
status code: 500
-
output:
{"error": "Internal error"}
Used by a buyer to rate the owner of a furniture with the id of after the transaction is completed. The rating score is specified by <rating>.
<rating> should be between an integer between 0 and 5.
- Example:
POST /furnitures/f123/rate?rating=5
- status code: 200
- output:
{
"error": ""
}
- status: 400
- output:
{
"error": "<specific reason>"
}
- status: 500
- output:
{
"error": "<specific reason>"
}
Used by a buyer to show the intention to buy a furniture.
- Example:
POST /furnitures/1/buy
- status code: 200
- output:
{
"error": ""
}
- status: 400
- output:
{
"error": ""furniture not existed"
}
- status: 400
- output:
{
"error": ""The item is already sold or in progress"
}
- status: 500
- output:
{
"error": "<specific reason>"
}
Used by a furniture owner to confirm the pending transaction with the id of when the transaction is pending. Confirm/not confirm is true/false depend on params. If confirm=False, the furniture status goes back to "init", and buyer is set to NULL.
- Example:
POST /furnitures/1/confirm?confirm=True
- status code: 200
- output:
{
"error": ""
}
- status: 400
- output:
{
"error": "fid not existed."
}
{
"error": "Only owner can confirm the transaction."
}
{
"error": "the owner can only confirm the pending transaction"
}
- status: 500
- output:
{
"error": "f'db error <specific reason>"
}