Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat: allow the requestor to specify the leagueId
Browse files Browse the repository at this point in the history
This commit updates the service to request the competitions for a
specific league (maps to year).
  • Loading branch information
Jamie McDonald committed Apr 13, 2021
1 parent 8e71e6d commit 7b0ca73
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -30,8 +30,10 @@ To run the service in a kubernetes cluster (with hot reloading):
### Sample Requests
To make a request for all competitions:
```shell script
curl -X GET -H "Content-Type: application/json" localhost:8080/calendar
curl -X GET -H "Content-Type: application/json" localhost:8080/calendar?leagueId=388
```

Note that the leagueId can be obtained by inspecting the network requests on the [IFSC Competitions page](https://www.ifsc-climbing.org/index.php/world-competition).

## License
This project uses the following license: [MIT](LICENSE.md).
Expand Up @@ -5,6 +5,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;
Expand All @@ -18,8 +19,8 @@ public class CalendarController {
private final CalendarService calendarService;

@GetMapping(produces = "text/calendar")
public Mono<ResponseEntity<String>> getCalendar() {
return calendarService.createCalendar().map(ResponseEntity::ok);
public Mono<ResponseEntity<String>> getCalendar(@RequestParam("leagueId") String leagueId) {
return calendarService.createCalendar(leagueId).map(ResponseEntity::ok);
}

}
Expand Up @@ -3,5 +3,5 @@
import reactor.core.publisher.Mono;

public interface CalendarService {
Mono<String> createCalendar();
Mono<String> createCalendar(String leagueId);
}
Expand Up @@ -25,8 +25,8 @@ public class InternetCalendarService implements CalendarService {
private final CompetitionsService competitionsService;

@Override
public Mono<String> createCalendar() {
return competitionsService.findAll()
public Mono<String> createCalendar(String leagueId) {
return competitionsService.findAll(leagueId)
.flatMap(competitions -> Mono.just(competitions.getEvents()))
.flatMap(this::mapEventsToCalendar)
.doFinally(calendar -> log.info("Created calendar for all categories"));
Expand Down
Expand Up @@ -5,5 +5,5 @@
import reactor.core.publisher.Mono;

public interface CompetitionsService {
Mono<CompetitionList> findAll();
Mono<CompetitionList> findAll(String leagueId);
}
Expand Up @@ -25,9 +25,12 @@ public IfscCompetitionsService(IfscCompetitionsConfig config) {
}

@Override
public Mono<CompetitionList> findAll() {
public Mono<CompetitionList> findAll(String leagueId) {
return webClient.get()
.uri("/results-api.php?api=season_leagues_calendar&league=388")
.uri(uriBuilder -> uriBuilder.path("/results-api.php")
.queryParam("api", "season_leagues_calendar")
.queryParam("league", leagueId)
.build())
.retrieve()
.bodyToMono(CompetitionList.class);
}
Expand Down
Expand Up @@ -43,10 +43,10 @@ void afterEach() {
void shouldExecuteService() {
String expectedValue = "ICALENDAR_VALUE";

when(calendarService.createCalendar()).thenReturn(Mono.just(expectedValue));
when(calendarService.createCalendar("388")).thenReturn(Mono.just(expectedValue));

FluxExchangeResult<String> exchangeResult = client.get()
.uri("/calendar")
.uri("/calendar?leagueId=388")
.exchange()
.expectHeader()
.contentType("text/calendar;charset=UTF-8")
Expand All @@ -56,6 +56,6 @@ void shouldExecuteService() {
.assertNext(result -> assertThat(result).isEqualTo(expectedValue))
.verifyComplete();

verify(calendarService).createCalendar();
verify(calendarService).createCalendar("388");
}
}
Expand Up @@ -54,7 +54,7 @@ void shouldExecuteSuccessfully(MockWebServerWrapper wrapper) throws IOException
.setBody(Files.readString(Paths.get("src/test/resources/data/ifscResponseInput.json"))));

client.get()
.uri("/calendar")
.uri("/calendar?leagueId=388")
.exchange()
.expectHeader()
.contentType("text/calendar;charset=UTF-8")
Expand Down
Expand Up @@ -56,9 +56,9 @@ void shouldCreateCalendar() {
Competition cliffhanger = new Competition("Cliffhanger", epoch, epoch);
Competition olympics = new Competition("Olympics", epochPlusOne, epochPlusOne);

when(competitionsService.findAll()).thenReturn(Mono.just(new CompetitionList(asList(cliffhanger, olympics))));
when(competitionsService.findAll("388")).thenReturn(Mono.just(new CompetitionList(asList(cliffhanger, olympics))));

Mono<String> calendarMono = calendarService.createCalendar();
Mono<String> calendarMono = calendarService.createCalendar("388");

StepVerifier.create(calendarMono)
.assertNext(calendarString -> {
Expand Down
Expand Up @@ -56,7 +56,7 @@ void shouldReturnCompetitions() throws Exception {
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.setBody(Files.readString(Paths.get("src/test/resources/data/ifscResponseInput.json"))));

StepVerifier.create(service.findAll())
StepVerifier.create(service.findAll("388"))
.assertNext(competitionList -> {
assertThat(competitionList.getEvents()).hasSize(3);

Expand Down

0 comments on commit 7b0ca73

Please sign in to comment.