Преглед изворни кода

should have made a jsonable superclass

master
DemiSel пре 2 година
родитељ
комит
92ed6cb0a6

+ 1
- 1
backend/src/main/java/model/questionnaire/Session.java Прегледај датотеку

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

+ 18
- 12
backend/src/main/java/model/questionnaire/SessionAnswers.java Прегледај датотеку

@@ -60,6 +60,23 @@ public class SessionAnswers implements Jsonable {
60 60
     // ------------------------------------------------------------------
61 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 80
     @Override
64 81
     public String toJson() {
65 82
         final StringWriter writable = new StringWriter();
@@ -74,18 +91,7 @@ public class SessionAnswers implements Jsonable {
74 91
 
75 92
     @Override
76 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 Прегледај датотеку

@@ -3,6 +3,7 @@ import url from '../server';
3 3
 
4 4
 function QuestionnaireResult(props){
5 5
     const [resultsFetched, onResultsFetched] = React.useState(null);
6
+    console.log(resultsFetched);
6 7
 
7 8
     if(null === resultsFetched)
8 9
     {

Loading…
Откажи
Сачувај