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

Merge get challenge API. #175

Merged
merged 2 commits into from
Apr 4, 2014
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
46 changes: 45 additions & 1 deletion actions/challenges.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved.
*
* @version 1.19
* @version 1.20
* @author Sky_, mekanizumu, TCSASSEMBLER, freegod, Ghost_141, kurtrips, xjtufreeman, ecnu_haozi, hesibo, LazyChild
* @changes from 1.0
* merged with Member Registration API
Expand Down Expand Up @@ -46,6 +46,8 @@
* add clientSelection flag in studio results
* changes in 1.19:
* add new allowed sort columns.
* changes in 1.20:
* add get challenge detail api for both design and develop challenge.
*/
"use strict";
/*jslint stupid: true, unparam: true, continue: true */
Expand Down Expand Up @@ -786,6 +788,10 @@ var getChallenge = function (api, connection, dbConnectionMap, isStudio, next) {
submissionEndDate : formatDate(data.submission_end_date)
};

if (connection.action == "getChallenge") {
challenge.type = isStudio ? 'design' : 'develop';
}

if (data.project_type === COPILOT_POSTING_PROJECT_TYPE && (isCopilot || helper.isAdmin(caller))) {
challenge.copilotDetailedRequirements = data.copilot_detailed_requirements;
}
Expand Down Expand Up @@ -1515,6 +1521,44 @@ exports.getStudioChallenge = {
}
};

/**
* The API for getting challenge details.
*
* @since 1.19
*/
exports.getChallenge = {
name: "getChallenge",
description: "getStudioChallenge",
inputs: {
required: ["contestId"],
optional: ["refresh"]
},
blockedConnectionTypes: [],
outputExample: {},
version: 'v2',
transaction: 'read', // this action is read-only
databases: ["tcs_catalog", "tcs_dw"],
run: function (api, connection, next) {
if (connection.dbConnectionMap) {
api.log("Execute getChallenge#run", 'debug');
api.dataAccess.executeQuery('check_challenge_exists', {challengeId: connection.params.contestId}, connection.dbConnectionMap, function(err, result) {
if (err) {
api.helper.handleError(api, connection, err);
next(connection, true);
} else if (result.length == 0) {
api.helper.handleError(api, connection, new NotFoundError("Challenge not found."));
next(connection, true);
} else {
var isStudio = Boolean(result[0].is_studio);
getChallenge(api, connection, connection.dbConnectionMap, isStudio, next);
}
});
} else {
api.helper.handleNoConnection(api, connection, next);
}
}
};

/**
* The API for searching challenges
*/
Expand Down
2 changes: 1 addition & 1 deletion queries/challenge_details
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SELECT
ELSE 0
END AS current_phase_remaining_time
, CASE WHEN pidr.value = 'On' THEN
NVL((SELECT value::decimal FROM project_info pi_dr WHERE pi_dr.project_info_type_id = 30 AND pi_dr.project_id = p.project_id), (SELECT round(NVL(pi16.value::decimal, 0)) FROM project_info pi16 WHERE pi16.project_info_type_id = 16 AND pi16.project_id = p.project_id))
NVL((SELECT value::decimal FROM project_info pi_dr WHERE pi_dr.project_info_type_id = 30 AND pi_dr.project_id = p.project_id), (SELECT round(NVL(pi16.value::decimal, 1)) FROM project_info pi16 WHERE pi16.project_info_type_id = 16 AND pi16.project_id = p.project_id))
ELSE NULL END AS digital_run_points
, pi51.value AS submission_limit
, nvl((SELECT max(event_id) from contest_project_xref x, contest c where project_id = p.project_id and c.contest_id = x.contest_id), 0) as event_id
Expand Down
1 change: 1 addition & 0 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ var testMethods = {
exports.routes = {
get: [
{ path: "/:apiVersion/logs", action: "getLogTail" },
{ path: "/:apiVersion/challenges/:contestId", action: "getChallenge" },
{ path: "/:apiVersion/challenges", action: "searchSoftwareAndStudioChallenges" },

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