Browse Source

should have made a jsonable superclass

master
DemiSel 2 years ago
parent
commit
92ed6cb0a6

+ 1
- 1
backend/src/main/java/model/questionnaire/Session.java View File

41
     public JsonObject asJsonObject() {
41
     public JsonObject asJsonObject() {
42
         JsonObject vResult = new JsonObject();
42
         JsonObject vResult = new JsonObject();
43
         vResult.put(KEY_ID, fId.toString());
43
         vResult.put(KEY_ID, fId.toString());
44
-        vResult.put(KEY_RESULTS, fAnswers.toJson());
44
+        vResult.put(KEY_RESULTS, fAnswers.asJsonObject());
45
         return vResult;
45
         return vResult;
46
     }
46
     }
47
 
47
 

+ 18
- 12
backend/src/main/java/model/questionnaire/SessionAnswers.java View File

60
     // ------------------------------------------------------------------
60
     // ------------------------------------------------------------------
61
     // Jsonable Implementation
61
     // Jsonable Implementation
62
     // ------------------------------------------------------------------
62
     // ------------------------------------------------------------------
63
+    public JsonObject asJsonObject()
64
+    {
65
+        JsonObject vResult = new JsonObject();
66
+        JsonArray vAnswers = new JsonArray();
67
+        fAnswers.forEach( (question, answer) -> {
68
+            vAnswers.add(answer.asJsonObject().putChain(KEY_QUESTION, question.asJsonObject()));
69
+        });
70
+        vResult.put(KEY_ANSWERS, vAnswers);
71
+        JsonArray vTraits = new JsonArray();
72
+        fTraits.forEach( (trait, weight) -> {
73
+            vTraits.add(trait.asJsonObject().putChain(KEY_WEIGHT, weight));
74
+        });
75
+        vResult.put(KEY_TRAITS, vTraits);
76
+        return vResult;
77
+    }
78
+
79
+
63
     @Override
80
     @Override
64
     public String toJson() {
81
     public String toJson() {
65
         final StringWriter writable = new StringWriter();
82
         final StringWriter writable = new StringWriter();
74
 
91
 
75
     @Override
92
     @Override
76
     public void toJson(Writer writable) throws IOException {
93
     public void toJson(Writer writable) throws IOException {
77
-        JsonObject vResult = new JsonObject();
78
-        JsonArray vAnswers = new JsonArray();
79
-        fAnswers.forEach( (question, answer) -> {
80
-            vAnswers.add(answer.asJsonObject().putChain(KEY_QUESTION, question.asJsonObject()));
81
-        });
82
-        vResult.put(KEY_ANSWERS, vAnswers);
83
-        JsonArray vTraits = new JsonArray();
84
-        fTraits.forEach( (trait, weight) -> {
85
-            vTraits.add(trait.asJsonObject().putChain(KEY_WEIGHT, weight));
86
-        });
87
-        vResult.put(KEY_TRAITS, vTraits);
88
-        writable.write(new String(vResult.toJson().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
94
+        writable.write(new String(asJsonObject().toJson().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
89
     }
95
     }
90
 
96
 
91
 }
97
 }

+ 1
- 0
frontend/src/component/questionnaire_result.js View File

3
 
3
 
4
 function QuestionnaireResult(props){
4
 function QuestionnaireResult(props){
5
     const [resultsFetched, onResultsFetched] = React.useState(null);
5
     const [resultsFetched, onResultsFetched] = React.useState(null);
6
+    console.log(resultsFetched);
6
 
7
 
7
     if(null === resultsFetched)
8
     if(null === resultsFetched)
8
     {
9
     {

Loading…
Cancel
Save