Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lombok dependency #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand All @@ -51,13 +57,22 @@
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDate;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -16,16 +17,11 @@

@RestController
@CrossOrigin
@RequiredArgsConstructor
public class TeamController {

private TeamRepository teamRepository;
private MatchRepository matchRepository;

public TeamController(TeamRepository teamRepository, MatchRepository matchRepository) {
this.teamRepository = teamRepository;
this.matchRepository = matchRepository;
}

private final TeamRepository teamRepository;
private final MatchRepository matchRepository;

@GetMapping("/team")
public Iterable<Team> getAllTeam() {
Expand All @@ -35,9 +31,7 @@ public Iterable<Team> getAllTeam() {
@GetMapping("/team/{teamName}")
public Team getTeam(@PathVariable String teamName) {
Team team = this.teamRepository.findByTeamName(teamName);
team.setMatches(matchRepository.findLatestMatchesbyTeam(teamName,4));

return team;
return team.toBuilder().matches(matchRepository.findLatestMatchesbyTeam(teamName,4)).build();
}

@GetMapping("/team/{teamName}/matches")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import io.javabrains.ipldashboard.model.Team;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
package io.javabrains.ipldashboard.data;

import java.time.LocalDate;
import java.time.LocalDateTime;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.javabrains.ipldashboard.model.Match;
import org.springframework.batch.item.ItemProcessor;

import io.javabrains.ipldashboard.model.Match;
import java.time.LocalDate;

public class MatchDataProcessor implements ItemProcessor<MatchInput, Match> {

private static final Logger log = LoggerFactory.getLogger(MatchDataProcessor.class);

@Override
public Match process(final MatchInput matchInput) throws Exception {

Match match = new Match();
match.setId(Long.parseLong(matchInput.getId()));
match.setCity(matchInput.getCity());

match.setDate(LocalDate.parse(matchInput.getDate()));

match.setPlayerOfMatch(matchInput.getPlayer_of_match());
match.setVenue(matchInput.getVenue());

// Set Team 1 and Team 2 depending on the innings order
String firstInningsTeam, secondInningsTeam;

if ("bat".equals(matchInput.getToss_decision())) {
firstInningsTeam = matchInput.getToss_winner();
secondInningsTeam = matchInput.getToss_winner().equals(matchInput.getTeam1())
? matchInput.getTeam2() : matchInput.getTeam1();
secondInningsTeam = matchInput.getToss_winner().equals(matchInput.getTeam1())
? matchInput.getTeam2() : matchInput.getTeam1();

} else {
secondInningsTeam = matchInput.getToss_winner();
firstInningsTeam = matchInput.getToss_winner().equals(matchInput.getTeam1())
? matchInput.getTeam2() : matchInput.getTeam1();
firstInningsTeam = matchInput.getToss_winner().equals(matchInput.getTeam1())
? matchInput.getTeam2() : matchInput.getTeam1();
}
match.setTeam1(firstInningsTeam);
match.setTeam2(secondInningsTeam);

match.setTossWinner(matchInput.getToss_winner());
match.setTossDecision(matchInput.getToss_decision());
match.setMatchWinner(matchInput.getWinner());
match.setResult(matchInput.getResult());
match.setResultMargin(matchInput.getResult_margin());
match.setUmpire1(matchInput.getUmpire1());
match.setUmpire2(matchInput.getUmpire2());

return match;

return Match.builder()
.id(Long.parseLong(matchInput.getId()))
.city(matchInput.getCity())
.date(LocalDate.parse(matchInput.getDate()))
.playerOfMatch(matchInput.getPlayer_of_match())
.venue(matchInput.getVenue())
.team1(firstInningsTeam)
.team2(secondInningsTeam)
.tossWinner(matchInput.getToss_winner())
.tossDecision(matchInput.getToss_decision())
.matchWinner(matchInput.getWinner())
.result(matchInput.getWinner())
.result(matchInput.getResult())
.resultMargin(matchInput.getResult_margin())
.umpire1(matchInput.getUmpire1())
.umpire2(matchInput.getUmpire2())
.build();

}

}
114 changes: 9 additions & 105 deletions src/main/java/io/javabrains/ipldashboard/data/MatchInput.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package io.javabrains.ipldashboard.data;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class MatchInput {
private String id;
private String city;
Expand All @@ -18,110 +27,5 @@ public class MatchInput {
private String method;
private String umpire1;
private String umpire2;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getPlayer_of_match() {
return player_of_match;
}
public void setPlayer_of_match(String player_of_match) {
this.player_of_match = player_of_match;
}
public String getVenue() {
return venue;
}
public void setVenue(String venue) {
this.venue = venue;
}
public String getNeutral_venue() {
return neutral_venue;
}
public void setNeutral_venue(String neutral_venue) {
this.neutral_venue = neutral_venue;
}
public String getTeam1() {
return team1;
}
public void setTeam1(String team1) {
this.team1 = team1;
}
public String getTeam2() {
return team2;
}
public void setTeam2(String team2) {
this.team2 = team2;
}
public String getToss_winner() {
return toss_winner;
}
public void setToss_winner(String toss_winner) {
this.toss_winner = toss_winner;
}
public String getToss_decision() {
return toss_decision;
}
public void setToss_decision(String toss_decision) {
this.toss_decision = toss_decision;
}
public String getWinner() {
return winner;
}
public void setWinner(String winner) {
this.winner = winner;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getResult_margin() {
return result_margin;
}
public void setResult_margin(String result_margin) {
this.result_margin = result_margin;
}
public String getEliminator() {
return eliminator;
}
public void setEliminator(String eliminator) {
this.eliminator = eliminator;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getUmpire1() {
return umpire1;
}
public void setUmpire1(String umpire1) {
this.umpire1 = umpire1;
}
public String getUmpire2() {
return umpire2;
}
public void setUmpire2(String umpire2) {
this.umpire2 = umpire2;
}



}
Loading