generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: opening search APIs for OrgUnits and Categories (#364)
- Loading branch information
Ricardo Campos
authored
Sep 4, 2024
1 parent
bc52ddc
commit 6ffc7e0
Showing
14 changed files
with
822 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/ca/bc/gov/restapi/results/oracle/entity/OpenCategoryCodeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ca.bc.gov.restapi.results.oracle.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDate; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** This class represents an Opening Category in the database. */ | ||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "OPEN_CATEGORY_CODE") | ||
public class OpenCategoryCodeEntity { | ||
|
||
@Id | ||
@Column(name = "OPEN_CATEGORY_CODE") | ||
private String code; | ||
|
||
@Column(name = "DESCRIPTION", length = 120, nullable = false) | ||
private String description; | ||
|
||
@Column(name = "EFFECTIVE_DATE", nullable = false) | ||
private LocalDate effectiveDate; | ||
|
||
@Column(name = "EXPIRY_DATE", nullable = false) | ||
private LocalDate expiryDate; | ||
|
||
@Column(name = "UPDATE_TIMESTAMP", nullable = false) | ||
private LocalDate updateTimestamp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpenCategoryCodeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ca.bc.gov.restapi.results.oracle.repository; | ||
|
||
import ca.bc.gov.restapi.results.oracle.entity.OpenCategoryCodeEntity; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** This interface provides methods to get, save, and manage data in the database. */ | ||
public interface OpenCategoryCodeRepository extends JpaRepository<OpenCategoryCodeEntity, String> { | ||
|
||
List<OpenCategoryCodeEntity> findAllByExpiryDateAfter(LocalDate now); | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ca.bc.gov.restapi.results.oracle.repository; | ||
|
||
import ca.bc.gov.restapi.results.oracle.entity.OrgUnitEntity; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** This interface provides methods to get, save, and manage org unit data in the database. */ | ||
public interface OrgUnitRepository extends JpaRepository<OrgUnitEntity, Long> { | ||
|
||
List<OrgUnitEntity> findAllByExpiryDateAfter(LocalDate now); | ||
|
||
List<OrgUnitEntity> findAllByOrgUnitCodeIn(List<String> orgUnitCodes); | ||
} |
39 changes: 39 additions & 0 deletions
39
backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ca.bc.gov.restapi.results.oracle.service; | ||
|
||
import ca.bc.gov.restapi.results.oracle.entity.OpenCategoryCodeEntity; | ||
import ca.bc.gov.restapi.results.oracle.repository.OpenCategoryCodeRepository; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** This class contains methods to handle Opening Categories. */ | ||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class OpenCategoryCodeService { | ||
|
||
private final OpenCategoryCodeRepository openCategoryCodeRepository; | ||
|
||
/** | ||
* Find all Opening categories. Option to include expired ones. | ||
* | ||
* @param includeExpired True to include expired, false otherwise. | ||
* @return List of {@link OpenCategoryCodeEntity} with found categories. | ||
*/ | ||
public List<OpenCategoryCodeEntity> findAllCategories(boolean includeExpired) { | ||
log.info("Getting all open category codes. Include expired: {}", includeExpired); | ||
|
||
if (includeExpired) { | ||
List<OpenCategoryCodeEntity> openCategoryCodes = openCategoryCodeRepository.findAll(); | ||
log.info("Found {} open category codes (including expired)", openCategoryCodes.size()); | ||
return openCategoryCodes; | ||
} | ||
|
||
List<OpenCategoryCodeEntity> openCategoryCodes = | ||
openCategoryCodeRepository.findAllByExpiryDateAfter(LocalDate.now()); | ||
log.info("Found {} open category codes (excluding expired)", openCategoryCodes.size()); | ||
return openCategoryCodes; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OrgUnitService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ca.bc.gov.restapi.results.oracle.service; | ||
|
||
import ca.bc.gov.restapi.results.oracle.entity.OrgUnitEntity; | ||
import ca.bc.gov.restapi.results.oracle.repository.OrgUnitRepository; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** This class contains methods to handle Org Units. */ | ||
@Slf4j | ||
@Service | ||
@AllArgsConstructor | ||
public class OrgUnitService { | ||
|
||
private final OrgUnitRepository orgUnitRepository; | ||
|
||
/** | ||
* Find all Org Units. Option to include expired ones. | ||
* | ||
* @param includeExpired True to include expired, false otherwise. | ||
* @return List of {@link OrgUnitEntity} with found categories. | ||
*/ | ||
public List<OrgUnitEntity> findAllOrgUnits(boolean includeExpired) { | ||
log.info("Getting all org units. Include expired: {}", includeExpired); | ||
|
||
if (includeExpired) { | ||
List<OrgUnitEntity> orgUnits = orgUnitRepository.findAll(); | ||
log.info("Found {} org units (including expired)", orgUnits.size()); | ||
return orgUnits; | ||
} | ||
|
||
List<OrgUnitEntity> orgUnits = orgUnitRepository.findAllByExpiryDateAfter(LocalDate.now()); | ||
log.info("Found {} org units (excluding expired)", orgUnits.size()); | ||
return orgUnits; | ||
} | ||
|
||
/** | ||
* Find all Org Units by code. | ||
* | ||
* @param orgUnitCodes Org Unit codes to search for. | ||
* @return List of {@link OrgUnitEntity} with found categories. | ||
*/ | ||
public List<OrgUnitEntity> findAllOrgUnitsByCode(List<String> orgUnitCodes) { | ||
log.info("Getting all org units by codes: {}", orgUnitCodes); | ||
|
||
List<OrgUnitEntity> orgUnits = orgUnitRepository.findAllByOrgUnitCodeIn(orgUnitCodes); | ||
log.info("Found {} org units by codes", orgUnits.size()); | ||
return orgUnits; | ||
} | ||
} |
Oops, something went wrong.