diff --git a/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEvent.java b/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEvent.java index 3f313998bc..efba60bfaa 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEvent.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEvent.java @@ -54,8 +54,8 @@ public class VolunteeringEvent { @Column(name = "hours") @Schema(description = "number of hours spent volunteering") - @TypeDef(type = DataType.INTEGER) - private int hours; + @TypeDef(type = DataType.DOUBLE) + private double hours; @Nullable @Column(name = "notes") @@ -63,7 +63,7 @@ public class VolunteeringEvent { @Schema(description = "notes about the volunteering event") private String notes; - public VolunteeringEvent(UUID relationshipId, LocalDate eventDate, int hours, String notes) { + public VolunteeringEvent(UUID relationshipId, LocalDate eventDate, double hours, String notes) { this(null, relationshipId, eventDate, hours, notes); } @@ -79,4 +79,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(id, relationshipId, eventDate, hours, notes); } -} \ No newline at end of file +} diff --git a/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventDTO.java b/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventDTO.java index 4d56245e01..a296d944de 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventDTO.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventDTO.java @@ -29,9 +29,9 @@ public class VolunteeringEventDTO { @NotNull @Schema(description = "number of hours spent volunteering") - private Integer hours; + private Double hours; @Nullable @Schema(description = "notes about the volunteering event") private String notes; -} \ No newline at end of file +} diff --git a/server/src/main/resources/db/common/V119__alter_volunteering_event_table.sql b/server/src/main/resources/db/common/V119__alter_volunteering_event_table.sql new file mode 100644 index 0000000000..5f54908312 --- /dev/null +++ b/server/src/main/resources/db/common/V119__alter_volunteering_event_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE volunteering_event +ALTER COLUMN hours TYPE float; diff --git a/server/src/test/java/com/objectcomputing/checkins/services/fixture/VolunteeringFixture.java b/server/src/test/java/com/objectcomputing/checkins/services/fixture/VolunteeringFixture.java index bc25b5653e..0d926c16ce 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/fixture/VolunteeringFixture.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/fixture/VolunteeringFixture.java @@ -41,7 +41,7 @@ default VolunteeringRelationship createVolunteeringRelationship(UUID memberId, U return getVolunteeringRelationshipRepository().save(new VolunteeringRelationship(memberId, organizationId, startDate, endDate, active)); } - default VolunteeringEvent createVolunteeringEvent(UUID relationshipId, LocalDate now, int i, String notes) { + default VolunteeringEvent createVolunteeringEvent(UUID relationshipId, LocalDate now, double i, String notes) { return getVolunteeringEventRepository().save(new VolunteeringEvent(relationshipId, now, i, notes)); } } diff --git a/server/src/test/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventControllerTest.java b/server/src/test/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventControllerTest.java index 804edaf2bf..6b6f84cb98 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventControllerTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/volunteering/VolunteeringEventControllerTest.java @@ -30,6 +30,8 @@ @Property(name = VolunteeringClients.Event.ENABLED, value = "true") class VolunteeringEventControllerTest extends TestContainersSuite implements MemberProfileFixture, RoleFixture, VolunteeringFixture { + static final double fiveHours = 5.0; + static final double tenHours = 10.0; @Inject VolunteeringClients.Event eventClient; @@ -63,7 +65,7 @@ void memberCanCreateEventForTheirRelationships() { LocalDate now = LocalDate.now(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - var event = new VolunteeringEventDTO(relationship.getId(), now, 10, "Notes"); + var event = new VolunteeringEventDTO(relationship.getId(), now, tenHours, "Notes"); var createdEvent = eventClient.create(timAuth, event); assertEquals(HttpStatus.CREATED, createdEvent.getStatus()); @@ -83,7 +85,7 @@ void memberCannotCreateEventForSomeoneElseRelationships() { LocalDate now = LocalDate.now(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - var event = new VolunteeringEventDTO(relationship.getId(), now, 10, "Notes"); + var event = new VolunteeringEventDTO(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), MEMBER_ROLE); @@ -104,7 +106,7 @@ void memberWithPermissionCanCreateEventForSomeoneElseRelationships() { MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), ADMIN_ROLE); - var event = new VolunteeringEventDTO(relationship.getId(), now, 10, "Notes"); + var event = new VolunteeringEventDTO(relationship.getId(), now, tenHours, "Notes"); var createdEvent = eventClient.create(bobAuth, event); assertEquals(HttpStatus.CREATED, createdEvent.getStatus()); @@ -124,9 +126,9 @@ void memberCanUpdateTheirOwnEvents() { VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); - var updated = eventClient.update(timAuth, event.getId(), new VolunteeringEventDTO(relationship.getId(), now, 5, "New notes")); + var updated = eventClient.update(timAuth, event.getId(), new VolunteeringEventDTO(relationship.getId(), now, fiveHours, "New notes")); assertEquals(event.getId(), updated.getId()); assertEquals("New notes", updated.getNotes()); } @@ -138,12 +140,12 @@ void memberCannotUpdateOthersEvents() { VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), MEMBER_ROLE); - var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(relationship.getId(), now, 5, "New notes"))); + var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(relationship.getId(), now, fiveHours, "New notes"))); assertEquals(HttpStatus.BAD_REQUEST, e.getStatus()); assertEquals("Member %s does not have permission to update Volunteering event for relationship %s".formatted(bob.getId(), relationship.getId()), e.getMessage()); } @@ -157,12 +159,12 @@ void memberCannotUpdateTheirEventToSomeoneElse() { VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); VolunteeringRelationship bobRelationship = createVolunteeringRelationship(bob.getId(), organization.getId(), now); - var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(timAuth, event.getId(), new VolunteeringEventDTO(bobRelationship.getId(), now, 5, "New notes"))); + var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(timAuth, event.getId(), new VolunteeringEventDTO(bobRelationship.getId(), now, fiveHours, "New notes"))); assertEquals(HttpStatus.BAD_REQUEST, e.getStatus()); assertEquals("Member %s does not have permission to update Volunteering event for relationship %s".formatted(tim.getId(), bobRelationship.getId()), e.getMessage()); } @@ -175,13 +177,13 @@ void memberCannotUpdateSomeoneElseEventToTheirs() { VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), MEMBER_ROLE); VolunteeringRelationship bobRelationship = createVolunteeringRelationship(bob.getId(), organization.getId(), now); - var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(bobRelationship.getId(), now, 5, "New notes"))); + var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(bobRelationship.getId(), now, fiveHours, "New notes"))); assertEquals(HttpStatus.BAD_REQUEST, e.getStatus()); assertEquals("Member %s does not have permission to update Volunteering event for relationship %s".formatted(bob.getId(), relationship.getId()), e.getMessage()); } @@ -192,13 +194,13 @@ void memberCannotHackUpdateOthersEventsWithTheirOwnRelationship() { MemberProfile tim = createADefaultMemberProfile(); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), MEMBER_ROLE); VolunteeringRelationship bobsRelationship = createVolunteeringRelationship(bob.getId(), organization.getId(), now); - var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(bobsRelationship.getId(), now, 5, "New notes"))); + var e = assertThrows(HttpClientResponseException.class, () -> eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(bobsRelationship.getId(), now, fiveHours, "New notes"))); assertEquals(HttpStatus.BAD_REQUEST, e.getStatus()); assertEquals("Member %s does not have permission to update Volunteering event for relationship %s".formatted(bob.getId(), relationship.getId()), e.getMessage()); } @@ -209,12 +211,12 @@ void memberCanUpdateOthersEventsWithProperPermission() { MemberProfile tim = createADefaultMemberProfile(); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), ADMIN_ROLE); - var updated = eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(relationship.getId(), now, 5, "New notes")); + var updated = eventClient.update(bobAuth, event.getId(), new VolunteeringEventDTO(relationship.getId(), now, fiveHours, "New notes")); assertEquals(event.getId(), updated.getId()); assertEquals("New notes", updated.getNotes()); } @@ -226,7 +228,7 @@ void memberCanDeleteTheirOwnEvents() { String timAuth = auth(tim.getWorkEmail(), MEMBER_ROLE); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); var deletedEvent = eventClient.delete(timAuth, event.getId()); assertEquals(HttpStatus.OK, deletedEvent.getStatus()); @@ -238,7 +240,7 @@ void memberCannotDeleteOthersEvents() { MemberProfile tim = createADefaultMemberProfile(); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), MEMBER_ROLE); @@ -254,7 +256,7 @@ void memberWithPermissionCanDeleteOthersEvents() { MemberProfile tim = createADefaultMemberProfile(); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); MemberProfile bob = memberWithoutBoss("bob"); String bobAuth = auth(bob.getWorkEmail(), ADMIN_ROLE); @@ -304,13 +306,13 @@ void eventListCanBeFiltered() { var bobClosed = createVolunteeringRelationship(bob.getId(), closedOrg.getId(), now.minusDays(100), now.minusDays(50), false); var clairClosed = createVolunteeringRelationship(claire.getId(), closedOrg.getId(), now.minusDays(1), now); - var aliceLiftEvent1 = createVolunteeringEvent(aliceLiftForLife.getId(), now.minusDays(2), 10, "aliceLiftEvent1"); // 2 days ago + var aliceLiftEvent1 = createVolunteeringEvent(aliceLiftForLife.getId(), now.minusDays(2), tenHours, "aliceLiftEvent1"); // 2 days ago var aliceLiftEvent2 = createVolunteeringEvent(aliceLiftForLife.getId(), now, 8, "aliceLiftEvent2"); // today var bobLiftEvent1 = createVolunteeringEvent(bobLiftForLife.getId(), now, 6, "bobLiftEvent1"); // today var clairLiftEvent1 = createVolunteeringEvent(claireLiftForLife.getId(), now.minusDays(3), 4, "clairLiftEvent1"); // 3 days ago var aliceFoodEvent1 = createVolunteeringEvent(aliceFood.getId(), now.minusDays(20), 2, "aliceFoodEvent1"); // 20 days ago var clairFoodEvent1 = createVolunteeringEvent(claireFood.getId(), now, 1, "clairFoodEvent1"); // today - var bobClosedEvent1 = createVolunteeringEvent(bobClosed.getId(), now.minusDays(76), 10, "bobClosedEvent1"); // 76 days ago + var bobClosedEvent1 = createVolunteeringEvent(bobClosed.getId(), now.minusDays(76), tenHours, "bobClosedEvent1"); // 76 days ago var clairClosedEvent1 = createVolunteeringEvent(clairClosed.getId(), now.minusDays(1), 0, "clairClosedEvent1"); // yesterday // List all events, sorted by event date and then by organization name @@ -353,10 +355,10 @@ void relationshipMustExist() { String timAuth = auth(tim.getWorkEmail(), MEMBER_ROLE); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); UUID randomId = UUID.randomUUID(); - VolunteeringEventDTO newEvent = new VolunteeringEventDTO(randomId, now, 10, "Notes"); + VolunteeringEventDTO newEvent = new VolunteeringEventDTO(randomId, now, tenHours, "Notes"); // Creating an event with a non-existent relationship should fail var e = assertThrows(HttpClientResponseException.class, () -> eventClient.create(timAuth, newEvent)); @@ -376,9 +378,9 @@ void eventDateMustBeSet() { String timAuth = auth(tim.getWorkEmail(), MEMBER_ROLE); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); - VolunteeringEventDTO newEvent = new VolunteeringEventDTO(relationship.getId(), null, 10, "Notes"); + VolunteeringEventDTO newEvent = new VolunteeringEventDTO(relationship.getId(), null, tenHours, "Notes"); // Creating an event with a null date should fail var e = assertThrows(HttpClientResponseException.class, () -> eventClient.create(timAuth, newEvent)); @@ -400,9 +402,9 @@ void hoursMustBeNonNegative() { String timAuth = auth(tim.getWorkEmail(), MEMBER_ROLE); VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); - VolunteeringEventDTO newEvent = new VolunteeringEventDTO(relationship.getId(), now, -1, "Notes"); + VolunteeringEventDTO newEvent = new VolunteeringEventDTO(relationship.getId(), now, -1.0, "Notes"); // Creating an event with negative hours should fail var e = assertThrows(HttpClientResponseException.class, () -> eventClient.create(timAuth, newEvent)); @@ -422,7 +424,7 @@ void hoursAreRequired() { VolunteeringOrganization organization = createDefaultVolunteeringOrganization(); VolunteeringRelationship relationship = createVolunteeringRelationship(tim.getId(), organization.getId(), now); - VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, 10, "Notes"); + VolunteeringEvent event = createVolunteeringEvent(relationship.getId(), now, tenHours, "Notes"); String postBody = """ { "relationshipId": "%s",