Skip to content

Commit 55683ac

Browse files
authored
Merge pull request topcoder-platform#26 from sharathkumaranbu/Issue_22
GET /resource/:resourceId from ES
2 parents 6a12a6d + 6fd6755 commit 55683ac

12 files changed

+190
-74
lines changed

scripts/data/ReviewSummations.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"id": "e45e4180-65aa-42ec-a945-5fd21dec1501",
4-
"submissionId": "a12a4180-65aa-42ec-a945-5fd21dec0501",
4+
"submissionId": "a12a4180-65aa-42ec-a945-5fd21dec0504",
55
"aggregateScore": 17.8,
66
"scoreCardId": "a12a4180-65aa-42ec-a945-5fd21dec0587",
77
"isPassing": false,
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"id": "e45e4180-65aa-42ec-a945-5fd21dec1504",
37-
"submissionId": "a12a4180-65aa-42ec-a945-5fd21dec0504",
37+
"submissionId": "a12a4180-65aa-42ec-a945-5fd21dec0501",
3838
"aggregateScore": 99.0,
3939
"scoreCardId": "a12a4180-65aa-42ec-a945-5fd21dec0587",
4040
"isPassing": true,

scripts/data/Reviews.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
{
1515
"id": "d24d4180-65aa-42ec-a945-5fd21dec0502",
1616
"score": 92.0,
17-
"typeId": "c56a4180-65aa-42ec-a945-5fd21dec0503",
17+
"typeId": "c56a4180-65aa-42ec-a945-5fd21dec0501",
1818
"reviewerId": "c23a4180-65aa-42ec-a945-5fd21dec0503",
1919
"scoreCardId": "b25a4180-65aa-42ec-a945-5fd21dec0503",
20-
"submissionId": "a12a4180-65aa-42ec-a945-5fd21dec0502",
20+
"submissionId": "a12a4180-65aa-42ec-a945-5fd21dec0501",
2121
"created": "2018-05-20T07:00:30.123Z",
2222
"updated": "2018-06-01T07:36:28.178Z",
2323
"createdBy": "admin",

src/services/ReviewService.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const HelperService = require('./HelperService')
1515
const table = 'Review'
1616

1717
/**
18-
* Function to get review based on ID
18+
* Function to get review based on ID from DynamoDB
1919
* This function will be used all by other functions to check existence of review
2020
* @param {Number} reviewId reviewId which need to be retrieved
2121
* @return {Object} Data retrieved from database
@@ -33,17 +33,17 @@ function * _getReview (reviewId) {
3333
}
3434

3535
/**
36-
* Function to get review based on ID
36+
* Function to get review based on ID from ES
3737
* @param {Number} reviewId reviewId which need to be found
3838
* @return {Object} Data found from database
3939
*/
4040
function * getReview (reviewId) {
41-
const exist = yield _getReview(reviewId)
42-
if (!exist) {
41+
const response = yield helper.fetchFromES({id: reviewId}, helper.camelize(table))
42+
if (response.total === 0) {
4343
throw new errors.HttpStatusError(404, `Review with ID = ${reviewId} is not found`)
4444
}
4545
// Return the retrieved review
46-
return exist
46+
return response.rows[0]
4747
}
4848

4949
getReview.schema = {

src/services/ReviewSummationService.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const HelperService = require('./HelperService')
1515
const table = 'ReviewSummation'
1616

1717
/**
18-
* Function to get Review summation based on ID
18+
* Function to get Review summation based on ID from DynamoDB
1919
* This function will be used all by other functions to check existence of Review summation
2020
* @param {Number} reviewSummationId reviewSummationId which need to be retrieved
2121
* @return {Object} Data retrieved from database
@@ -33,17 +33,17 @@ function * _getReviewSummation (reviewSummationId) {
3333
}
3434

3535
/**
36-
* Function to get Review summation based on ID
36+
* Function to get Review summation based on ID from ES
3737
* @param {Number} reviewSummationId reviewSummationId which need to be found
3838
* @return {Object} Data found from database
3939
*/
4040
function * getReviewSummation (reviewSummationId) {
41-
const exist = yield _getReviewSummation(reviewSummationId)
42-
if (!exist) {
41+
const response = yield helper.fetchFromES({id: reviewSummationId}, helper.camelize(table))
42+
if (response.total === 0) {
4343
throw new errors.HttpStatusError(404, `Review summation with ID = ${reviewSummationId} is not found`)
4444
}
4545
// Return the retrieved Review summation
46-
return exist
46+
return response.rows[0]
4747
}
4848

4949
getReviewSummation.schema = {

src/services/ReviewTypeService.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { originator, mimeType, events } = require('../../constants').busApiMeta
1313
const table = 'ReviewType'
1414

1515
/**
16-
* Function to get review type based on ID
16+
* Function to get review type based on ID from DyanmoDB
1717
* This function will be used all by other functions to check existence of review type
1818
* @param {Number} reviewTypeId ReviewTypeId which need to be retrieved
1919
* @return {Object} Data retrieved from database
@@ -31,17 +31,17 @@ function * _getReviewType (reviewTypeId) {
3131
}
3232

3333
/**
34-
* Function to get review type based on ID
34+
* Function to get review type based on ID from ES
3535
* @param {Number} reviewTypeId ReviewTypeId which need to be found
3636
* @return {Object} Data found from database
3737
*/
3838
function * getReviewType (reviewTypeId) {
39-
const exist = yield _getReviewType(reviewTypeId)
40-
if (!exist) {
39+
const response = yield helper.fetchFromES({id: reviewTypeId}, helper.camelize(table))
40+
if (response.total === 0) {
4141
throw new errors.HttpStatusError(404, `Review type with ID = ${reviewTypeId} is not found`)
4242
}
4343
// Return the retrieved review type
44-
return exist
44+
return response.rows[0]
4545
}
4646

4747
getReviewType.schema = {

src/services/SubmissionService.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function * _uploadToS3 (file, name) {
4141
}
4242

4343
/**
44-
* Function to get submission based on ID
44+
* Function to get submission based on ID from DynamoDB
4545
* This function will be used all by other functions to check existence of a submission
4646
* @param {String} submissionId submissionId which need to be retrieved
4747
* @return {Object} Data retrieved from database
@@ -59,17 +59,17 @@ function * _getSubmission (submissionId) {
5959
}
6060

6161
/**
62-
* Function to get submission based on ID
62+
* Function to get submission based on ID from ES
6363
* @param {String} submissionId submissionId which need to be retrieved
6464
* @return {Object} Data retrieved from database
6565
*/
6666
function * getSubmission (submissionId) {
67-
const exist = yield _getSubmission(submissionId)
68-
if (!exist) {
67+
const response = yield helper.fetchFromES({id: submissionId}, helper.camelize(table))
68+
if (response.total === 0) {
6969
throw new errors.HttpStatusError(404, `Submission with ID = ${submissionId} is not found`)
7070
}
7171
// Return the retrieved submission
72-
return exist
72+
return response.rows[0]
7373
}
7474

7575
getSubmission.schema = {

test/common/testData.js

+104-11
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,37 @@ const nonExReviewTypeId = 'b56a4180-65aa-42ec-a945-5fd21dec0501'
66

77
const testReviewType = {
88
Item: {
9-
'id': 'a56a4180-65aa-42ec-a945-5fd21dec0501',
10-
'name': 'test',
11-
'isActive': true
9+
id: 'c56a4180-65aa-42ec-a945-5fd21dec0501',
10+
name: 'Screening',
11+
isActive: true
1212
}
1313
}
1414

1515
const testReviewTypePatch = {
1616
Item: {
17-
'id': 'a56a4180-65aa-42ec-a945-5fd21dec0501',
18-
'name': 'testPatching',
19-
'isActive': true
17+
id: 'c56a4180-65aa-42ec-a945-5fd21dec0501',
18+
name: 'testPatching',
19+
isActive: true
2020
}
2121
}
2222

23+
const testReviewTypeES = {
24+
hits:
25+
{ total: 1,
26+
max_score: 0,
27+
hits: [ { _index: 'submission',
28+
_type: '_doc',
29+
_id: 'c56a4180-65aa-42ec-a945-5fd21dec0501',
30+
_score: 0,
31+
_source: {
32+
id: 'c56a4180-65aa-42ec-a945-5fd21dec0501',
33+
name: 'Screening',
34+
isActive: true
35+
}
36+
}]
37+
}
38+
}
39+
2340
const testReviewTypesES = {
2441
hits:
2542
{ total: 5,
@@ -87,11 +104,11 @@ const testSubmission = {
87104

88105
const testSubmissionWoLegacy = {
89106
Item: {
90-
challengeId: 'c3564180-65aa-42ec-a945-5fd21dec0503',
107+
challengeId: 'c3564180-65aa-42ec-a945-5fd21dec0502',
91108
id: 'a12a4180-65aa-42ec-a945-5fd21dec0502',
92109
type: 'ContestSubmission',
93-
url: 'https://software.topcoder.com/review/actions/DownloadContestSubmission?uid=123456',
94-
memberId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
110+
url: 'https://software.topcoder.com/review/actions/DownloadContestSubmission?uid=123457',
111+
memberId: 'b24d4180-65aa-42ec-a945-5fd21dec0502',
95112
created: '2018-05-20T07:00:30.123Z',
96113
createdBy: 'topcoder user',
97114
updated: '2018-06-01T07:36:28.178Z',
@@ -115,6 +132,31 @@ const testSubmissionPatch = {
115132
}
116133
}
117134

135+
const testSubmissionES = {
136+
hits:
137+
{ total: 1,
138+
max_score: 0,
139+
hits: [ { _index: 'submission',
140+
_type: '_doc',
141+
_id: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
142+
_score: 0,
143+
_source: {
144+
challengeId: 'c3564180-65aa-42ec-a945-5fd21dec0502',
145+
id: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
146+
type: 'ContestSubmission',
147+
url: 'https://software.topcoder.com/review/actions/DownloadContestSubmission?uid=123456',
148+
memberId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
149+
legacySubmissionId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
150+
submissionPhaseId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
151+
created: '2018-05-20T07:00:30.123Z',
152+
createdBy: 'topcoder user',
153+
updated: '2018-06-01T07:36:28.178Z',
154+
updatedBy: 'topcoder user'
155+
}
156+
}]
157+
}
158+
}
159+
118160
const testSubmissionsES = {
119161
hits:
120162
{ total: 5,
@@ -202,7 +244,7 @@ const testReview = {
202244
reviewerId: 'c23a4180-65aa-42ec-a945-5fd21dec0503',
203245
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
204246
scoreCardId: 'b25a4180-65aa-42ec-a945-5fd21dec0503',
205-
typeId: 'a56a4180-65aa-42ec-a945-5fd21dec0501',
247+
typeId: 'c56a4180-65aa-42ec-a945-5fd21dec0501',
206248
created: '2018-05-20T07:00:30.123Z',
207249
updated: '2018-06-01T07:36:28.178Z',
208250
createdBy: 'admin',
@@ -217,14 +259,38 @@ const testReviewPatch = {
217259
reviewerId: 'c23a4180-65aa-42ec-a945-5fd21dec0503',
218260
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
219261
scoreCardId: 'b25a4180-65aa-42ec-a945-5fd21dec0503',
220-
typeId: 'a56a4180-65aa-42ec-a945-5fd21dec0501',
262+
typeId: 'c56a4180-65aa-42ec-a945-5fd21dec0501',
221263
created: '2018-05-20T07:00:30.123Z',
222264
updated: '2018-06-01T07:36:28.178Z',
223265
createdBy: 'admin',
224266
updatedBy: 'admin'
225267
}
226268
}
227269

270+
const testReviewES = {
271+
hits:
272+
{ total: 1,
273+
max_score: 0,
274+
hits: [ { _index: 'submission',
275+
_type: '_doc',
276+
_id: 'd24d4180-65aa-42ec-a945-5fd21dec0501',
277+
_score: 0,
278+
_source: {
279+
id: 'd24d4180-65aa-42ec-a945-5fd21dec0502',
280+
score: 92,
281+
reviewerId: 'c23a4180-65aa-42ec-a945-5fd21dec0503',
282+
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
283+
scoreCardId: 'b25a4180-65aa-42ec-a945-5fd21dec0503',
284+
typeId: 'c56a4180-65aa-42ec-a945-5fd21dec0501',
285+
created: '2018-05-20T07:00:30.123Z',
286+
updated: '2018-06-01T07:36:28.178Z',
287+
createdBy: 'admin',
288+
updatedBy: 'admin'
289+
}
290+
}]
291+
}
292+
}
293+
228294
const testReviewsES = {
229295
hits:
230296
{ total: 4,
@@ -322,6 +388,29 @@ const testReviewSummationPatch = {
322388
}
323389
}
324390

391+
const testReviewSummationES = {
392+
hits:
393+
{ total: 1,
394+
max_score: 0,
395+
hits: [ { _index: 'submission',
396+
_type: '_doc',
397+
_id: 'e45e4180-65aa-42ec-a945-5fd21dec1504',
398+
_score: 0,
399+
_source: {
400+
id: 'e45e4180-65aa-42ec-a945-5fd21dec1504',
401+
aggregateScore: 99,
402+
isPassing: true,
403+
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
404+
scoreCardId: 'a12a4180-65aa-42ec-a945-5fd21dec0587',
405+
created: '2018-05-20T07:00:30.123Z',
406+
updated: '2018-06-01T07:36:28.178Z',
407+
createdBy: 'copilot',
408+
updatedBy: 'copilot'
409+
}
410+
}]
411+
}
412+
}
413+
325414
const testReviewSummationsES = {
326415
hits:
327416
{ total: 4,
@@ -390,18 +479,22 @@ module.exports = {
390479
nonExReviewTypeId,
391480
testReviewType,
392481
testReviewTypePatch,
482+
testReviewTypeES,
393483
testReviewTypesES,
394484
nonExSubmissionId,
395485
testSubmission,
396486
testSubmissionWoLegacy,
397487
testSubmissionPatch,
488+
testSubmissionES,
398489
testSubmissionsES,
399490
nonExReviewId,
400491
testReview,
401492
testReviewPatch,
493+
testReviewES,
402494
testReviewsES,
403495
nonExReviewSummationId,
404496
testReviewSummation,
405497
testReviewSummationPatch,
498+
testReviewSummationES,
406499
testReviewSummationsES
407500
}

0 commit comments

Comments
 (0)