Skip to content

Commit

Permalink
Update endpoint of getting a item
Browse files Browse the repository at this point in the history
  • Loading branch information
hr20k committed Nov 23, 2019
1 parent 3171fa8 commit adcfcd5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 9 deletions.
16 changes: 9 additions & 7 deletions api/routes/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ router.post('/', [

router.get('/:itemId', (req, res) => {
new Item({ id: req.params.itemId })
.fetch()
.fetch({ withRelated: ['tags'] })
.then(result => {
const params = {
Bucket: config.aws.s3.bucketName,
Key: result.get('image_url'),
Expires: 60 * 60 * 24
if (result.get('image_url')) {
const params = {
Bucket: config.aws.s3.bucketName,
Key: result.get('image_url'),
Expires: 60 * 60 * 24
}
const url = s3.getSignedUrl('getObject', params)
result.set('url', url)
}
const url = s3.getSignedUrl('getObject', params)
result.set('url', url)
res.json(result)
}).catch(Item.NotFoundError, (err) => {
logger.stderr.error(err.message)
Expand Down
72 changes: 70 additions & 2 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ info:
title: "Stock Checker"
contact:
email: "[email protected]"
host: "localhost:3000"
host: "api.stock-checker.hr20k.com"
basePath: "/v1"
tags:
- name: "auth"
- name: "users"
- name: "items"
- name: "tags"
schemes:
- "http"
- "https"
paths:
/signup:
post:
Expand Down Expand Up @@ -353,6 +353,54 @@ paths:
example: 401

/users/{id}/items/{itemId}:
get:
tags:
- "items"
summary: "Get a Item"
description: ""
operationId: "getItem"
parameters:
- name: "x-sc-token"
in: "header"
description: "JWT token"
required: true
type: "string"
- name: "id"
in: "path"
description: "User Id"
required: true
type: "integer"
- name: "itemId"
in: "path"
description: "Item Id"
required: true
type: "integer"
responses:
200:
description: "OK"
schema:
$ref: '#/definitions/Item'
404:
description: "Not Found"
schema:
type: "object"
properties:
errorMessage:
type: "string"
status:
type: "integer"
example: 404
401:
description: "Unauthorized"
schema:
type: "object"
properties:
errorMessage:
type: "string"
status:
type: "integer"
example: 401

put:
tags:
- "items"
Expand Down Expand Up @@ -395,6 +443,16 @@ paths:
description: "OK"
schema:
$ref: '#/definitions/Item'
404:
description: "Not Found"
schema:
type: "object"
properties:
errorMessage:
type: "string"
status:
type: "integer"
example: 404
401:
description: "Unauthorized"
schema:
Expand Down Expand Up @@ -430,6 +488,16 @@ paths:
responses:
200:
description: "OK"
404:
description: "Not Found"
schema:
type: "object"
properties:
errorMessage:
type: "string"
status:
type: "integer"
example: 404
401:
description: "Unauthorized"
schema:
Expand Down

0 comments on commit adcfcd5

Please sign in to comment.