Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 5c1d547

Browse files
committed
Merge challenge detail api.
1 parent ad860ba commit 5c1d547

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

actions/challenges.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.19
4+
* @version 1.20
55
* @author Sky_, mekanizumu, TCSASSEMBLER, freegod, Ghost_141, kurtrips, xjtufreeman, ecnu_haozi, hesibo, LazyChild
66
* @changes from 1.0
77
* merged with Member Registration API
@@ -46,6 +46,8 @@
4646
* add clientSelection flag in studio results
4747
* changes in 1.19:
4848
* add new allowed sort columns.
49+
* changes in 1.20:
50+
* add get challenge detail api for both design and develop challenge.
4951
*/
5052
"use strict";
5153
/*jslint stupid: true, unparam: true, continue: true */
@@ -786,6 +788,10 @@ var getChallenge = function (api, connection, dbConnectionMap, isStudio, next) {
786788
submissionEndDate : formatDate(data.submission_end_date)
787789
};
788790

791+
if (connection.action == "getChallenge") {
792+
challenge.type = isStudio ? 'design' : 'develop';
793+
}
794+
789795
if (data.project_type === COPILOT_POSTING_PROJECT_TYPE && (isCopilot || helper.isAdmin(caller))) {
790796
challenge.copilotDetailedRequirements = data.copilot_detailed_requirements;
791797
}
@@ -1515,6 +1521,44 @@ exports.getStudioChallenge = {
15151521
}
15161522
};
15171523

1524+
/**
1525+
* The API for getting challenge details.
1526+
*
1527+
* @since 1.19
1528+
*/
1529+
exports.getChallenge = {
1530+
name: "getChallenge",
1531+
description: "getStudioChallenge",
1532+
inputs: {
1533+
required: ["contestId"],
1534+
optional: ["refresh"]
1535+
},
1536+
blockedConnectionTypes: [],
1537+
outputExample: {},
1538+
version: 'v2',
1539+
transaction: 'read', // this action is read-only
1540+
databases: ["tcs_catalog", "tcs_dw"],
1541+
run: function (api, connection, next) {
1542+
if (connection.dbConnectionMap) {
1543+
api.log("Execute getChallenge#run", 'debug');
1544+
api.dataAccess.executeQuery('check_challenge_exists', {challengeId: connection.params.contestId}, connection.dbConnectionMap, function(err, result) {
1545+
if (err) {
1546+
api.helper.handleError(api, connection, err);
1547+
next(connection, true);
1548+
} else if (result.length == 0) {
1549+
api.helper.handleError(api, connection, new NotFoundError("Challenge not found."));
1550+
next(connection, true);
1551+
} else {
1552+
var isStudio = Boolean(result[0].is_studio);
1553+
getChallenge(api, connection, connection.dbConnectionMap, isStudio, next);
1554+
}
1555+
});
1556+
} else {
1557+
api.helper.handleNoConnection(api, connection, next);
1558+
}
1559+
}
1560+
};
1561+
15181562
/**
15191563
* The API for searching challenges
15201564
*/

routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ var testMethods = {
138138
exports.routes = {
139139
get: [
140140
{ path: "/:apiVersion/logs", action: "getLogTail" },
141+
{ path: "/:apiVersion/challenges/:contestId", action: "getChallenge" },
141142
{ path: "/:apiVersion/challenges", action: "searchSoftwareAndStudioChallenges" },
142143

143144
{ path: "/:apiVersion/develop/challenges/checkpoint/:challengeId", action: "getSoftwareCheckpoint" },

0 commit comments

Comments
 (0)