ethanrossblack / market_money_erb

Market Money API creation project for Turing Mod 3
0 stars 0 forks source link

5. Create a Vendor #5

Closed ethanrossblack closed 1 year ago

ethanrossblack commented 1 year ago

5. Create a Vendor

Details

  1. This endpoint should follow the pattern of POST /api/v0/vendors, and should pass ALL attributes required to create a vendor (name, description, contact_name, contact_phone, and credit_accepted) as JSON in the body of the request. (In postman, navigate to Body tab, select raw and change the format to JSON instead of Text)
  2. This endpoint should create a new vendor resource.
  3. A successful response will return a response with a 201 status code, and return the newly created vendor resource.
  4. If any number of attributes are left out in the body of the request, a status code of 400, as well as a descriptive error message should be sent back in the response.
  5. Validating the presence of a boolean value can be tricky since false is evaluated as nil. Validating the presence of a field that could be false will generate some a validation error when we don't mean it to. We'd suggest creating your own custom validation for validating the presence of a boolean field.

Example 1 😁

Request:

  POST /api/v0/vendors
  Content-Type: application/json
  Accept: application/json

Body:

{
    "name": "Buzzy Bees",
    "description": "local honey and wax products",
    "contact_name": "Berly Couwer",
    "contact_phone": "8389928383",
    "credit_accepted": false
}

Response: status: 201

{
    "data": {
        "id": "56542",
        "type": "vendor",
        "attributes": {
            "name": "Buzzy Bees",
            "description": "local honey and wax products",
            "contact_name": "Berly Couwer",
            "contact_phone": "8389928383",
            "credit_accepted": false
        }
    }
}

Example 2 😭

Request:

    POST /api/v0/vendors
    Content-Type: application/json
    Accept: application/json

Body:

  {
      "name": "Buzzy Bees",
      "description": "local honey and wax products",
      "credit_accepted": false
  }

Response: status: 400

{
  "errors": [
      {
          "detail": "Validation failed: Contact name can't be blank, Contact phone can't be blank"
      }
  ]
}