Skip to content

Commit

Permalink
Feature: get active events remotely in voting-app
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Czeladka committed Aug 23, 2023
1 parent 93aa0d3 commit bd98cf6
Showing 1 changed file with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.cardano.foundation.voting.client;

import io.vavr.control.Either;
import lombok.RequiredArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.cardano.foundation.voting.domain.CardanoNetwork;
import org.cardano.foundation.voting.domain.VotingEventType;
Expand Down Expand Up @@ -80,8 +81,24 @@ public Either<Problem, Optional<TransactionDetailsResponse>> getTransactionDetai
}
}

public Either<Problem, List<EventDetailsResponse>> findAllActiveEvents() {
return Either.right(List.of());
public Either<Problem, List<EventSummary>> findAllActiveEvents() {
var url = String.format("%s/api/reference/event", ledgerFollowerBaseUrl);

try {
return Either.right(Optional.ofNullable(restTemplate.getForObject(url, EventSummaryList.class))
.map(EventSummaryList::getEventSummaries).orElse(List.of()).stream().filter(EventSummary::active)
.toList());
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == NOT_FOUND) {
return Either.right(List.of());
}

return Either.left(Problem.builder()
.withTitle("REFERENCE_ERROR")
.withDetail("Unable to get event details from chain-tip follower service, reason:" + e.getMessage())
.withStatus(new HttpStatusAdapter(e.getStatusCode()))
.build());
}
}

public Either<Problem, Optional<EventDetailsResponse>> getEventDetails(String eventId) {
Expand Down Expand Up @@ -118,6 +135,25 @@ public Optional<ProposalDetailsResponse> findProposalByName(String name) {

}

public record EventSummary(String name,
boolean finished,
boolean notStarted,
boolean active) {

public boolean isEventInactive() {
return !active;
}

}

@AllArgsConstructor
@Getter
public class EventSummaryList {

private List<EventSummary> eventSummaries;

}

public record EventDetailsResponse(String id,
boolean finished,
boolean notStarted,
Expand Down

0 comments on commit bd98cf6

Please sign in to comment.