Skip to content

Commit cbc8dd6

Browse files
committed
incorporate feedback
1 parent a6a1beb commit cbc8dd6

26 files changed

+314
-267
lines changed

lib/DB/Schema/Result/Attempt.pm

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,6 @@ Note: a problem should have only one of a library_id, problem_path or problem_po
5555
5656
=cut
5757

58-
sub valid_params {
59-
return {
60-
timestamp => q{[1-9]d+},
61-
scores => q{.*},
62-
answer => q{.*},
63-
comment => q{.*}
64-
};
65-
}
66-
67-
sub required_params {
68-
return {};
69-
}
70-
7158
### this is the table that stores problems for a given Problem Set
7259

7360
__PACKAGE__->table('attempt');
@@ -78,38 +65,37 @@ __PACKAGE__->add_columns(
7865
attempt_id => {
7966
data_type => 'integer',
8067
size => 16,
81-
is_nullable => 0,
8268
is_auto_increment => 1,
8369
},
8470
user_problem_id => {
85-
data_type => 'integer',
86-
size => 16,
87-
is_nullable => 0,
71+
data_type => 'integer',
72+
size => 16,
73+
8874
},
8975
# store scores as a JSON object
9076
scores => {
9177
data_type => 'text',
9278
size => 256,
93-
is_nullable => 0,
9479
default_value => '{}',
80+
retrieve_on_insert => 1,
9581
serializer_class => 'JSON',
9682
serializer_options => { utf8 => 1 }
9783
},
9884
# store answers as a JSON object
9985
answers => {
10086
data_type => 'text',
10187
size => 256,
102-
is_nullable => 0,
10388
default_value => '{}',
89+
retrieve_on_insert => 1,
10490
serializer_class => 'JSON',
10591
serializer_options => { utf8 => 1 }
10692
},
10793
# store comments as a JSON object
10894
comments => {
10995
data_type => 'text',
11096
size => 256,
111-
is_nullable => 0,
11297
default_value => '{}',
98+
retrieve_on_insert => 1,
11399
serializer_class => 'JSON',
114100
serializer_options => { utf8 => 1 }
115101
}
@@ -119,4 +105,13 @@ __PACKAGE__->set_primary_key('attempt_id');
119105

120106
__PACKAGE__->belongs_to(user_problem => 'DB::Schema::Result::UserProblem', 'user_problem_id');
121107

108+
sub valid_params {
109+
return {
110+
timestamp => q{[1-9]d+},
111+
scores => q{.*},
112+
answer => q{.*},
113+
comment => q{.*}
114+
};
115+
}
116+
122117
1;

lib/DB/Schema/Result/Course.pm

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package DB::Schema::Result::Course;
2-
use base qw/DBIx::Class::Core/;
32
use strict;
43
use warnings;
4+
use feature 'signatures';
5+
no warnings qw/experimental::signatures/;
56

7+
use base qw/DBIx::Class::Core DB::Validation/;
68
use Mojo::JSON qw/true false/;
79

810
=head1 DESCRIPTION
@@ -33,11 +35,6 @@ C<visible>: a boolean on whether the course is visible or not.
3335
3436
=cut
3537

36-
our @VALID_DATES = qw/open end/;
37-
our @REQUIRED_DATES = qw//;
38-
our $VALID_PARAMS = { visible => q{[01]} };
39-
our $REQUIRED_PARAMS = { _ALL_ => ['visible'] };
40-
4138
__PACKAGE__->table('course');
4239

4340
__PACKAGE__->load_components(qw/InflateColumn::Serializer InflateColumn::Boolean Core/);
@@ -46,23 +43,20 @@ __PACKAGE__->add_columns(
4643
course_id => {
4744
data_type => 'integer',
4845
size => 16,
49-
is_nullable => 0,
5046
is_auto_increment => 1,
5147
},
5248
course_name => {
53-
data_type => 'text',
54-
is_nullable => 0,
49+
data_type => 'text',
5550
},
5651
course_dates => {
5752
data_type => 'text',
58-
is_nullable => 0,
5953
default_value => '{}',
54+
retrieve_on_insert => 1,
6055
serializer_class => 'JSON',
6156
serializer_options => { utf8 => 1 }
6257
},
6358
visible => {
6459
data_type => 'boolean',
65-
is_nullable => 0,
6660
default_value => 1,
6761
retrieve_on_insert => 1
6862
}
@@ -83,4 +77,53 @@ __PACKAGE__->has_many(problem_pools => 'DB::Schema::Result::ProblemPool', 'cours
8377
# set up the one-to-one relationship to course settings;
8478
__PACKAGE__->has_one(course_settings => 'DB::Schema::Result::CourseSettings', 'course_id');
8579

80+
=head2 C<valid_fields>
81+
82+
subroutine that returns a hash of the valid fields for json columns
83+
84+
=cut
85+
86+
sub valid_fields ($, $field_name) {
87+
if ($field_name eq 'course_dates') {
88+
return {
89+
open => q{\d+},
90+
end => q{\d+}
91+
};
92+
} elsif ($field_name eq 'course_params') {
93+
return { visible => 'bool' };
94+
} else {
95+
return {};
96+
}
97+
}
98+
99+
=head2 C<additional_validation>
100+
101+
subroutine that checks json columns for consistency
102+
103+
=cut
104+
105+
sub additional_validation ($course, $field_name) {
106+
return 1 if ($field_name ne 'course_dates');
107+
108+
my $dates = $course->get_inflated_column('course_dates');
109+
DB::Exception::ImproperDateOrder->throw(message => 'The course dates are not in order')
110+
unless $dates->{end} > $dates->{open};
111+
112+
return 1;
113+
}
114+
115+
=head2 C<required>
116+
117+
subroutine that returns a hashref describing the required fields in JSON columns
118+
119+
=cut
120+
121+
sub required ($, $field_name) {
122+
if ($field_name eq 'set_dates') {
123+
return { '_ALL_' => [ 'open', 'end' ] };
124+
} else {
125+
return {};
126+
}
127+
}
128+
86129
1;

lib/DB/Schema/Result/CourseSettings.pm

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ C<email>: a JSON object that stores email settings
4747
4848
=cut
4949

50-
our @VALID_DATES = qw/open end/;
51-
our @REQUIRED_DATES = qw//;
52-
our $VALID = {
53-
institution => q{.*},
54-
visible => q{[01]}
55-
};
56-
our $REQUIRED = { _ALL_ => ['visible'] };
57-
5850
__PACKAGE__->table('course_settings');
5951

6052
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
@@ -63,59 +55,57 @@ __PACKAGE__->add_columns(
6355
course_settings_id => {
6456
data_type => 'integer',
6557
size => 16,
66-
is_nullable => 0,
6758
is_auto_increment => 1,
6859
},
6960
course_id => {
70-
data_type => 'integer',
71-
size => 16,
72-
is_nullable => 0,
61+
data_type => 'integer',
62+
size => 16,
7363
},
7464
general => {
7565
data_type => 'text',
7666
size => 256,
77-
is_nullable => 0,
7867
default_value => '{}',
68+
retrieve_on_insert => 1,
7969
serializer_class => 'JSON',
8070
serializer_options => { utf8 => 1 }
8171
},
8272
optional => {
8373
data_type => 'text',
8474
size => 256,
85-
is_nullable => 0,
8675
default_value => '{}',
76+
retrieve_on_insert => 1,
8777
serializer_class => 'JSON',
8878
serializer_options => { utf8 => 1 }
8979
},
9080
problem_set => {
9181
data_type => 'text',
9282
size => 256,
93-
is_nullable => 0,
9483
default_value => '{}',
84+
retrieve_on_insert => 1,
9585
serializer_class => 'JSON',
9686
serializer_options => { utf8 => 1 }
9787
},
9888
problem => {
9989
data_type => 'text',
10090
size => 256,
101-
is_nullable => 0,
10291
default_value => '{}',
92+
retrieve_on_insert => 1,
10393
serializer_class => 'JSON',
10494
serializer_options => { utf8 => 1 }
10595
},
10696
permissions => {
10797
data_type => 'text',
10898
size => 256,
109-
is_nullable => 0,
11099
default_value => '{}',
100+
retrieve_on_insert => 1,
111101
serializer_class => 'JSON',
112102
serializer_options => { utf8 => 1 }
113103
},
114104
email => {
115105
data_type => 'text',
116106
size => 256,
117-
is_nullable => 0,
118107
default_value => '{}',
108+
retrieve_on_insert => 1,
119109
serializer_class => 'JSON',
120110
serializer_options => { utf8 => 1 }
121111
}

lib/DB/Schema/Result/CourseUser.pm

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,19 @@ __PACKAGE__->add_columns(
9494
course_user_id => {
9595
data_type => 'integer',
9696
size => 16,
97-
is_nullable => 0,
9897
is_auto_increment => 1,
9998
},
10099
course_id => {
101-
data_type => 'integer',
102-
size => 16,
103-
is_nullable => 0,
100+
data_type => 'integer',
101+
size => 16,
104102
},
105103
user_id => {
106-
data_type => 'integer',
107-
size => 16,
108-
is_nullable => 0,
104+
data_type => 'integer',
105+
size => 16,
109106
},
110107
role_id => {
111108
data_type => 'integer',
112109
size => 16,
113-
is_nullable => 0,
114110
default_value => 0
115111
},
116112
section => {
@@ -127,34 +123,13 @@ __PACKAGE__->add_columns(
127123
course_user_params => {
128124
data_type => 'text',
129125
size => 256,
130-
is_nullable => 0,
131126
default_value => '{}',
127+
retrieve_on_insert => 1,
132128
serializer_class => 'JSON',
133129
serializer_options => { utf8 => 1 }
134130
}
135131
);
136132

137-
sub valid_fields ($self, $field_name) {
138-
if ($field_name eq 'course_user_params') {
139-
return {
140-
comment => q{.*},
141-
useMathQuill => 'bool',
142-
displayMode => q{.*},
143-
status => q{[A-Z]},
144-
lis_source_did => q{.*},
145-
showOldAnswers => 'bool'
146-
};
147-
}
148-
}
149-
150-
sub required ($self, $field_name) {
151-
return {};
152-
}
153-
154-
sub additional_validation ($self, $field_name) {
155-
return 1;
156-
}
157-
158133
__PACKAGE__->set_primary_key('course_user_id');
159134
__PACKAGE__->add_unique_constraint([qw/course_id user_id/]);
160135

@@ -170,4 +145,23 @@ __PACKAGE__->has_one(
170145
{ cascade_delete => 0 }
171146
);
172147

148+
=head2 C<valid_fields>
149+
150+
subroutine that returns a hash of the valid fields for json columns
151+
152+
=cut
153+
154+
sub valid_fields ($, $column_name) {
155+
if ($column_name eq 'course_user_params') {
156+
return {
157+
comment => q{.*},
158+
useMathQuill => 'bool',
159+
displayMode => q{.*},
160+
status => q{[A-Z]},
161+
lis_source_did => q{.*},
162+
showOldAnswers => 'bool'
163+
};
164+
}
165+
}
166+
173167
1;

lib/DB/Schema/Result/DBPermRole.pm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@ __PACKAGE__->add_columns(
3434
db_perm_role_id => {
3535
data_type => 'integer',
3636
size => 16,
37-
is_nullable => 0,
3837
is_auto_increment => 1,
3938
},
4039
db_perm_id => {
41-
data_type => 'integer',
42-
size => 16,
43-
is_nullable => 0,
40+
data_type => 'integer',
41+
size => 16,
4442
},
4543
role_id => {
46-
data_type => 'integer',
47-
size => 16,
48-
is_nullable => 0,
44+
data_type => 'integer',
45+
size => 16,
4946
}
5047
);
5148

lib/DB/Schema/Result/DBPermission.pm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ __PACKAGE__->add_columns(
3939
db_perm_id => {
4040
data_type => 'integer',
4141
size => 16,
42-
is_nullable => 0,
4342
is_auto_increment => 1
4443
},
4544
category => {
46-
data_type => 'text',
47-
is_nullable => 0,
45+
data_type => 'text',
4846
},
4947
action => {
50-
data_type => 'text',
51-
is_nullable => 0,
48+
data_type => 'text',
5249
},
5350
admin_required => {
5451
data_type => 'boolean',

0 commit comments

Comments
 (0)