LeahK / CowCareMobileApplication

This is a working version of the Katy's Cow Care Mobile Application.
0 stars 1 forks source link

Clicking on a presented choice in screen 3 sends HTTP request that updates or creates the calf. #9

Open buckmaxwell opened 8 years ago

buckmaxwell commented 8 years ago

For reference on screen information see here.

Clicking on a presented choice will send an HTTP request that will update or create the calf. The options will then be reloaded. If the option requires wait time, or the option clicked is a final option* the user will be "bounced" back to screen 2.

CASE 1 If the user came to screen 3 by supplying null for the calf (AKA they clicked on the '+') button, a POST request must be sent to the calves collection endpoint.

POST /calves?include=treatment_plan

The request body for this request should look something like

{
  "data": {
    "type": "calves",
    "attributes": {
      "id": "d262ed33-7dd7-449d-834a-4b5817c16e66",
      "type": "calves"
    },
    "relationships": {
      "farm": {
        "data": {
          "type": "farms",
          "id": "b89ef3f0-ccaa-4122-8b76-b92c38f2e560"
        }
      },
      "treatment_plan": {
        "data": {
          "type": "treatment_plans",
          "id": "ed86977e-ac5d-44b2-905b-f1d13562f869"
        }
      }
    }
  }
}

CASE 2 If the user came to screen 3 by supplying a representation of the calf object (AKA they clicked on an individual calf id), a PATCH request must be sent to the individual calf endpoint after the user selects their option. This patch request will include a partial implementation of the calf object, with the treatment_plan_position attribute set to the new current position in the treatment plan.

PATCH /calves/d262ed33-7dd7-449d-834a-4b5817c16e66
{
  "data": {
    "type": "calves",
    "id": "d262ed33-7dd7-449d-834a-4b5817c16e66",
    "attributes": {
      "treatment_plan_position": "231b840e-31de-4335-be68-28a19553c48c"
    }
}

BOTH Note. The server will return a 201 or a 204 for successful requests to post and patch respectively. 204s will have no response body. Do not worry about this. Since the treatment plan is already stored completely on the phone, it will be easy to load the next options. If the option selected requires waiting, or is a final option make sure the user is redirected back to screen 2, ideally with a useful 'toast' or message.

*A final option is an option that has no children. Examples of final options in treatment plans would be "Calf totally recovers", or "Calf must be euthanized".

buckmaxwell commented 8 years ago

@LeahK @liu1372 , POST and PATCH methods to calves as shown here are working for the mock server at

POST http://private-a59ad-katyscareapi.apiary-mock.com/calves?include=treatment_plan

PATCH http://private-a59ad-katyscareapi.apiary-mock.com/calves