Giter Club home page Giter Club logo

market_money's Issues

8. Create a MarketVendor

Details
This endpoint should follow the pattern of POST /api/v0/market_vendors, and it should create a new association between a market and a vendor (so then, the vendor has a new market that they sell at).

When valid ids for vendor and market are passed in, a MarketVendor will be created, and a response will be sent back with a 201 status, detailing that a Vendor was added to a Market.

After implementing the happy path for this endpoint, run it, and check that when you call GET /api/v0/markets/:id/vendors for the vendor in which you just added to a market, that you see the newly associated market listed.

If an invalid vendor id or and invalid market id is passed in, a 404 status code as well as a descriptive message should be sent back with the response.

If a vendor id and/or a market id are not passed in, a 400 status code as well as a descriptive message should be sent back with the response.

If there already exists a MarketVendor with that market_id and that vendor_id, a response with a 422 status code and a message informing the client that that association already exists, should be sent back. Looking at custom validation might help to implement a validation for uniqueness of the attributes for this resource.

Example #1 ๐Ÿ˜
Request:

POST /api/v0/market_vendors
Content-Type: application/json
Accept: application/json
Body:

{
"market_id": 322474,
"vendor_id": 54861
}
(where 322474 and 54861 are valid market and vendor id's.)
Response: status: 201

{
"message": "Successfully added vendor to market"
}

Example #2 ๐Ÿ˜ญ
Request:

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

Body:

{
"market_id": 987654321,
"vendor_id": 54861
}
(where 987654321 is an invalid market id)
Response: status: 404

{
"errors": [
{
"detail": "Validation failed: Market must exist"
}
]
}

Example #3 ๐Ÿ˜ญ
Request:

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

Body:

{
"market_id": 322474,
"vendor_id": 54861
}
(where 322474 and 54861 are valid market and vendor id's, but an existing MarketVendor with those values already exists.)
Response: status: 422

{
"errors": [
{
"detail": "Validation failed: Market vendor asociation between market with market_id=70 and vendor_id=1150 already exists"
}
]
}

11. Get Cash Dispensers Near a Market

Details:

The endpoint should be in the pattern of GET /api/v0/markets/:id/nearest_atms

You will need to utilize the TomTom API for this. Specifically, the category search endpoint.

Find a category that would work for ATMโ€™s, and use the API to find ATMโ€™s near the location of the Farmerโ€™s Market.

The atms that are returned should be in the order of closest to furthest away.

If an invalid market id is passed in, a 404 status as well as a descriptive error message should be sent back in the response.

The data top level key should always point to an array even if one or zero atms were located near the market location.

Example #1 ๐Ÿ˜
Request:

GET /api/v0/markets/327794/nearest_atms
Content-Type: application/json
Accept: application/json
Response: status: 200

{
"data": [
{
"id": null,
"type": "atm",
"attributes": {
"name": "ATM",
"address": "3902 Central Avenue Southeast, Albuquerque, NM 87108",
"lat": 35.07904,
"lon": -106.60068,
"distance": 0.10521432030421865
}
},
{
"id": null,
"type": "atm",
"attributes": {
"name": "ATM",
"address": "4100 Central Avenue Southeast, Albuquerque, NM 87108",
"lat": 35.0788,
"lon": -106.59842,
"distance": 0.14448001321588486
}
},
...,
...,
...,
]
}

Example #2 ๐Ÿ˜ญ
Request:

 GET /api/v0/markets/123123123123/nearest_atm (where `123123123123` is an invalid Market id)
 Content-Type: application/json
 Accept: application/json

Response: status: 404

{
"errors": [
{
"detail": "Couldn't find Market with 'id'=123123123123"
}
]
}

4. Get One Vendor

Details
This endpoint should follow the pattern of GET /api/v0/vendors/:id
If a valid vendor id is passed in, a JSON object is sent back with a top-level data key that points to the vendor resource with that id, and all attributes for that vendor.
If an invalid vendor id is passed in, a 404 status as well as a descriptive error message should be sent back in the response.

Example #1 ๐Ÿ˜
Request:

GET /api/v0/vendors/55297
Content-Type: application/json
Accept: application/json
Response: status: 200

{
"data": {
"id": "55297",
"type": "vendor",
"attributes": {
"name": "Orange County Olive Oil",
"description": "Handcrafted olive oil made from locally grown olives",
"contact_name": "Syble Hamill",
"contact_phone": "1-276-593-3530",
"credit_accepted": false
}
}
}

Request:

 GET /api/v0/vendors/123123123123 (where `123123123123` is an invalid Vendor id)
 Content-Type: application/json
 Accept: application/json

Response: status: 404

{
"errors": [
{
"detail": "Couldn't find Vendor with 'id'=123123123123"
}
]
}

2. Get One Market

Details:
This endpoint should follow the pattern of GET /api/v0/markets/:id.
If a valid market id is passed in, all market attributes, as well as a vendor_count should be returned.
If an invalid market id is passed in, a 404 status as well as a descriptive error message should be sent back in the response.

example 1
Request:

 GET /api/v0/markets/322458
 Content-Type: application/json
 Accept: application/json

Response: status: 200

{
"data": {
"id": "322458",
"type": "market",
"attributes": {
"name": "14&U Farmers' Market",
"street": "1400 U Street NW ",
"city": "Washington",
"county": "District of Columbia",
"state": "District of Columbia",
"zip": "20009",
"lat": "38.9169984",
"lon": "-77.0320505",
"vendor_count": 1
}
}
}

Example #2 ๐Ÿ˜ญ
Request:

 GET /api/v0/markets/123123123123 (where `123123123123` is an invalid Market id)
 Content-Type: application/json
 Accept: application/json

Response: status: 404

{
"errors": [
{
"detail": "Couldn't find Market with 'id'=123123123123"
}
]
}

6. Update a Vendor

Details
This endpoint should follow the pattern of PATCH /api/v0/vendors/:id, and can pass any number and combination of attribtues to be updated (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)

This endpoint should update an existing vendor with any parameters sent in via the body.

If someone were to try to update a vendor resource to have a nil or empty attribute, a proper 400-level status code as well as a descriptive error message should be sent back in the response.

A successful response will return the newly updated vendor resource.

Example #1 ๐Ÿ˜
Request:

PATCH /api/v0/vendors/56542
Content-Type: application/json
Accept: application/json
Body:

{
"contact_name": "Kimberly Couwer",
"credit_accepted": false
}
Response: status: 200

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

Example #2 ๐Ÿ˜ญ
Request:

 PATCH /api/v0/vendors/123123123123 (where `123123123123` is an invalid Vendor id)
 Content-Type: application/json
 Accept: application/json

Body:

{
"contact_name": "Kimberly Couwer",
"credit_accepted": false
}
Response: status: 404

{
"errors": [
{
"detail": "Couldn't find Vendor with 'id'=123123123123"
}
]
}

Example #3 ๐Ÿ˜ญ
Request:

 PATCH /api/v0/vendors/56542 (where `56542` is a valid Vendor id)
 Content-Type: application/json
 Accept: application/json

Body:

{
"contact_name": "",
"credit_accepted": false
}
Response: status: 400

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

1. Get All Markets Details:

This endpoint should follow the pattern of GET /api/v0/markets and should return ALL markets in the database.
In addition to the marketโ€™s main attributes, the market resource should also list an attribute for vendor_count, which is the number of vendors that are associated with that market.

Example #1 ๐Ÿ˜
Request:

 GET /api/v0/markets
 Content-Type: application/json
 Accept: application/json

Response: status: 200

{
"data": [
{
"id": "322458",
"type": "market",
"attributes": {
"name": "14&U Farmers' Market",
"street": "1400 U Street NW ",
"city": "Washington",
"county": "District of Columbia",
"state": "District of Columbia",
"zip": "20009",
"lat": "38.9169984",
"lon": "-77.0320505",
"vendor_count": 1
}
},
{
"id": "322474",
"type": "market",
"attributes": {
"name": "2nd Street Farmers' Market",
"street": "194 second street",
"city": "Amherst",
"county": "Amherst",
"state": "Virginia",
"zip": "24521",
"lat": "37.583311",
"lon": "-79.048573",
"vendor_count": 35
}
},
...,
...,
]
}

10. Search Markets by state, city, and/or name

Details:

The endpoint should be in the pattern of GET /api/v0/markets/search, and can accept city, state, and name parameters.

The following combination of parameters can be sent in at any time:

  • state
  • state, city
  • state, city, name
  • state, name
  • name

The following combination of parameters can NOT be sent in at any time:

  • city
  • city, name

If an invalid set of parameters are sent in, a proper error message should be sent back, along with a 422 status code.

In the event that valid parameters are sent in, and only one market is returned from the search, the data top level key should still point to an array holding that one market resource data.

Similar to above, in the event that valid parameters are sent in, and NO markets are returned, the data top level key should point to an empty array. And a status code of 200 should still be returned

Example #1 ๐Ÿ˜
Request:

GET /api/v0/markets/search?city=albuquerque&state=new Mexico&name=Nob hill
Content-Type: application/json
Accept: application/json
Response: status: 200

{
"data": [
{
"id": "327794",
"type": "market",
"attributes": {
"name": "Nob Hill Growers' Market",
"street": "Lead & Morningside SE",
"city": "Albuquerque",
"county": "Bernalillo",
"state": "New Mexico",
"zip": null,
"lat": "35.077529",
"lon": "-106.600449",
"vendor_count": 5
}
}
]
}

Example #2 ๐Ÿ˜ญ
Request:

 GET /api/v0/markets/search?city=albuquerque
 Content-Type: application/json
 Accept: application/json

Response: status: 422

{
"errors": [
{
"detail": "Invalid set of parameters. Please provide a valid set of parameters to perform a search with this endpoint."
}
]
}

3. Get All Vendors for a Market

Details
This endpoint should follow the pattern of GET /api/v0/markets/:id/vendors
If a valid market id is passed in, a JSON object is sent back with a top-level data key that points to a collection of that marketโ€™s vendors. Each vendor contains all of itโ€™s attributes.
If an invalid market id is passed in, a 404 status as well as a descriptive error message should be sent back in the response.

example 1
Request:

GET /api/v0/markets/322474/vendors
Content-Type: application/json
Accept: application/json
Response: status: 200

{
"data": [
{
"id": "55297",
"type": "vendor",
"attributes": {
"name": "Orange County Olive Oil",
"description": "Handcrafted olive oil made from locally grown olives",
"contact_name": "Syble Hamill",
"contact_phone": "1-276-593-3530",
"credit_accepted": false
}
},
{
"id": "56227",
"type": "vendor",
"attributes": {
"name": "The Vodka Vault",
"description": "Handcrafted vodka with a focus on unique and unusual flavors",
"contact_name": "Rueben Parker DVM",
"contact_phone": "1-140-885-8633",
"credit_accepted": true
}
},
...,
...,
]
}

Example #2 ๐Ÿ˜ญ
Request:

 GET /api/v0/markets/123123123123/vendors (where `123123123123` is an invalid Market id)
 Content-Type: application/json
 Accept: application/json

Response: status: 404

{
"errors": [
{
"detail": "Couldn't find Market with 'id'=123123123123"
}
]
}

5. Create a Vendor

Details
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)

This endpoint should create a new vendor resource.

A successful response will return a response with a 201 status code, and return the newly created vendor resource.

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.

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"
}
]
}

