Skip to content

Commit

Permalink
chore: final GeeCon version
Browse files Browse the repository at this point in the history
Signed-off-by: Maximillian Arruda <[email protected]>
  • Loading branch information
Maximillian Arruda authored and Maximillian Arruda committed Oct 23, 2023
1 parent 48baa2c commit 0261e7c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.org.soujava.coffewithjava.jnopo;

import io.opentelemetry.instrumentation.annotations.WithSpan;
import jakarta.data.repository.PageableRepository;
import jakarta.data.repository.Param;
import jakarta.data.repository.Query;
Expand All @@ -13,6 +12,7 @@ public interface Playoffs extends PageableRepository<GameMatch,String> {
List<GameMatch> findByWinnerNameLike(String name);

@Query("select * from GameMatch where tied=@tied")
@WithSpan
List<GameMatch> listTiedPlayoffs(@Param("tied") boolean tied);

List<GameMatch> findByLoserNameLike(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import org.eclipse.jnosql.mapping.DatabaseType;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

@Path("/playoffs")
@Consumes({MediaType.APPLICATION_JSON})
Expand All @@ -26,14 +27,37 @@ public List<GameMatch> tiedPlayoffs() {
}

@GET
@Path("/winners")
@WithSpan
public List<GameMatch> winners(
@QueryParam("winner") String winnerName,
@QueryParam("loser") String loserName
public Set<String> getWinners(
@QueryParam("name") String name
) {
if (winnerName != null)
return playoffs.findByWinnerNameLike(winnerName);
return playoffs.findAll().toList();
if (name != null)
return playoffs.findByWinnerNameLike(name)
.stream()
.map(g -> g.winner().name())
.collect(Collectors.toSet());
return playoffs.listTiedPlayoffs(false)
.stream()
.map(g -> g.winner().name())
.collect(Collectors.toSet());
}

@GET
@Path("/losers")
@WithSpan
public Set<String> getLosers(
@QueryParam("name") String name
) {
if (name != null)
return playoffs.findByLoserNameLike(name)
.stream()
.map(g -> g.loser().name())
.collect(Collectors.toSet());
return playoffs.listTiedPlayoffs(false)
.stream()
.map(g -> g.loser().name())
.collect(Collectors.toSet());
}

}

0 comments on commit 0261e7c

Please sign in to comment.