ARE WE NEGAN?
System for share resources between non-infected humans
- Info Resources
- List Survivors
- Add Survivors
- Update Survivor Location
- Flag Survivor as Infected
- Exchange Resources
- Percentage of infected survivors
- Percentage of non-infected survivors
- Average Resources By Survivor
- Points lost because of infected survivors
- Testing with RSpec
- Clone the project.
https://kadusim@bitbucket.org/kadusim/zssn-api.git
- Bundle the Gems.
bundle install
- Default resources.
rails db:create
rails db:migration
rails db:seed
- Start the application
rails s
Application will be runing at localhost:3000.
GET api/resources`
status: 200 Ok
Content-Type: "application/json"
Body:
[
{
"id": 1,
"item": "water",
"value": 4
},
{
"id": 2,
"item": "food",
"value": 3
},
{
"id": 3,
"item": "medication",
"value": 2
},
{
"id": 4,
"item": "ammunition",
"value": 1
}
]
GET api/survivors`
status: 200 Ok
Content-Type: "application/json"
Body:
[
{
"id": 1,
"name": "Kadu",
"age": 29,
"gender": "M",
"latitude": "12.783827",
"longitude": "78.821028",
"infected": false,
"resources": [
{
"id": 2,
"item": "food",
"value": 3,
"created_at": "2018-04-30T14:38:44.776Z",
"updated_at": "2018-04-30T14:38:44.776Z"
},
{
"id": 1,
"item": "water",
"value": 4,
"created_at": "2018-04-30T14:38:44.753Z",
"updated_at": "2018-04-30T14:38:44.753Z"
}
]
},
{
"id": 3,
"name": "Nalu",
"age": 9,
"gender": "F",
"latitude": "22.874897",
"longitude": "-74.982948",
"infected": false,
"resources": [
{
"id": 3,
"item": "medication",
"value": 2,
"created_at": "2018-04-30T14:38:44.789Z",
"updated_at": "2018-04-30T14:38:44.789Z"
}
]
}
]
POST api/survivors`
Parameters:
{
"survivor": {
"name": "Celia",
"age": "29",
"gender": "F",
"latitude": "25.874897",
"longitude": "-77.9829482",
"infected": false,
"inventory_attributes": {
"inventory_resources_attributes": [
{ "resource_id": 1 },
{ "resource_id": 2 },
{ "resource_id": 3 },
{ "resource_id": 3 },
{ "resource_id": 4 }
]
}
}
}
status: 201 created
Content-Type: "application/json"
Body:
{
"id": 5,
"name": "Celia",
"age": 23,
"gender": "M",
"latitude": "25.874897",
"longitude": "-77.982948",
"infected": false,
"resources": [
{
"id": 1,
"item": "water",
"value": 4,
"created_at": "2018-04-30T14:38:44.753Z",
"updated_at": "2018-04-30T14:38:44.753Z"
},
{
"id": 2,
"item": "food",
"value": 3,
"created_at": "2018-04-30T14:38:44.776Z",
"updated_at": "2018-04-30T14:38:44.776Z"
},
{
"id": 3,
"item": "medication",
"value": 2,
"created_at": "2018-04-30T14:38:44.789Z",
"updated_at": "2018-04-30T14:38:44.789Z"
},
{
"id": 3,
"item": "medication",
"value": 2,
"created_at": "2018-04-30T14:38:44.789Z",
"updated_at": "2018-04-30T14:38:44.789Z"
},
{
"id": 4,
"item": "ammunition",
"value": 1,
"created_at": "2018-04-30T14:38:44.800Z",
"updated_at": "2018-04-30T14:38:44.800Z"
}
]
}
Status | Error | Message |
---|---|---|
422 | unprocessable_entity | {field} can't be blank |
PATCH/PUT api/survivors/:id
Parameters:
{
"survivor": {
"latitude": "12.7838273",
"longitude": "78.8210282"
}
}
status: 204 no_content
Content-Type: "application/json"
Status | Error |
---|---|
404 | Not Found |
POST api/infected_report
Parameters:
Body:
{
"survivor_id": 2,
"reporter_id": 4
}
status: 201 created
Content-Type: "application/json"
Body:
{
"message": "Survivor reported successfully"
}
Status | Error | Description |
---|---|---|
422 | unprocessable_entity | Reporter has already reported the survivor |
404 | Not Found | Couldn't find Survivor |
403 | Forbidden | Survivor or reporter was infected |
POST api/exchanges
Parameters:
{
"exchanges": {
"survivor_one": {
"id": 1,
"resources": [
{
"resource_id": 4,
"quantity": 2
},
{
"resource_id": 3,
"quantity": 1
}
]
},
"survivor_two": {
"id": 3,
"resources": [
{
"resource_id": 1,
"quantity": 1
}
]
}
}
}
status: 200 ok
Content-Type: "application/json"
Body:
{
"message": "Successful exchange"
}
Status | Error | Message |
---|---|---|
404 | Not Found | Couldn't find Survivor with 'id'={id} |
401 | Unauthorized | Be careful, survivor id:{id} is infected |
401 | Unauthorized | Survivor id:{id} no have enough resources for exchange |
401 | Unauthorized | An exchange must be made with the same amount of points |
GET api/reports/percentage_infected_survivors
status: 200 ok
Content-Type: "application/json"
Body:
{
"percentage": "50.0"
}
status: 200 ok if no survivors
Body:
{
"message": "No survivors found"
}
GET api/reports/percentage_non_infected_survivors
status: 200 ok
Content-Type: "application/json"
Body:
{
"percentage": "50.0"
}
status: 200 ok if no survivors
Body:
{
"message": "No survivors found"
}
GET api/reports/average_resources_by_survivor
status: 200 ok
Content-Type: "application/json"
Body:
{
"averages": {
"water": 10,
"food": 5,
"medication": 2,
"ammunition": 30
}
}
status: 200 ok if no survivors
Body:
{
"message": "No survivors found"
}
GET api/reports/points_lost_because_infected
status: 200 ok
Content-Type: "application/json"
Body:
{
"points_lost": 100
}
status: 200 ok if no survivors
Body:
{
"message": "No survivors found"
}
- Execute all tests
rspec
- by Kadu Simões