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 1 commit
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 @@ -16,41 +16,7 @@ public class MatchDataProcessor implements ItemProcessor<MatchInput, Match> {

@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();

} else {
secondInningsTeam = matchInput.getToss_winner();
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 matchInput.toMatch();
}

}
147 changes: 43 additions & 104 deletions src/main/java/io/javabrains/ipldashboard/data/MatchInput.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package io.javabrains.ipldashboard.data;

import io.javabrains.ipldashboard.model.Match;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class MatchInput {
private String id;
private String city;
Expand All @@ -18,110 +30,37 @@ 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;
}


public Match toMatch() {
String firstInningsTeam, secondInningsTeam;

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

} else {
secondInningsTeam = this.getToss_winner();
firstInningsTeam = this.getToss_winner().equals(this.getTeam1())
? this.getTeam2() : this.getTeam1();
}

return Match.builder()
.id(Long.parseLong(this.getId()))
.city(this.getCity())
.date(LocalDate.parse(this.getDate()))
.playerOfMatch(this.getPlayer_of_match())
.venue(this.getVenue())
.team1(firstInningsTeam)
.team2(secondInningsTeam)
.tossWinner(this.getToss_winner())
.tossDecision(this.getToss_decision())
.matchWinner(this.getWinner())
.result(this.getWinner())
.result(this.getResult())
.resultMargin(this.getResult_margin())
.umpire1(this.getUmpire1())
.umpire2(this.getUmpire2())
.build();
}
}
97 changes: 9 additions & 88 deletions src/main/java/io/javabrains/ipldashboard/model/Match.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package io.javabrains.ipldashboard.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Match {

@Id
Expand All @@ -23,92 +32,4 @@ public class Match {
private String resultMargin;
private String umpire1;
private String umpire2;

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public String getPlayerOfMatch() {
return playerOfMatch;
}
public void setPlayerOfMatch(String playerOfMatch) {
this.playerOfMatch = playerOfMatch;
}
public String getVenue() {
return venue;
}
public void setVenue(String venue) {
this.venue = 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 getTossWinner() {
return tossWinner;
}
public void setTossWinner(String tossWinner) {
this.tossWinner = tossWinner;
}
public String getTossDecision() {
return tossDecision;
}
public void setTossDecision(String tossDecision) {
this.tossDecision = tossDecision;
}
public String getMatchWinner() {
return matchWinner;
}
public void setMatchWinner(String matchWinner) {
this.matchWinner = matchWinner;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getResultMargin() {
return resultMargin;
}
public void setResultMargin(String resultMargin) {
this.resultMargin = resultMargin;
}
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