-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCourse.pm
More file actions
40 lines (32 loc) · 1.04 KB
/
Course.pm
File metadata and controls
40 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package WeBWorK3::Controller::Course;
use warnings;
use strict;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub getCourses ($c) {
my @all_courses = $c->schema->resultset('Course')->getCourses;
$c->render(json => \@all_courses);
return;
}
sub getCourse ($c) {
my $course = $c->schema->resultset('Course')->getCourse(info => { course_id => int($c->param('course_id')) });
$c->render(json => $course);
return;
}
# Update the course given by course_id with given params.
sub updateCourse ($c) {
my $course = $c->schema->resultset('Course')
->updateCourse(info => { course_id => int($c->param('course_id')) }, params => $c->req->json);
$c->render(json => $course);
return;
}
sub addCourse ($c) {
my $course = $c->schema->resultset('Course')->addCourse(params => $c->req->json);
$c->render(json => $course);
return;
}
sub deleteCourse ($c) {
$c->schema->resultset('Course')->deleteCourse(info => { course_id => int($c->param('course_id')) });
$c->render(json => { message => 'The course was successfully deleted.' });
return;
}
1;