Skip to content

Commit 0cabd45

Browse files
committed
feat(model): add solutions
1 parent 48f79b6 commit 0cabd45

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class Challenge {
7373
// Challenge Type 15 - Odin
7474
final List<String>? assignments;
7575

76+
final List<List<SolutionFile>>? solutions;
77+
7678
Challenge({
7779
required this.id,
7880
required this.block,
@@ -94,6 +96,7 @@ class Challenge {
9496
this.audio,
9597
this.scene,
9698
required this.hooks,
99+
this.solutions,
97100
});
98101

99102
factory Challenge.fromJson(Map<String, dynamic> data) {
@@ -134,6 +137,13 @@ class Challenge {
134137
hooks: Hooks.fromJson(
135138
data['hooks'] ?? {'beforeAll': ''},
136139
),
140+
solutions: data['solutions'] != null
141+
? (data['solutions'] as List)
142+
.map<List<SolutionFile>>((solutionList) => (solutionList as List)
143+
.map<SolutionFile>((file) => SolutionFile.fromJson(file))
144+
.toList())
145+
.toList()
146+
: null,
137147
);
138148
}
139149

@@ -180,6 +190,10 @@ class Challenge {
180190
'solution': question.solution,
181191
})
182192
.toList(),
193+
'solutions': challenge.solutions
194+
?.map((solutionList) =>
195+
solutionList.map((file) => file.toJson()).toList())
196+
.toList(),
183197
};
184198
}
185199
}
@@ -494,3 +508,61 @@ class EnglishAudio {
494508
);
495509
}
496510
}
511+
512+
class SolutionFile {
513+
final String head;
514+
final String tail;
515+
final String id;
516+
final List<String> history;
517+
final String name;
518+
final String ext;
519+
final String path;
520+
final String fileKey;
521+
final String contents;
522+
final String seed;
523+
final String? error;
524+
525+
SolutionFile({
526+
required this.head,
527+
required this.tail,
528+
required this.id,
529+
required this.history,
530+
required this.name,
531+
required this.ext,
532+
required this.path,
533+
required this.fileKey,
534+
required this.contents,
535+
required this.seed,
536+
this.error,
537+
});
538+
539+
factory SolutionFile.fromJson(Map<String, dynamic> data) {
540+
return SolutionFile(
541+
head: data['head'] ?? '',
542+
tail: data['tail'] ?? '',
543+
id: data['id'] ?? '',
544+
history: ((data['history'] ?? []) as List).cast<String>(),
545+
name: data['name'] ?? '',
546+
ext: data['ext'] ?? '',
547+
path: data['path'] ?? '',
548+
fileKey: data['fileKey'] ?? '',
549+
contents: data['contents'] ?? '',
550+
seed: data['seed'] ?? '',
551+
error: data['error'],
552+
);
553+
}
554+
555+
Map<String, dynamic> toJson() => {
556+
'head': head,
557+
'tail': tail,
558+
'id': id,
559+
'history': history,
560+
'name': name,
561+
'ext': ext,
562+
'path': path,
563+
'fileKey': fileKey,
564+
'contents': contents,
565+
'seed': seed,
566+
'error': error,
567+
};
568+
}

0 commit comments

Comments
 (0)