teams and matches
This commit is contained in:
parent
b1867425cf
commit
c84273b5c3
12
Back/pom.xml
12
Back/pom.xml
@ -24,13 +24,6 @@
|
|||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
@ -51,6 +44,11 @@
|
|||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package com.resultprediction.polishekstraklasa.Predictions;
|
package com.resultprediction.polishekstraklasa.Predictions;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@ -11,7 +16,6 @@ import java.util.Collections;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@RestController
|
|
||||||
public class PredictionsApplication {
|
public class PredictionsApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.resultprediction.polishekstraklasa.Predictions.controllers;
|
||||||
|
|
||||||
|
import com.resultprediction.polishekstraklasa.Predictions.model.match.Match;
|
||||||
|
import com.resultprediction.polishekstraklasa.Predictions.model.match.MatchRepository;
|
||||||
|
import com.resultprediction.polishekstraklasa.Predictions.model.team.Team;
|
||||||
|
import com.resultprediction.polishekstraklasa.Predictions.model.team.TeamRepository;
|
||||||
|
import com.resultprediction.polishekstraklasa.Predictions.model.teamsMatchStatistics.TeamsMatchStatisticsRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/matches")
|
||||||
|
public class MatchController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MatchRepository matchRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TeamRepository teamRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TeamsMatchStatisticsRepository teamsMatchStatisticsRepository;
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
public String create(@RequestBody List<Match> matches) {
|
||||||
|
for (Match match : matches){
|
||||||
|
Optional<Team> team1 = teamRepository.findByName(match.getTeamsMatchStatistics1().getTeam().getName());
|
||||||
|
if (team1.isPresent())
|
||||||
|
match.getTeamsMatchStatistics1().setTeam(team1.get());
|
||||||
|
else match.getTeamsMatchStatistics1().setTeam(teamRepository.save(new Team(null, match.getTeamsMatchStatistics1().getTeam().getName())));
|
||||||
|
|
||||||
|
Optional<Team> team2 = teamRepository.findByName(match.getTeamsMatchStatistics2().getTeam().getName());
|
||||||
|
if (team2.isPresent())
|
||||||
|
match.getTeamsMatchStatistics2().setTeam(team2.get());
|
||||||
|
else match.getTeamsMatchStatistics2().setTeam(teamRepository.save(new Team(null, match.getTeamsMatchStatistics2().getTeam().getName())));
|
||||||
|
|
||||||
|
match.setTeamsMatchStatistics1(teamsMatchStatisticsRepository.save(match.getTeamsMatchStatistics1()));
|
||||||
|
match.setTeamsMatchStatistics2(teamsMatchStatisticsRepository.save(match.getTeamsMatchStatistics2()));
|
||||||
|
}
|
||||||
|
matchRepository.saveAll(matches);
|
||||||
|
return "done";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.resultprediction.polishekstraklasa.Predictions.controllers;
|
||||||
|
|
||||||
|
import com.resultprediction.polishekstraklasa.Predictions.model.team.Team;
|
||||||
|
import com.resultprediction.polishekstraklasa.Predictions.model.team.TeamRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/teams")
|
||||||
|
public class TeamController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TeamRepository teamRepository;
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
public String create(@RequestBody List<Team> teams) {
|
||||||
|
for (Team team : teams){
|
||||||
|
if (teamRepository.findByName(team.getName()).isPresent())
|
||||||
|
return "some teams are in database already";
|
||||||
|
}
|
||||||
|
return "done";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.resultprediction.polishekstraklasa.Predictions.model.match;
|
package com.resultprediction.polishekstraklasa.Predictions.model.match;
|
||||||
|
|
||||||
import com.resultprediction.polishekstraklasa.Predictions.model.teamStatistics.TeamStatistics;
|
import com.resultprediction.polishekstraklasa.Predictions.model.teamsMatchStatistics.TeamsMatchStatistics;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -10,26 +10,28 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
|
||||||
@Entity
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "Matches")
|
||||||
public class Match {
|
public class Match {
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@OneToOne
|
@OneToOne
|
||||||
private TeamStatistics teamStatistics1;
|
private TeamsMatchStatistics teamsMatchStatistics1;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@OneToOne
|
@OneToOne
|
||||||
private TeamStatistics teamStatistics2;
|
private TeamsMatchStatistics teamsMatchStatistics2;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -39,7 +41,7 @@ public class Match {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@DateTimeFormat(pattern = "dd-MM-yyyy")
|
@DateTimeFormat(pattern = "dd-MM-yyyy")
|
||||||
private Date date;
|
private Date matchDate;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -2,5 +2,5 @@ package com.resultprediction.polishekstraklasa.Predictions.model.match;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface MatchRepository extends JpaRepository<Long, Match> {
|
public interface MatchRepository extends JpaRepository<Match, Long> {
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,16 @@ import lombok.Getter;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "Teams")
|
||||||
public class Team {
|
public class Team {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private Long id;
|
private Long id;
|
||||||
|
@ -2,5 +2,8 @@ package com.resultprediction.polishekstraklasa.Predictions.model.team;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface TeamRepository extends JpaRepository<Long, Team> {
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface TeamRepository extends JpaRepository<Team, Long> {
|
||||||
|
Optional<Team> findByName(String name);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.resultprediction.polishekstraklasa.Predictions.model.teamStatistics;
|
package com.resultprediction.polishekstraklasa.Predictions.model.teamsMatchStatistics;
|
||||||
|
|
||||||
import com.resultprediction.polishekstraklasa.Predictions.model.team.Team;
|
import com.resultprediction.polishekstraklasa.Predictions.model.team.Team;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -8,15 +8,15 @@ import lombok.Setter;
|
|||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
||||||
@Entity
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TeamStatistics {
|
@Entity
|
||||||
|
public class TeamsMatchStatistics {
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
@ -1,6 +1,6 @@
|
|||||||
package com.resultprediction.polishekstraklasa.Predictions.model.teamStatistics;
|
package com.resultprediction.polishekstraklasa.Predictions.model.teamsMatchStatistics;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface TeamStatisticsRepository extends JpaRepository<Long, TeamStatistics> {
|
public interface TeamsMatchStatisticsRepository extends JpaRepository<TeamsMatchStatistics, Long> {
|
||||||
}
|
}
|
@ -2,4 +2,3 @@ spring.jpa.hibernate.ddl-auto=update
|
|||||||
spring.datasource.url=jdbc:mysql://localhost:3306/ekstraklasa
|
spring.datasource.url=jdbc:mysql://localhost:3306/ekstraklasa
|
||||||
spring.datasource.username=ekstra
|
spring.datasource.username=ekstra
|
||||||
spring.datasource.password=YnBDC0hqqhKaxt94
|
spring.datasource.password=YnBDC0hqqhKaxt94
|
||||||
security.session=never
|
|
||||||
|
Loading…
Reference in New Issue
Block a user