Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 92 additions & 4 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ paths:
type: integer
minimum: 1
maximum: 100
default: 20
description: Maximum number of items to return (default 20)
- name: offset
in: query
schema:
type: integer
minimum: 0
default: 0
description: Number of items to skip before starting to collect the result set (default 0)
- name: currency
in: query
schema:
Expand All @@ -67,6 +75,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

post:
tags:
Expand All @@ -90,6 +100,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

/sneakers/{id}:
get:
Expand All @@ -114,6 +126,9 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

put:
tags:
- sneakers
Expand Down Expand Up @@ -147,6 +162,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

delete:
tags:
Expand All @@ -166,7 +183,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }

'500':
$ref: '#/components/responses/InternalServerError'

# REVIEWS

Expand Down Expand Up @@ -195,6 +213,9 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

post:
tags:
- reviews
Expand Down Expand Up @@ -233,6 +254,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

/reviews/{reviewId}:
get:
Expand All @@ -257,6 +280,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

put:
tags:
Expand Down Expand Up @@ -286,6 +311,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

delete:
tags:
Expand All @@ -305,7 +332,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }

'500':
$ref: '#/components/responses/InternalServerError'

# USERS

Expand Down Expand Up @@ -338,6 +366,8 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
$ref: '#/components/responses/InternalServerError'

/users/{id}:
get:
Expand All @@ -362,6 +392,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

put:
tags:
Expand Down Expand Up @@ -396,6 +428,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

delete:
tags:
Expand All @@ -415,6 +449,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

/users/{id}/favorites:
get:
Expand All @@ -441,6 +477,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

post:
tags:
Expand Down Expand Up @@ -473,6 +511,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

/users/{id}/favorites/{sneakerId}:
delete:
Expand All @@ -498,6 +538,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

# PROVIDERS

Expand All @@ -512,12 +554,14 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/Provider'
$ref: '#/components/schemas/ProvidersResponse'
'404':
description: No providers found
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

post:
tags:
Expand All @@ -541,6 +585,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

/providers/{id}:
get:
Expand All @@ -565,6 +611,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

put:
tags:
Expand Down Expand Up @@ -599,6 +647,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

delete:
tags:
Expand All @@ -618,6 +668,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

# STORES

Expand All @@ -640,6 +692,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

post:
tags:
Expand All @@ -663,6 +717,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

/stores/{id}:
get:
Expand All @@ -687,6 +743,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

put:
tags:
Expand Down Expand Up @@ -721,6 +779,8 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

delete:
tags:
Expand All @@ -740,8 +800,13 @@ paths:
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'500':
$ref: '#/components/responses/InternalServerError'

## COMPONENTS
components:

# Schemas
schemas:

SneakersResponse:
Expand All @@ -753,6 +818,16 @@ components:
$ref: '#/components/schemas/Sneaker'
count:
type: integer
description: Number of sneakers returned in this response
total:
type: integer
description: Total number of sneakers matching the query (for all pages)
offset:
type: integer
description: Offset used in the query
limit:
type: integer
description: Limit used in the query
message:
type: string
status:
Expand All @@ -775,6 +850,8 @@ components:
type: string
modelKey:
type: string
size:
type: number
retail_price:
type: number
format: float
Expand Down Expand Up @@ -919,4 +996,15 @@ components:
status:
type: string
enum: [failure]
required: [message, status]
required: [message, status]


# Responses
responses:

InternalServerError:
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- [x] There are at least 3 resources and they are related to each other (sneakers, users, reviews).
- [x] One of the collections has at least **1000 documents**
- [x] There is a **dataset** to seed this collection in the repository ( -> this dataset is in **JSON format**)
- [ ] At least one route allows pagination
- [x] At least one route allows pagination
- [x] At least one route allows filtering data to search inside this collection

- [x] Uses an external API
Expand Down
7 changes: 7 additions & 0 deletions docs/routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Query Parameters:
- Minimum: 1
- Maximum: 100
- Default: 20
- `offset`: Number of items to skip before starting to collect the result set (useful for **pagination**)
- Type: integer
- Minimum: 0
- Default: 0
- `currency`: Currency in which prices should be returned. See [currencies.md](/docs/currencies.md) for the list of **valid** currencies.
- Type: string

Expand All @@ -27,6 +31,9 @@ Examples:

# Get 2 sneakers released after October 22, 2021, priced in EUR
sneakers?currency=eur&limit=2&release_date_after=2021-10-22

# Get 2 sneakers released after October 22, 2021, priced in EUR, skipping the first 5
/sneakers?currency=eur&limit=2&offset=5&release_date_after=2021-10-22
```

**GET** /sneakers/{id} : Get a specific sneaker information
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Provider } from "../schemas/provider";

export const getProviders = async (req, res) => {
try {
const providers = await Provider.find();
const providers = await Provider.find().select('-__v');

if (!providers || providers.length === 0) {
return res.status(404).json({
Expand Down Expand Up @@ -30,7 +30,9 @@ export const getProviderById = async (req, res) => {
const { id } = req.params;

try {
const provider = await Provider.findById(id);
const provider = await Provider
.findById(id)
.select('-__v');

if (!provider) {
return res.status(404).json({
Expand Down Expand Up @@ -85,7 +87,11 @@ export const updateProviderById = async (req, res) => {
const updateData = req.body;

try {
const provider = await Provider.findByIdAndUpdate(id, updateData, { new: true });
const provider = await Provider.findByIdAndUpdate(
id,
updateData,
{ new: true, select: '-__v'}
);

if (!provider) {
return res.status(404).json({
Expand Down
Loading