Skip to content

Commit 3d1b099

Browse files
committed
get-course-exercises
1 parent 4191f8e commit 3d1b099

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

tmc-langs-cli/src/app.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ pub fn create_app() -> App<'static, 'static> {
262262
.required(true)
263263
.takes_value(true)))
264264

265+
.subcommand(SubCommand::with_name("get-course-exercises")
266+
.about("Get course exercises.")
267+
.arg(Arg::with_name("course-id")
268+
.help("The ID of the course.")
269+
.long("course-id")
270+
.required(true)
271+
.takes_value(true)))
272+
265273
.subcommand(SubCommand::with_name("paste")
266274
.about("Send exercise to pastebin with comment.")
267275
.arg(Arg::with_name("submission-url")

tmc-langs-cli/src/main.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,21 @@ fn run() -> Result<()> {
661661
let course_id = into_usize(course_id)?;
662662
let course = core.get_course(course_id).context("Failed to get course")?;
663663

664+
let output = Output {
665+
status: Status::Successful,
666+
message: None,
667+
result: OutputResult::RetrievedData,
668+
percent_done: 1.0,
669+
data: Some(course),
670+
};
671+
print_output(&output)?;
672+
} else if let Some(matches) = matches.subcommand_matches("get-course-exercises") {
673+
let course_id = matches.value_of("course-id").unwrap();
674+
let course_id = into_usize(course_id)?;
675+
let course = core
676+
.get_course_exercises(course_id)
677+
.context("Failed to get course")?;
678+
664679
let output = Output {
665680
status: Status::Successful,
666681
message: None,

tmc-langs-core/src/response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub struct Exercise {
175175
pub solution_zip_url: Option<String>,
176176
}
177177

178-
#[derive(Debug, Deserialize)]
178+
#[derive(Debug, Deserialize, Serialize)]
179179
pub struct CourseExercise {
180180
pub id: usize,
181181
pub available_points: Vec<ExercisePoint>,
@@ -200,7 +200,7 @@ pub struct CourseDataExercise {
200200
pub disabled: bool,
201201
}
202202

203-
#[derive(Debug, Deserialize)]
203+
#[derive(Debug, Deserialize, Serialize)]
204204
pub struct ExercisePoint {
205205
pub id: usize,
206206
pub exercise_id: usize,

tmc-langs-core/src/tmc_core.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ impl TmcCore {
334334
self.course(course_id)
335335
}
336336

337+
pub fn get_course_exercises(&self, course_id: usize) -> Result<Vec<CourseExercise>> {
338+
if self.token.is_none() {
339+
return Err(CoreError::AuthRequired);
340+
}
341+
self.exercises(course_id)
342+
}
343+
337344
/// Sends the given submission as a paste.
338345
///
339346
/// # Errors

0 commit comments

Comments
 (0)