7. Delete a Vendor

Details
This endpoint should follow the pattern of DELETE /api/v0/vendors/:id
When a valid id is passed in, that vendor will be destroyed, as well as any associations that vendor had. A status code of 204 should be sent back, without any content in the body.
If an invalid id is passed in, a 404 status code as well as a descriptive message should be sent back with the response.

Example #1 ๐Ÿ˜
Request:

DELETE /api/v0/vendors/56542
Content-Type: application/json
Accept: application/json
Response: status: 204

Example #2 ๐Ÿ˜ญ
Request:

 DELETE /api/v0/vendors/123123123123 (where `123123123123` is an invalid Vendor id)
 Content-Type: application/json
 Accept: application/json

Response: status: 404

{
"errors": [
{
"detail": "Couldn't find Vendor with 'id'=123123123123"
}
]
}

9. Delete a MarketVendor

Details

This endpoint should follow the pattern of DELETE /api/v0/market_vendors, and it should destroy an existing association between a market and a vendor (so that a vendor no longer is listed at a certain market).

The market_id and the vendor_id should be passed in via the body.

When a MarketVendor resource can be found with the passed in vendor_id and market_id, that resource should be destroyed, and a response will be sent back with a 204 status, with nothing returned in the body of the request.

After implementing the happy path for this endpoint, run it, and check that when you call GET /api/v0/vendors/:id/markets for the vendor in which you just deleted an association to a market, that you donโ€™t see the recently removed market listed.

If a MarketVendor resource can NOT be found with the passed in vendor_id and market_id, a 404 status code as well as a descriptive message should be sent back with the response.

Example #1 ๐Ÿ˜
Request:

DELETE /api/v0/market_vendors
Content-Type: application/json
Accept: application/json
Body:

{
"market_id": 322474,
"vendor_id": 54861
}
Response: status: 204

Request:

 DELETE /api/v0/market_vendors
 Content-Type: application/json
 Accept: application/json

Body:

{
"market_id": 4233,
"vendor_id": 11520
}
(where there is no MarketVendor that has a market_id=4233 AND a vendor_id=11520)
Response: status: 404

{
"errors": [
{
"detail": "No MarketVendor with market_id=4233 AND vendor_id=11520 exists"
}
]
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.