Skip to content

Commit 9a02f29

Browse files
committed
WIP: send message from mojolicious layer and more cleanup.
1 parent 871b610 commit 9a02f29

File tree

14 files changed

+42
-40
lines changed

14 files changed

+42
-40
lines changed

lib/DB/Schema/ResultSet/ProblemPool.pm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,8 @@ remove a Problem out of a ProblemPool in a course
435435
=cut
436436

437437
sub removePoolProblem ($self, %args) {
438-
my $prob = $self->getPoolProblem(info => $args{info}, as_result_set => 1);
439-
DB::Exception::PoolProblemNotInPool->throw(info => $args{info}) unless defined($prob);
440-
441-
my $prob2 = $prob->delete;
442-
return $prob2 if $args{as_result_set};
443-
return { $prob2->get_inflated_columns };
438+
$self->getPoolProblem(info => $args{info}, as_result_set => 1)->delete;
439+
return;
444440
}
445441

446442
# just a small subroutine to shorten access to the db.

lib/WeBWorK3/Controller/Course.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ sub addCourse ($c) {
3232
}
3333

3434
sub deleteCourse ($c) {
35-
my $course =
36-
$c->schema->resultset('Course')->deleteCourse(info => { course_id => int($c->param('course_id')) });
37-
$c->render(json => $course);
35+
$c->schema->resultset('Course')->deleteCourse(info => { course_id => int($c->param('course_id')) });
36+
$c->render(json => { message => 'The course was successfully deleted.' });
3837
return;
3938
}
4039

lib/WeBWorK3/Controller/Problem.pm

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ sub updateProblem ($c) {
5555
}
5656

