Skip to content

Commit

Permalink
chore: added expired as default
Browse files Browse the repository at this point in the history
Added expired categories as default, and marked them as expired on their names
  • Loading branch information
paulushcgcj committed Dec 2, 2024
1 parent 146523d commit b939b11
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public PaginatedResult<OpeningSearchResponseDto> openingSearch(
*/
@GetMapping("/categories")
public List<CodeDescriptionDto> getOpeningCategories(
@RequestParam(value = "includeExpired", required = false)
@RequestParam(value = "includeExpired", required = false, defaultValue = "true")
Boolean includeExpired) {
boolean addExpired = Boolean.TRUE.equals(includeExpired);
return openCategoryCodeService.findAllCategories(addExpired);
Expand All @@ -152,7 +152,7 @@ public List<OrgUnitEntity> getOpeningOrgUnits() {
*/
@GetMapping("/org-units-by-code")
public List<OrgUnitEntity> getOpeningOrgUnitsByCode(
@RequestParam(value = "orgUnitCodes", required = true)
@RequestParam(value = "orgUnitCodes")
String[] codes) {
return orgUnitService.findAllOrgUnitsByCode(Arrays.asList(codes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -38,4 +39,9 @@ public class OpenCategoryCodeEntity {

@Column(name = "UPDATE_TIMESTAMP", nullable = false)
private LocalDate updateTimestamp;

@Transient
public boolean isExpired() {
return expiryDate != null && LocalDate.now().isAfter(expiryDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Service;

/** This class contains methods to handle Opening Categories. */
/**
* This class contains methods to handle Opening Categories.
*/
@Slf4j
@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -38,7 +40,13 @@ public List<CodeDescriptionDto> findAllCategories(boolean includeExpired) {
);
return openCategoryCodes
.stream()
.map(entity -> new CodeDescriptionDto(entity.getCode(), entity.getDescription()))
.map(entity -> new CodeDescriptionDto(
entity.getCode(),
entity.isExpired()
? entity.getDescription() + " (Expired)"
: entity.getDescription()
)
)
.toList();
}
}

0 comments on commit b939b11

Please sign in to comment.