Commit a2ede9b76bf3b0be8b52fb38abd3a1751b1789bb

Authored by kristinlaahneolsen
1 parent 3a30cf41

suksessfull innsetting av log-entry gjennom postman. Mangler nå endpoint til det…

…te, og implementere d i appen
Risiko/app/src/main/java/activity/EvaluationLog.java
... ... @@ -48,7 +48,6 @@ public class EvaluationLog extends AppCompatActivity {
48 48 Api.get().getEvaluationLog(assosiatedeval).enqueue(new Callback<List<dataclasses.EvaluationLog>>() {
49 49 @Override
50 50 public void onResponse(Call<List<dataclasses.EvaluationLog>> call, Response<List<dataclasses.EvaluationLog>> response) {
51   - System.out.println("VÆÆÆR SÅ SNIIILL");
52 51 if (response.isSuccessful()) {
53 52 List<dataclasses.EvaluationLog> log = response.body();
54 53 List<dataclasses.EvaluationLog> logs = new ArrayList<>();
... ... @@ -67,7 +66,7 @@ public class EvaluationLog extends AppCompatActivity {
67 66  
68 67 @Override
69 68 public void onFailure(Call<List<dataclasses.EvaluationLog>> call, Throwable t) {
70   - System.out.println("DIN DUST");
  69 + t.printStackTrace();
71 70  
72 71 }
73 72 });
... ...
restApi/.idea/workspace.xml
... ... @@ -50,8 +50,8 @@
50 50 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
51 51 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
52 52 <provider selected="true" editor-type-id="text-editor">
53   - <state relative-caret-position="169">
54   - <caret line="367" column="35" lean-forward="false" selection-start-line="367" selection-start-column="35" selection-end-line="367" selection-end-column="35" />
  53 + <state relative-caret-position="464">
  54 + <caret line="406" column="42" lean-forward="true" selection-start-line="406" selection-start-column="42" selection-end-line="406" selection-end-column="42" />
55 55 <folding />
56 56 </state>
57 57 </provider>
... ... @@ -122,9 +122,8 @@
122 122 </packageJsonPaths>
123 123 </component>
124 124 <component name="ProjectFrameBounds" extendedState="6" fullScreen="true">
125   - <option name="y" value="23" />
126   - <option name="width" value="1440" />
127   - <option name="height" value="873" />
  125 + <option name="width" value="450" />
  126 + <option name="height" value="900" />
128 127 </component>
129 128 <component name="ProjectView">
130 129 <navigator currentView="ProjectPane" proportions="" version="1">
... ... @@ -242,24 +241,24 @@
242 241 <workItem from="1541681303243" duration="9060000" />
243 242 <workItem from="1542189792461" duration="7537000" />
244 243 <workItem from="1542881688157" duration="372000" />
245   - <workItem from="1543226716067" duration="4130000" />
  244 + <workItem from="1543226716067" duration="6979000" />
246 245 </task>
247 246 <servers />
248 247 </component>
249 248 <component name="TimeTrackingManager">
250   - <option name="totallyTimeSpent" value="33821000" />
  249 + <option name="totallyTimeSpent" value="36670000" />
251 250 </component>
252 251 <component name="ToolWindowManager">
253   - <frame x="0" y="0" width="1071" height="900" extended-state="6" />
  252 + <frame x="0" y="0" width="1045" height="900" extended-state="6" />
254 253 <editor active="true" />
255 254 <layout>
256   - <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2704762" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
  255 + <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13476562" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
257 256 <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
258 257 <window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
259 258 <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="true" content_ui="tabs" />
260 259 <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32769045" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
261 260 <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
262   - <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2704762" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
  261 + <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13476562" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
263 262 <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
264 263 <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
265 264 <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39903265" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
... ... @@ -366,8 +365,8 @@
366 365 </entry>
367 366 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
368 367 <provider selected="true" editor-type-id="text-editor">
369   - <state relative-caret-position="169">
370   - <caret line="367" column="35" lean-forward="false" selection-start-line="367" selection-start-column="35" selection-end-line="367" selection-end-column="35" />
  368 + <state relative-caret-position="464">
  369 + <caret line="406" column="42" lean-forward="true" selection-start-line="406" selection-start-column="42" selection-end-line="406" selection-end-column="42" />
371 370 <folding />
372 371 </state>
373 372 </provider>
... ...
restApi/api/routes/routes.js
... ... @@ -352,12 +352,12 @@ var appRouter = function(app) {
352 352 }
353 353 }
354 354 );
355   - })
  355 + });
356 356  
357 357  
358 358  
359 359 /**
360   - * See evaluationlog
  360 + * See evaluationlog connected to a spesific evaluation
361 361 */
362 362 app.get("/evaluation/:assosiatedeval/evaluationlog", function (req, res) {
363 363 if (!req.params.assosiatedeval) {
... ... @@ -386,6 +386,29 @@ var appRouter = function(app) {
386 386 }
387 387 );
388 388 });
  389 +
  390 + /**
  391 + * Add a new log entry
  392 + */
  393 + app.post("/evaluationlog", function(req, res) {
  394 + if(!req.body.name || !req.body.date || !req.body.changedfields || !req.body.associatedeval) {
  395 + logEndpoint("post /evaluationlog", null, "Missing params in body");
  396 + return res.status(400).send("Missing params");
  397 + } else {
  398 + const query = 'INSERT INTO risk.evaluationlog(id, name, date, changedfields, associatedeval) ' +
  399 + 'VALUES(?,?,?,?,?)';
  400 + const params = [uuid(), req.body.name, req.body.date, req.body.changedfields, req.body.associatedeval];
  401 + db.execute(query, params, { prepare: true }, function (err) {
  402 + if (err) {
  403 + logEndpoint("post /evaluationlog", err, "Bad request, see API log");
  404 + return res.status(400).send("Bad Request");
  405 + }
  406 + logEndpoint("post /evaluationlog", err, "Success, log created");
  407 + return res.status(200).send("Log Created");
  408 + })
  409 + }
  410 + });
  411 +
389 412 };
390 413  
391 414 /**
... ... @@ -433,7 +456,7 @@ function setupTables(db) {
433 456 }
434 457 });
435 458  
436   - db.execute("CREATE TABLE risk.evaluationlog(id uuid, name text, date text, changedfields text, associatedEval uuid, PRIMARY KEY(id));", function (err) {
  459 + db.execute("CREATE TABLE risk.evaluationlog(id uuid, name text, date text, changedfields text, associatedeval uuid, PRIMARY KEY(id));", function (err) {
437 460 if (err) console.log("Failed to create table evaluationlog.\n" + err)
438 461 });
439 462  
... ...