5757
sub deleteProblem ($c) {
58-
my $deleted_problem = $c->schema->resultset('SetProblem')->deleteSetProblem(
58+
$c->schema->resultset('SetProblem')->deleteSetProblem(
5959
info => {
6060
course_id => int($c->param('course_id')),
6161
set_id => int($c->param('set_id')),
6262
set_problem_id => int($c->param('set_problem_id'))
6363
}
6464
);
65-
$c->render(json => $deleted_problem);
65+
$c->render(json => { message => 'The problem was successfully deleted.' });
6666
return;
6767
}
6868

@@ -142,15 +142,15 @@ sub updateUserProblem ($c) {
142142
}
143143

144144
sub deleteUserProblem ($c) {
145-
my $deleted_problem = $c->schema->resultset('UserProblem')->deleteUserProblem(
145+
$c->schema->resultset('UserProblem')->deleteUserProblem(
146146
info => {
147147
course_id => int($c->param('course_id')),
148148
set_id => int($c->param('set_id')),
149149
user_id => int($c->param('user_id')),
150150
user_problem_id => int($c->param('user_problem_id'))
151151
}
152152
);
153-
$c->render(json => $deleted_problem);
153+
$c->render(json => { message => 'The user problem was successfully deleted.' });
154154
return;
155155
}
156156

@@ -204,14 +204,14 @@ sub updateProblemPool ($c) {
204204
}
205205

206206
sub deleteProblemPool ($c) {
207-
my $problem_pool = $c->schema->resultset('ProblemPool')->deleteProblemPool(
207+
$c->schema->resultset('ProblemPool')->deleteProblemPool(
208208
info => {
209209
course_id => int($c->param('course_id')),
210210
problem_pool_id => int($c->param('problem_pool_id')),
211211
},
212212
params => $c->req->json
213213
);
214-
$c->render(json => $problem_pool);
214+
$c->render(json => { message => 'The problem pool was successfully deleted.' });
215215
return;
216216
}
217217

@@ -261,14 +261,13 @@ sub updatePoolProblem ($c) {
261261
}
262262

263263
sub removePoolProblem ($c) {
264-
my $problem_pool = $c->schema->resultset('ProblemPool')->removePoolProblem(
264+
$c->schema->resultset('ProblemPool')->removePoolProblem(
265265
info => {
266266
course_id => int($c->param('course_id')),
267267
problem_pool_id => int($c->param('problem_pool_id')),
268-
},
269-
params => $c->req->json
268+
}
270269
);
271-
$c->render(json => $problem_pool);
270+
$c->render(json => { message => 'The pool problem was successfully removed.' });
272271
return;
273272
}
274273

lib/WeBWorK3/Controller/ProblemSet.pm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ sub addProblemSet ($self) {
6262
}
6363

6464
sub deleteProblemSet ($self) {
65-
my $problem_set = $self->schema->resultset('ProblemSet')->deleteProblemSet(
65+
$self->schema->resultset('ProblemSet')->deleteProblemSet(
6666
info => {
6767
course_id => int($self->param('course_id')),
6868
set_id => int($self->param('set_id'))
6969
}
7070
);
71-
$self->render(json => $problem_set);
71+
$self->render(json => { message => 'The problem set was successfully deleted.' });
7272
return;
7373
}
7474

@@ -144,15 +144,14 @@ sub updateUserSet ($self) {
144144
}
145145

146146
sub deleteUserSet ($self) {
147-
my $updated_user_set = $self->schema->resultset('UserSet')->deleteUserSet(
147+
$self->schema->resultset('UserSet')->deleteUserSet(
148148
info => {
149149
course_id => int($self->param('course_id')),
150150
set_id => int($self->param('set_id')),
151151
course_user_id => int($self->param('course_user_id'))
152-
},
153-
params => $self->req->json
152+
}
154153
);
155-
$self->render(json => $updated_user_set);
154+
$self->render(json => { message => 'The user set was successfully deleted.' });
156155
return;
157156
}
158157

lib/WeBWorK3/Controller/User.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sub addGlobalUser ($c) {
4848

4949
sub deleteGlobalUser ($c) {
5050
my $user = $c->schema->resultset('User')->deleteGlobalUser(info => { user_id => int($c->param('user_id')) });
51-
$c->render(json => $user);
51+
$c->render(json => { message => 'The global user was successfully deleted.' });
5252
return;
5353
}
5454

@@ -132,7 +132,7 @@ sub deleteCourseUser ($c) {
132132
user_id => int($c->param('user_id'))
133133
}
134134
);
135-
$c->render(json => $course_user);
135+
$c->render(json => { message => 'The course user was successfully deleted.' });
136136
return;
137137
}
138138

t/mojolicious/002_courses.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ $t->delete_ok('/webwork3/api/courses/9999999')->status_is(500, 'error status')
100100
->content_type_is('application/json;charset=UTF-8')->json_is('/exception' => 'DB::Exception::CourseNotFound');
101101

102102
# Delete the added course.
103-
$t->delete_ok("/webwork3/api/courses/$new_course_id")->status_is(200);
103+
$t->delete_ok("/webwork3/api/courses/$new_course_id")->status_is(200)
104+
->json_is('/message' => 'The course was successfully deleted.');
104105

105106
# Check that it is deleted.
106107
$t->get_ok("/webwork3/api/courses/$new_course_id")->status_is(500)

t/mojolicious/003_users.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ my $another_new_user_id = $t->tx->res->json('/user_id');
149149

150150
# For cleanup, delete the created users.
151151
$t->delete_ok("/webwork3/api/users/$new_user_from_db->{user_id}")->status_is(200)
152-
->content_type_is('application/json;charset=UTF-8');
152+
->content_type_is('application/json;charset=UTF-8')
153+
->json_is('/message' => 'The global user was successfully deleted.');
153154

154155
# And check that the user is no longer in the db.
155156
$t->get_ok("/webwork3/api/users/$new_user_from_db->{user_id}")->status_is(500)
@@ -214,6 +215,7 @@ $t->put_ok("/webwork3/api/courses/4/global-users/$new_global_user_id" => json =>
214215
->json_is('/student_id' => 4321);
215216

216217
$t->delete_ok("/webwork3/api/courses/4/global-users/$new_global_user_id")->status_is(200)
217-
->content_type_is('application/json;charset=UTF-8');
218+
->content_type_is('application/json;charset=UTF-8')
219+
->json_is('/message' => 'The global user was successfully deleted.');
218220

219221
done_testing;

t/mojolicious/004_course_users.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ $t->delete_ok("/webwork3/api/courses/4/users/5")->status_is(500, 'status for exc
131131

132132
# Delete the added course user
133133
$t->delete_ok("/webwork3/api/courses/4/users/$new_user_id")->status_is(200)
134-
->content_type_is('application/json;charset=UTF-8');
134+
->content_type_is('application/json;charset=UTF-8')
135+
->json_is('/message' => 'The course user was successfully deleted.');
135136

136137
# And make sure that the course user is no longer in the database;
137138
$t->get_ok("/webwork3/api/courses/4/users/$new_user_id")->status_is(500)
@@ -164,7 +165,8 @@ $t->post_ok('/webwork3/api/logout')->status_is(200);
164165
$t->post_ok('/webwork3/api/login' => json => { username => 'admin', password => 'admin' })->status_is(200);
165166

166167
# Delete the added users.
167-
$t->delete_ok("/webwork3/api/users/$new_user_id")->status_is(200);
168+
$t->delete_ok("/webwork3/api/users/$new_user_id")->status_is(200)
169+
->json_is('/message' => 'The global user was successfully deleted.');
168170

169171
# And check that the user is no longer in the db.
170172
$t->get_ok("/webwork3/api/users/$new_user_id")->status_is(500)->json_is('/exception' => 'DB::Exception::UserNotFound');

t/mojolicious/005_problem_sets.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ $t->post_ok('/webwork3/api/courses/4/sets' => json => $another_new_set)
150150
# Some cleanup to restore the database
151151
# Delete an existing set.
152152
$t->delete_ok("/webwork3/api/courses/4/sets/$new_set_id")->content_type_is('application/json;charset=UTF-8')
153-
->status_is(200);
153+
->status_is(200)->json_is('/message' => 'The problem set was successfully deleted.');
154154

155155
# And check that the problem set is no longer in the db.
156156
$t->get_ok("/webwork3/api/courses/4/sets/$new_set_id")->status_is(500)

t/mojolicious/006_quizzes.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ ok(JSON::PP::is_bool($problem_randorder) && !$problem_randorder, 'testing that p
131131

132132
# delete the added quiz
133133
$t->delete_ok("/webwork3/api/courses/4/sets/$returned_quiz->{set_id}")->status_is(200)
134-
->content_type_is('application/json;charset=UTF-8');
134+
->content_type_is('application/json;charset=UTF-8')
135+
->json_is('/message' => 'The problem set was successfully deleted.');
135136

136137
# And check that the quiz is no longer in the db.
137138
$t->get_ok("/webwork3/api/courses/4/sets/$returned_quiz->{set_id}")->status_is(500)

0 commit comments

Comments
 (0)