From ba36ddd5cbd0390a40923329f668a1d57abaa884 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Tue, 25 Sep 2018 12:42:35 +0100 Subject: [PATCH] Fixed overall observation scores being stored as ints instead of floats. --- .../Observations/api/NewObservation.java | 2 +- .../neviyn/Observations/core/Observation.java | 2 +- .../resources/ObservationResource.java | 3 +- .../Observations/dao/ObservationDaoTest.java | 2 +- .../resources/ObservationResourceTest.java | 2 +- frontend/src/store.js | 17 +++-- frontend/src/views/Home.vue | 23 ++++-- frontend/src/views/Observation.vue | 70 +++++++++---------- 8 files changed, 67 insertions(+), 54 deletions(-) diff --git a/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java b/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java index b8cad17..e86db3f 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java @@ -26,7 +26,7 @@ public class NewObservation { @NonNull @JsonProperty - private int monitoring, control, conservatism, teamwork, knowledge; + private float monitoring, control, conservatism, teamwork, knowledge; @NonNull @JsonProperty diff --git a/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java b/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java index 8f913b5..3c8a845 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java @@ -49,7 +49,7 @@ public class Observation implements Serializable { @NonNull @JsonProperty - private int monitoring, control, conservatism, teamwork, knowledge; + private float monitoring, control, conservatism, teamwork, knowledge; @NonNull @JsonProperty diff --git a/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java b/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java index f7ed89a..b920649 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java @@ -37,7 +37,8 @@ public class ObservationResource { @POST @UnitOfWork - public long add(@NotNull @Valid NewObservation newObservation) { + public long add(@NotNull NewObservation newObservation) { + log.info(newObservation.toString()); final DateTime submissionDate = LocalDate.now().toDateTimeAtStartOfDay(); Set tutors = new HashSet<>(); for (long l : newObservation.getTutorIds()) { diff --git a/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java b/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java index c7f2b4d..63fc3f5 100644 --- a/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java +++ b/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java @@ -23,7 +23,7 @@ public class ObservationDaoTest extends DaoTestBase { private final Site site = Site.builder().name("Test site").build(); private final Observation observation = Observation.builder().observed("Just a test observation").type(TrainingType.INITIAL) - .site(site).monitoring(1).control(2).conservatism(3).teamwork(4).knowledge(5).whom("Group A") + .site(site).monitoring(1f).control(2f).conservatism(3f).teamwork(4f).knowledge(5f).whom("Group A") .observations(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum"))) .date(DateTime.parse("2018-09-18T00:00:00.000Z")).build(); diff --git a/backend/src/test/java/uk/co/neviyn/Observations/resources/ObservationResourceTest.java b/backend/src/test/java/uk/co/neviyn/Observations/resources/ObservationResourceTest.java index 3f4a807..f4373df 100644 --- a/backend/src/test/java/uk/co/neviyn/Observations/resources/ObservationResourceTest.java +++ b/backend/src/test/java/uk/co/neviyn/Observations/resources/ObservationResourceTest.java @@ -46,7 +46,7 @@ public class ObservationResourceTest { when(tutorDao.get(1)).thenReturn(tutors.get(0)); when(tutorDao.get(2)).thenReturn(tutors.get(1)); resources.target("/observation").request().post(Entity.json(NewObservation.builder().type("INITIAL") - .conservatism(1).control(2).knowledge(3).monitoring(4).teamwork(5).siteId(1).tutorIds(Arrays.asList(1L, 2L)) + .conservatism(1f).control(2f).knowledge(3f).monitoring(4f).teamwork(5f).siteId(1).tutorIds(Arrays.asList(1L, 2L)) .observed("").whom("Group A").rawData(new ArrayList<>()).build())); verify(dao, times(1)).persist(any(Observation.class)); } diff --git a/frontend/src/store.js b/frontend/src/store.js index f13691c..9211943 100644 --- a/frontend/src/store.js +++ b/frontend/src/store.js @@ -8,7 +8,8 @@ export default new Vuex.Store({ site: null, tutors: [], description: null, - type: null + type: null, + whom: null }, mutations: { setSite(state, newSite) { @@ -23,13 +24,15 @@ export default new Vuex.Store({ setType(state, newType) { state.type = newType; }, + setWhom(state, newWhom) { + state.whom = newWhom; + }, resetStore(state) { - state = { - site: null, - tutors: [], - description: null, - type: null - }; + state.site = null; + state.tutors = []; + state.description = null; + state.type = null; + state.whom = null; } }, actions: {} diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index 5437a4f..64d749a 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -28,6 +28,13 @@ + + + + + + + @@ -83,10 +90,7 @@ export default { }; }, mounted() { - this.site = null; - this.description = null; - this.type = null; - this.tutors = []; + this.resetStore(); Vue.axios .get("/api/site/all") .then(response => { @@ -100,7 +104,7 @@ export default { }); }, computed: { - ...mapState(["site", "description", "type", "tutors"]) + ...mapState(["site", "description", "type", "tutors", "whom"]) }, watch: { site: function() { @@ -111,7 +115,14 @@ export default { } }, methods: { - ...mapMutations(["setSite", "setDescription", "setType", "setTutors"]), + ...mapMutations([ + "setSite", + "setDescription", + "setType", + "setTutors", + "setWhom", + "resetStore" + ]), getTutors: function() { if (this.site != null) { Vue.axios.get("/api/site/" + this.site + "/tutors").then(response => { diff --git a/frontend/src/views/Observation.vue b/frontend/src/views/Observation.vue index 1314a4d..dcfc9a5 100644 --- a/frontend/src/views/Observation.vue +++ b/frontend/src/views/Observation.vue @@ -2,16 +2,6 @@

{{type}}/{{description}}

-
- -
-

Enter confirmation code in order to submit.

- -
- Submit - Close -
-
@@ -120,7 +110,7 @@ export default { }; }, computed: { - ...mapState(["description", "type"]) + ...mapState(["description", "type", "whom", "site", "tutors"]) }, methods: { addAnotherObservation: function() { @@ -193,8 +183,40 @@ export default { e.preventDefault(); e.stopPropagation(); var form = document.getElementById("submission-form"); + console.log({ + siteId: this.site, + tutorIds: this.tutors, + observed: this.description, + whom: this.whom, + type: this.type, + monitoring: this.totals[0], + control: this.totals[1], + conservatism: this.totals[2], + teamwork: this.totals[3], + knowledge: this.totals[4], + rawData: JSON.parse(JSON.stringify(this.observations)) + }); if (form.checkValidity()) { - this.showModal(); + Vue.axios + .post("/api/observation", { + siteId: this.site, + tutorIds: this.tutors, + observed: this.description, + whom: this.whom, + type: this.type, + monitoring: this.totals[0], + control: this.totals[1], + conservatism: this.totals[2], + teamwork: this.totals[3], + knowledge: this.totals[4], + rawData: JSON.parse(JSON.stringify(this.observations)) + }) + .then(function(response) { + console.log(response); + }) + .catch(function(error) { + console.log(error); + }); } form.classList.add("was-validated"); }, @@ -204,30 +226,6 @@ export default { hideModal() { this.$refs.submissionModal.hide(); this.submitPassword = null; - }, - reallySubmit() { - var form = document.getElementById("submission-form"); - if (form.checkValidity()) { - Vue.axios - .post("/api/observation", { - siteId: this.site, - tutorIds: this.tutors, - observed: this.description, - type: this.type, - monitoring: this.totals[0], - control: this.totals[1], - conservatism: this.totals[2], - teamwork: this.totals[3], - knowledge: this.totals[4], - rawData: this.observations - }) - .then(function(response) { - console.log(response); - }) - .catch(function(error) { - console.log(error); - }); - } } } };