Skip to content

Commit

Permalink
add validLastUpdated field (#230)
Browse files Browse the repository at this point in the history
* initial

* amend tests

* rm
  • Loading branch information
john-tco authored Mar 6, 2024
1 parent bbd1123 commit 37e589f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public class GetGrantAdvertPublishingInformationResponseDTO {

private Instant lastUpdated;

private Instant created;

private boolean validLastUpdated;

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public class GrantAdvert extends BaseEntity {
@Column(name = "response", columnDefinition = "json")
private GrantAdvertResponse response;

/**
* The "lastUpdated" field has historically not being set correctly (it's not being updated with the advert).
* A recent PR has fixed this, see: https://github.com/cabinetoffice/gap-find-admin-backend/pull/216
* Advert rows created prior to the PR above have an invalid lastUpdated.
* Going forward, this field (validLastUpdated) needs to populate with "true" when adverts are created or updated.
* This field is used by the front-end to conditionally render the lastUpdated field (only when it's valid).
*/
@Column(name="valid_last_updated", columnDefinition = "boolean default false")
private boolean validLastUpdated;

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class GrantAdvertService {

private final FeatureFlagsConfigurationProperties featureFlagsProperties;

public GrantAdvert save(GrantAdvert advert) {
public GrantAdvert save(GrantAdvert advert) {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Optional.ofNullable(auth)
.ifPresentOrElse(authentication -> {
Expand All @@ -92,6 +92,8 @@ public GrantAdvert save(GrantAdvert advert) {

advert.getScheme().setLastUpdated(updatedAt);
advert.getScheme().setLastUpdatedBy(adminSession.getGrantAdminId());

advert.setValidLastUpdated(true);
}, () -> log.warn("Admin session was null. Update must have been performed by a lambda."));

return grantAdvertRepository.save(advert);
Expand All @@ -106,7 +108,7 @@ public GrantAdvert create(Integer grantSchemeId, Integer grantAdminId, String na
if (!doesAdvertExist) {
final GrantAdvert grantAdvert = GrantAdvert.builder().grantAdvertName(name).scheme(scheme)
.createdBy(grantAdmin).created(Instant.now()).lastUpdatedBy(grantAdmin).lastUpdated(Instant.now())
.status(GrantAdvertStatus.DRAFT).version(version).build();
.status(GrantAdvertStatus.DRAFT).version(version).validLastUpdated(true).build();
return save(grantAdvert);
}
final GrantAdvert existingAdvert = grantAdvertRepository.findBySchemeId(grantSchemeId).get();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE grant_advert ADD valid_last_updated boolean default false
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ class getAdvertPublishInformation {

private final Instant lastPublishedDate = dateTimeInput;

private final Instant createdDate = Instant.parse("2021-01-01T00:00:00.00Z");

private final Instant unpublishedDate = dateTimeInput;

@Test
Expand All @@ -466,6 +468,8 @@ void getAdvertPublishingInformation_GrantAdvertPublishingInformationReturned() t
.contentfulSlug(contentfulSlug).unpublishedDate(unpublishedDate)
.firstPublishedDate(firstPublishedDate).lastPublishedDate(lastPublishedDate)
.lastUpdatedByEmail("an-email")
.created(createdDate)
.validLastUpdated(true)
.lastUpdated(lastPublishedDate)
.closingDate(closingDate).openingDate(openingDate).build();

Expand Down

0 comments on commit 37e589f

Please sign in to comment.