@@ -25,6 +25,48 @@ public struct TextSubmission: BaseSubmission {
25
25
public var blocks : [ TextBlock ] ?
26
26
}
27
27
28
+ public extension TextSubmission {
29
+ private enum CodingKeys : String , CodingKey {
30
+ case type = " submissionExerciseType "
31
+ case id
32
+ case submitted
33
+ case submissionDate
34
+ case exampleSubmission
35
+ case durationInMinutes
36
+ case results
37
+ case participation
38
+ case text
39
+ case blocks
40
+ }
41
+
42
+ init ( from decoder: Decoder ) throws {
43
+ let container = try decoder. container ( keyedBy: CodingKeys . self)
44
+ id = try container. decodeIfPresent ( Int . self, forKey: . id)
45
+ submitted = try container. decodeIfPresent ( Bool . self, forKey: . submitted)
46
+ submissionDate = try container. decodeIfPresent ( Date . self, forKey: . submissionDate)
47
+ exampleSubmission = try container. decodeIfPresent ( Bool . self, forKey: . exampleSubmission)
48
+ durationInMinutes = try container. decodeIfPresent ( Double . self, forKey: . durationInMinutes)
49
+ results = try container. decodeIfPresent ( [ Result ? ] . self, forKey: . results)
50
+ participation = try container. decodeIfPresent ( Participation . self, forKey: . participation)
51
+ text = try container. decodeIfPresent ( String . self, forKey: . text)
52
+ blocks = try container. decodeIfPresent ( [ TextBlock ] . self, forKey: . blocks)
53
+ }
54
+
55
+ public func encode( to encoder: Encoder ) throws {
56
+ var container = encoder. container ( keyedBy: CodingKeys . self)
57
+ try container. encode ( Self . type, forKey: . type)
58
+ try container. encode ( id, forKey: . id)
59
+ try container. encode ( submitted, forKey: . submitted)
60
+ try container. encode ( submissionDate, forKey: . submissionDate)
61
+ try container. encode ( exampleSubmission, forKey: . exampleSubmission)
62
+ try container. encode ( durationInMinutes, forKey: . durationInMinutes)
63
+ try container. encode ( results, forKey: . results)
64
+ try container. encode ( participation, forKey: . participation)
65
+ try container. encode ( text, forKey: . text)
66
+ try container. encode ( blocks, forKey: . blocks)
67
+ }
68
+ }
69
+
28
70
public struct TextBlock : Codable {
29
71
public var id : String ?
30
72
public var text : String ?
0 commit comments