From 12e9050d59332c59f5c3972e5df6d2a271e504ab Mon Sep 17 00:00:00 2001 From: aromakh Date: Mon, 12 Oct 2020 17:28:24 +0300 Subject: [PATCH] get public brick by id without signup --- api/swagger.yaml | 17 +++++++++++++ controllers/Brick.js | 11 ++++++++ service/BrickService.js | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/api/swagger.yaml b/api/swagger.yaml index 924e69e..be2796e 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -508,6 +508,23 @@ paths: "200": description: "ok" x-swagger-router-controller: "Brick" + /brick/public/{id}: + get: + tags: + - "brick" + summary: "Get specific public brick by id" + operationId: "brickPublicIdGET" + parameters: + - name: "id" + in: "path" + required: true + type: "integer" + responses: + "200": + description: "ok" + schema: + $ref: "#/definitions/Brick" + x-swagger-router-controller: "Brick" /brick/build/{id}: post: tags: diff --git a/controllers/Brick.js b/controllers/Brick.js index d59df59..01d66c9 100644 --- a/controllers/Brick.js +++ b/controllers/Brick.js @@ -83,6 +83,17 @@ module.exports.brickIdGET = function brickIdGET (req, res, next) { }); }; +module.exports.brickPublicIdGET = function brickPublicIdGET (req, res, next) { + var id = req.swagger.params['id'].value; + Brick.brickPublicIdGET(id) + .then(function (response) { + utils.writeJson(res, response); + }) + .catch(function (response) { + utils.writeJson(res, response); + }); +}; + module.exports.brickPublishIdPOST = function brickPublishIdPOST (req, res, next) { var id = req.swagger.params['id'].value; Brick.brickPublishIdPOST(id) diff --git a/service/BrickService.js b/service/BrickService.js index 0c5da1d..2ad15a4 100644 --- a/service/BrickService.js +++ b/service/BrickService.js @@ -280,6 +280,62 @@ exports.brickIdGET = function(id) { } +/** + * Get specific public brick by id + * + * id Integer + * returns Brick + **/ +exports.brickPublicIdGET = function(id) { + return new Promise(function(resolve, reject) { + var examples = {}; + examples['application/json'] = { + "alternativeSubject" : "alternativeSubject", + "subTopic" : "subTopic", + "brief" : "brief", + "synthesis" : "synthesis", + "openQuestion" : "openQuestion", + "subject" : { + "color" : "color", + "name" : "name", + "checked" : true, + "id" : 5, + "bricksCount" : 5, + "publishedBricksCount" : 2 + }, + "created" : "2000-01-23T04:56:07.000+00:00", + "questions" : [ { + "contentBlocks" : "contentBlocks", + "id" : 7, + "questionType" : "None", + "order" : 9 + }, { + "contentBlocks" : "contentBlocks", + "id" : 7, + "questionType" : "None", + "order" : 9 + } ], + "revisionLog" : "revisionLog", + "title" : "title", + "subjectId" : 1, + "attemptsCount" : 6, + "brickLength" : "0", + "alternativeTopics" : "alternativeTopics", + "topic" : "topic", + "prep" : "prep", + "id" : 0, + "locked" : true, + "updated" : "2000-01-23T04:56:07.000+00:00" +}; + if (Object.keys(examples).length > 0) { + resolve(examples[Object.keys(examples)[0]]); + } else { + resolve(); + } + }); +} + + /** * Set brick to publish status *