diff --git a/Back/pom.xml b/Back/pom.xml index 8bde47f..82b8c8d 100644 --- a/Back/pom.xml +++ b/Back/pom.xml @@ -24,13 +24,6 @@ spring-boot-starter-data-jpa - - org.springframework.boot - spring-boot-devtools - runtime - true - - org.springframework.boot spring-boot-starter-web @@ -51,6 +44,11 @@ mysql-connector-java runtime + + org.springframework.boot + spring-boot-devtools + true + org.springframework.boot spring-boot-configuration-processor diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/PredictionsApplication.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/PredictionsApplication.java index 691f656..18b8124 100644 --- a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/PredictionsApplication.java +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/PredictionsApplication.java @@ -1,8 +1,13 @@ package com.resultprediction.polishekstraklasa.Predictions; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; 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.RestController; @@ -11,7 +16,6 @@ import java.util.Collections; import java.util.Map; @SpringBootApplication -@RestController public class PredictionsApplication { public static void main(String[] args) { diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/controllers/MatchController.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/controllers/MatchController.java new file mode 100644 index 0000000..e676783 --- /dev/null +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/controllers/MatchController.java @@ -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 matches) { + for (Match match : matches){ + Optional 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 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"; + } + +} diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/controllers/TeamController.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/controllers/TeamController.java new file mode 100644 index 0000000..2f4ebcf --- /dev/null +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/controllers/TeamController.java @@ -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 teams) { + for (Team team : teams){ + if (teamRepository.findByName(team.getName()).isPresent()) + return "some teams are in database already"; + } + return "done"; + } + +} diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/Match.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/Match.java index 0e3ee92..eaf48f8 100644 --- a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/Match.java +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/Match.java @@ -1,6 +1,6 @@ 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.Getter; import lombok.NoArgsConstructor; @@ -10,26 +10,28 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.*; import java.sql.Date; -@Entity + @NoArgsConstructor @AllArgsConstructor +@Entity +@Table(name = "Matches") public class Match { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) @Getter @Setter + @Id + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Getter @Setter @OneToOne - private TeamStatistics teamStatistics1; + private TeamsMatchStatistics teamsMatchStatistics1; @Getter @Setter @OneToOne - private TeamStatistics teamStatistics2; + private TeamsMatchStatistics teamsMatchStatistics2; @Getter @Setter @@ -39,7 +41,7 @@ public class Match { @Getter @Setter @DateTimeFormat(pattern = "dd-MM-yyyy") - private Date date; + private Date matchDate; @Getter @Setter diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/MatchRepository.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/MatchRepository.java index d473c4b..7a6bcc4 100644 --- a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/MatchRepository.java +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/match/MatchRepository.java @@ -2,5 +2,5 @@ package com.resultprediction.polishekstraklasa.Predictions.model.match; import org.springframework.data.jpa.repository.JpaRepository; -public interface MatchRepository extends JpaRepository { +public interface MatchRepository extends JpaRepository { } diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/Team.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/Team.java index d9eb13c..ee8ff0d 100644 --- a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/Team.java +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/Team.java @@ -5,18 +5,16 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import javax.persistence.*; -@Entity @NoArgsConstructor @AllArgsConstructor +@Entity +@Table(name = "Teams") public class Team { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.AUTO) @Getter @Setter private Long id; diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/TeamRepository.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/TeamRepository.java index 9a7a27f..f2a714f 100644 --- a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/TeamRepository.java +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/team/TeamRepository.java @@ -2,5 +2,8 @@ package com.resultprediction.polishekstraklasa.Predictions.model.team; import org.springframework.data.jpa.repository.JpaRepository; -public interface TeamRepository extends JpaRepository { +import java.util.Optional; + +public interface TeamRepository extends JpaRepository { + Optional findByName(String name); } diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamStatistics/TeamStatistics.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamsMatchStatistics/TeamsMatchStatistics.java similarity index 91% rename from Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamStatistics/TeamStatistics.java rename to Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamsMatchStatistics/TeamsMatchStatistics.java index bebb2bf..c96502a 100644 --- a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamStatistics/TeamStatistics.java +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamsMatchStatistics/TeamsMatchStatistics.java @@ -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 lombok.AllArgsConstructor; @@ -8,15 +8,15 @@ import lombok.Setter; import javax.persistence.*; -@Entity @NoArgsConstructor @AllArgsConstructor -public class TeamStatistics { +@Entity +public class TeamsMatchStatistics { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) @Getter @Setter + @Id + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Getter diff --git a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamStatistics/TeamStatisticsRepository.java b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamsMatchStatistics/TeamsMatchStatisticsRepository.java similarity index 51% rename from Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamStatistics/TeamStatisticsRepository.java rename to Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamsMatchStatistics/TeamsMatchStatisticsRepository.java index 6b39875..d27a7a7 100644 --- a/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamStatistics/TeamStatisticsRepository.java +++ b/Back/src/main/java/com/resultprediction/polishekstraklasa/Predictions/model/teamsMatchStatistics/TeamsMatchStatisticsRepository.java @@ -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; -public interface TeamStatisticsRepository extends JpaRepository { +public interface TeamsMatchStatisticsRepository extends JpaRepository { } diff --git a/Back/src/main/resources/application.properties b/Back/src/main/resources/application.properties index dbd8e78..2ef9e51 100644 --- a/Back/src/main/resources/application.properties +++ b/Back/src/main/resources/application.properties @@ -2,4 +2,3 @@ spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://localhost:3306/ekstraklasa spring.datasource.username=ekstra spring.datasource.password=YnBDC0hqqhKaxt94 -security.session=never