Skip to content

Commit

Permalink
chore: merge dev-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-ThinhVu committed Mar 27, 2024
1 parent 7934d90 commit 3b32884
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
Expand Up @@ -34,7 +34,7 @@
@RequestMapping("/api/v1/dreps")
@RequiredArgsConstructor
@Validated
@Tag(name = "drep", description = "The delegated representatives APIs")
@Tag(name = "dRep", description = "The delegated representatives APIs")
public class DRepController {

private final DRepService dRepService;
Expand All @@ -43,7 +43,7 @@ public class DRepController {
@LogMessage
@Operation(
summary = "Get list of DRep certificate history",
tags = {"drep"})
tags = {"dRep"})
public ResponseEntity<BaseFilterResponse<DRepCertificateHistoryResponse>>
getTxDRepCertificatesHistory(
@PathVariable @Parameter(description = "The DRep id or DRep hash")
Expand All @@ -63,21 +63,24 @@ public class DRepController {
@LogMessage
@Operation(
summary = "Get chart of DRep vote on Governance Action",
tags = {"drep"})
tags = {"dRep"})
public ResponseEntity<VotingProcedureChartResponse> getChartOfDRepVotesOnGovernanceAction(
@PathVariable @Parameter(description = "dRepHash") String dRepHash,
@RequestParam(value = "govActionType") GovActionType govActionType) {
@PathVariable @Parameter(description = "The DRep hash") String dRepHash,
@RequestParam(value = "govActionType")
@Parameter(description = "The type of Governance Action")
GovActionType govActionType) {
return ResponseEntity.ok(dRepService.getVoteProcedureChart(dRepHash, govActionType));
}

@GetMapping("/{dRepHashOrDRepId}/drep-details")
@LogMessage
@Operation(
summary = "Get details of Delegated Representative (DRep)",
tags = {"drep"})
tags = {"dRep"})
public ResponseEntity<DRepDetailsResponse> getDRepDetails(
@Valid @PathVariable @Parameter(description = "dRepHashOrDRepId") String dRepHashOrDRepId) {
return ResponseEntity.ok(dRepService.getDrepDetails(dRepHashOrDRepId));
@Valid @PathVariable @Parameter(description = "The DRep id or DRep hash")
String dRepHashOrDRepId) {
return ResponseEntity.ok(dRepService.getDRepDetails(dRepHashOrDRepId));
}

@GetMapping("/{dRepHashOrDRepId}/get-delegation")
Expand Down
Expand Up @@ -26,6 +26,7 @@ public class DRepDetailsResponse {
private String drepHash;
private String drepId;
private String anchorUrl;
private String anchorHash;
private Integer delegators;
private BigInteger activeVoteStake;
private BigInteger liveStake;
Expand Down
Expand Up @@ -12,5 +12,5 @@ public interface DrepInfoRepository extends JpaRepository<DRepInfo, Long> {
value =
" select dri from DRepInfo dri"
+ " where dri.drepHash = :dRepHashOrDRepId or dri.drepId = :dRepHashOrDRepId")
DRepInfo findByDrepHashOrDrepId(@Param("dRepHashOrDRepId") String dRepHashOrDRepId);
DRepInfo findByDRepHashOrDRepId(@Param("dRepHashOrDRepId") String dRepHashOrDRepId);
}
Expand Up @@ -16,7 +16,7 @@ BaseFilterResponse<DRepCertificateHistoryResponse> getTxDRepCertificateHistory(
VotingProcedureChartResponse getVoteProcedureChart(
String drepHashOrDrepId, GovActionType govActionType);

DRepDetailsResponse getDrepDetails(String drepHashOrDrepId);
DRepDetailsResponse getDRepDetails(String drepHashOrDrepId);

BaseFilterResponse<DRepDelegatorsResponse> getDRepDelegators(
String drepHashOrDrepId, Pageable pageable);
Expand Down
Expand Up @@ -129,8 +129,8 @@ public VotingProcedureChartResponse getVoteProcedureChart(
}

@Override
public DRepDetailsResponse getDrepDetails(String dRepHashOrDRepId) {
return dRepMapper.fromDrepInfo(drepInfoRepository.findByDrepHashOrDrepId(dRepHashOrDRepId));
public DRepDetailsResponse getDRepDetails(String dRepHashOrDRepId) {
return dRepMapper.fromDrepInfo(drepInfoRepository.findByDRepHashOrDRepId(dRepHashOrDRepId));
}

@Override
Expand Down
Expand Up @@ -146,7 +146,7 @@ void testGetDrepDetails() throws Exception {
.votingParticipation(BigInteger.TEN.add(BigInteger.TWO))
.build();

when(dRepService.getDrepDetails(drepHash)).thenReturn(dRepDetailsResponse);
when(dRepService.getDRepDetails(drepHash)).thenReturn(dRepDetailsResponse);
mockMvc
.perform(
get("/api/v1/dreps/{drepHashOrDrepId}/drep-details", drepHash)
Expand Down Expand Up @@ -182,4 +182,22 @@ void testGetChartDRepVoteOnGovernanceAction() throws Exception {
.string(containsString("43a0e2e2d6bf1d0c48b0eb1744fb853407c6b94f2de79f0508c5962e")))
.andExpect(jsonPath("$.numberOfYesVote").value(10L));
}

@Test
void testGetDetailsOfDRep() throws Exception {
String dRepHash = "43a0e2e2d6bf1d0c48b0eb1744fb853407c6b94f2de79f0508c5962e";
DRepDetailsResponse dRepDetailsResponse =
DRepDetailsResponse.builder().drepHash(dRepHash).drepId("dRepId").delegators(100).build();
when(dRepService.getDRepDetails(dRepHash)).thenReturn(dRepDetailsResponse);
mockMvc
.perform(
get("/api/v1/dreps/{dRepHashOrDRepId}/drep-details", dRepHash)
.param("dRepHashOrDRepId", dRepHash)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(
content()
.string(containsString("43a0e2e2d6bf1d0c48b0eb1744fb853407c6b94f2de79f0508c5962e")))
.andExpect(jsonPath("$.delegators").value(100));
}
}
Expand Up @@ -90,9 +90,9 @@ public void testGetDRepDetail() {
.delegators(10)
.activeVoteStake(BigInteger.TWO)
.build();
when(drepInfoRepository.findByDrepHashOrDrepId(drepHash)).thenReturn(dRepInfo);
when(drepInfoRepository.findByDRepHashOrDRepId(drepHash)).thenReturn(dRepInfo);

var actual = dRepCertificateService.getDrepDetails(drepHash);
var actual = dRepCertificateService.getDRepDetails(drepHash);

Assertions.assertEquals(dRepInfo.getDrepId(), actual.getDrepId());
Assertions.assertEquals(10, actual.getDelegators());
Expand Down

0 comments on commit 3b32884

Please sign in to comment.