Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8. Create a MarketVendor #8

Open
JorjaF opened this issue Aug 28, 2023 · 0 comments
Open

8. Create a MarketVendor #8

JorjaF opened this issue Aug 28, 2023 · 0 comments

Comments

@JorjaF
Copy link
Owner

JorjaF commented Aug 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant