Skip to content

Commit

Permalink
Merge pull request #1185 from cardano-foundation/fix/cannot-search-dr…
Browse files Browse the repository at this point in the history
…ep-dev-test

fix: cannot search DRep
  • Loading branch information
Sotatek-DucPhung committed May 3, 2024
2 parents ab6c3a2 + 4148db3 commit 8c5b4c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class SearchResponse {
private PoolSearchResponse pool;
private boolean validPoolName;
private ScriptSearchResponse script;
private String dRep;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.cardanofoundation.explorer.api.model.response.search.ScriptSearchResponse;
import org.cardanofoundation.explorer.api.model.response.search.SearchResponse;
import org.cardanofoundation.explorer.api.model.response.search.TokenSearchResponse;
import org.cardanofoundation.explorer.api.repository.explorer.DrepInfoRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.BlockRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.MultiAssetRepository;
Expand All @@ -28,6 +29,7 @@
import org.cardanofoundation.explorer.api.service.SearchService;
import org.cardanofoundation.explorer.api.util.AddressUtils;
import org.cardanofoundation.explorer.common.entity.enumeration.ScriptType;
import org.cardanofoundation.explorer.common.entity.explorer.DRepInfo;
import org.cardanofoundation.explorer.common.entity.ledgersync.Block;
import org.cardanofoundation.explorer.common.entity.ledgersync.MultiAsset;
import org.cardanofoundation.explorer.common.entity.ledgersync.Script;
Expand All @@ -43,6 +45,7 @@ public class SearchServiceImpl implements SearchService {
private final PoolHashRepository poolHashRepository;
private final StakeAddressRepository stakeAddressRepository;
private final ScriptRepository scriptRepository;
private final DrepInfoRepository drepInfoRepository;

@Value("${application.network}")
private String network;
Expand All @@ -59,9 +62,15 @@ public SearchResponse search(String query) {
searchAddress(rawQuery, searchResponse);
searchPool(query, searchResponse);
searchScriptHash(query, searchResponse);
searchDRep(query, searchResponse);
return searchResponse;
}

private void searchDRep(String query, SearchResponse searchResponse) {
Optional<DRepInfo> dRepInfo = drepInfoRepository.findByDRepHashOrDRepId(query);
dRepInfo.ifPresent(repInfo -> searchResponse.setDRep(repInfo.getDrepId()));
}

private void searchEpoch(String query, SearchResponse searchResponse) {
try {
Integer epochNo = Integer.parseInt(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import org.cardanofoundation.explorer.api.model.response.pool.projection.PoolInfoProjection;
import org.cardanofoundation.explorer.api.repository.explorer.DrepInfoRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.BlockRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.MultiAssetRepository;
Expand All @@ -45,6 +46,7 @@ public class SearchServiceTest {
@Mock private MultiAssetRepository multiAssetRepository;
@Mock private PoolHashRepository poolHashRepository;
@Mock private StakeAddressRepository stakeAddressRepository;
@Mock private DrepInfoRepository drepInfoRepository;

@BeforeEach
void setUp() {
Expand Down

0 comments on commit 8c5b4c7

Please sign in to comment.