Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP:36804 - Filter related changes in API GET /partners/v3 #952

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,34 @@ public ResponseWrapperV2<PartnerDetailsV3Dto> getPartnerDetails(@PathVariable St

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetallpartners())")
@GetMapping(value = "/v3")
@Operation(summary = "Get all partner details", description = "This endpoint will fetch list of all the partner details")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@Operation(summary = "Get all partner details", description = "This endpoint will fetch a list of all the partner details")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))
})
public ResponseWrapperV2<PageResponseV2Dto<PartnerSummaryDto>> getAllPartners(
@RequestParam(value = "sortFieldName", required = false) String sortFieldName,
@RequestParam(value = "sortType", required = false) String sortType, // e.g. ASC or DESC
@RequestParam(value = "sortType", required = false) String sortType, // e.g., ASC or DESC
@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "8") int pageSize,
@RequestParam(value = "partnerId", required = false) String partnerId) {
@RequestParam(value = "partnerId", required = false) String partnerId,
@RequestParam(value = "partnerType", required = false) String partnerType,
@RequestParam(value = "isActive", required = false) Boolean isActive,
@RequestParam(value = "orgName", required = false) String orgName,
@RequestParam(value = "emailAddress", required = false) String emailAddress,
@RequestParam(value = "certificateUploadStatus", required = false) String certificateUploadStatus,
@RequestParam(value = "policyGroupName", required = false) String policyGroupName
) {
FilterDto filterDto = new FilterDto();
filterDto.setPartnerId(partnerId);
filterDto.setPartnerTypeCode(partnerType);
filterDto.setOrganizationName(orgName);
filterDto.setPolicyGroupName(policyGroupName);
filterDto.setCertificateUploadStatus(certificateUploadStatus);
filterDto.setEmailAddress(emailAddress);
filterDto.setIsActive(isActive);
return partnerManagementService.getAllPartners(sortFieldName, sortType, pageNo, pageSize, filterDto);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
@Data
public class FilterDto {
private String partnerId;
private String partnerTypeCode;
private String organizationName;
private String policyGroupName;
private String certificateUploadStatus;
private String emailAddress;
private Boolean isActive;
}
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,10 @@ public ResponseWrapperV2<PageResponseV2Dto<PartnerSummaryDto>> getAllPartners(St
}

Page<PartnerSummaryEntity> page = partnerSummaryRepository.
getSummaryOfAllPartners(filterDto.getPartnerId(), pageable);
getSummaryOfAllPartners(filterDto.getPartnerId(),filterDto.getPartnerTypeCode(),
filterDto.getOrganizationName(), filterDto.getPolicyGroupName(),
filterDto.getCertificateUploadStatus(), filterDto.getEmailAddress(),
filterDto.getIsActive(), pageable);
if (Objects.nonNull(page) && !page.getContent().isEmpty()) {
List<PartnerSummaryDto> partnerSummaryDtoList = MapperUtils.mapAll(page.getContent(), PartnerSummaryDto.class);
pageResponseV2Dto.setPageNo(pageNo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,31 @@
@Repository("PartnerSummaryRepository")
public interface PartnerSummaryRepository extends BaseRepository<PartnerSummaryEntity, String> {

@Query("SELECT new PartnerSummaryEntity("
+ "p.id, p.partnerTypeCode, p.name, p.policyGroup.id, pg.name, "
+ "p.emailId, CASE WHEN p.certificateAlias IS NULL THEN 'not_uploaded' ELSE 'uploaded' END, "
+ "p.approvalStatus, p.isActive, p.crDtimes) "
+ "FROM PartnerV3 p "
+ "LEFT JOIN p.policyGroup pg "
+ "WHERE (:partnerId is null or p.id = :partnerId)"
@Query(value = "SELECT new PartnerSummaryEntity(" +
"p.id, p.partnerTypeCode, p.name, p.policyGroup.id, pg.name, " +
"p.emailId, CASE WHEN p.certificateAlias IS NULL THEN 'not_uploaded' ELSE 'uploaded' END, " +
"p.approvalStatus, p.isActive, p.crDtimes) " +
"FROM PartnerV3 p " +
"LEFT JOIN p.policyGroup pg " +
"WHERE (:partnerId IS NULL OR p.id LIKE %:partnerId%) " +
"AND (:partnerTypeCode IS NULL OR p.partnerTypeCode LIKE %:partnerTypeCode%) " +
"AND (:organizationName IS NULL OR p.name LIKE %:organizationName%) " +
"AND (:policyGroupName IS NULL OR pg.name LIKE %:policyGroupName%) " +
"AND (:certificateUploadStatus IS NULL OR " +
"(:certificateUploadStatus = 'not_uploaded' AND p.certificateAlias IS NULL) " +
"OR (:certificateUploadStatus = 'uploaded' AND p.certificateAlias IS NOT NULL)) " +
"AND (:emailAddress IS NULL OR p.emailId LIKE %:emailAddress%) " +
"AND (:isActive IS NULL OR p.isActive = :isActive)"
)
Page<PartnerSummaryEntity> getSummaryOfAllPartners(@Param("partnerId") String partnerId, Pageable pageable);
Page<PartnerSummaryEntity> getSummaryOfAllPartners(
@Param("partnerId") String partnerId,
@Param("partnerTypeCode") String partnerTypeCode,
@Param("organizationName") String organizationName,
@Param("policyGroupName") String policyGroupName,
@Param("certificateUploadStatus") String certificateUploadStatus,
@Param("emailAddress") String emailAddress,
@Param("isActive") Boolean isActive,
Pageable pageable
);

}
Loading