Skip to content

Commit 667c840

Browse files
fix(model): use enum for chapterType and moduleType (#1514)
1 parent 88ca4ac commit 667c840

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

mobile-app/lib/models/learn/curriculum_model.dart

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class SuperBlock {
2525
return Chapter(
2626
dashedName: chapter['dashedName'],
2727
comingSoon: chapter['comingSoon'] ?? false,
28-
chapterType: chapter['chapterType'],
28+
chapterType: ChapterType.fromValue(chapter['chapterType']),
2929
modules: (chapter['modules']).map<Module>((module) {
3030
return Module(
3131
dashedName: module['dashedName'],
3232
comingSoon: module['comingSoon'] ?? false,
33-
moduleType: module['moduleType'],
33+
moduleType: ModuleType.fromValue(module['moduleType']),
3434
blocks: (module['blocks']).map<Block>((block) {
3535
return Block.fromJson(
3636
block['meta'],
@@ -209,10 +209,24 @@ class ChallengeOrder {
209209
});
210210
}
211211

212+
enum ChapterType {
213+
exam('exam');
214+
215+
static ChapterType fromValue(String value) {
216+
return ChapterType.values.firstWhere(
217+
(chapterType) => chapterType.value == value,
218+
orElse: () => throw ArgumentError('Invalid chapter type value: $value'),
219+
);
220+
}
221+
222+
final String value;
223+
const ChapterType(this.value);
224+
}
225+
212226
class Chapter {
213227
final String dashedName;
214228
final bool? comingSoon;
215-
final String? chapterType;
229+
final ChapterType? chapterType;
216230
final List<Module>? modules;
217231

218232
Chapter({
@@ -223,10 +237,25 @@ class Chapter {
223237
});
224238
}
225239

240+
enum ModuleType {
241+
review('review'),
242+
exam('exam');
243+
244+
static ModuleType fromValue(String value) {
245+
return ModuleType.values.firstWhere(
246+
(moduleType) => moduleType.value == value,
247+
orElse: () => throw ArgumentError('Invalid module type value: $value'),
248+
);
249+
}
250+
251+
final String value;
252+
const ModuleType(this.value);
253+
}
254+
226255
class Module {
227256
final String dashedName;
228257
final bool? comingSoon;
229-
final String? moduleType;
258+
final ModuleType? moduleType;
230259
final List<Block>? blocks;
231260

232261
Module({

0 commit comments

Comments
 (0)