-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added /fixtures & /fixtures/matchweek feature to allow user to retrie…
…ve and see fixtures based on matchweek
- Loading branch information
1 parent
a13a892
commit 018a090
Showing
17 changed files
with
641 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/com/sg/backend/controllers/FixturesController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.sg.backend.controllers; | ||
|
||
import java.util.List; | ||
|
||
import javax.servlet.http.HttpSession; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.sg.backend.models.Fixtures; | ||
import com.sg.backend.service.FixturesService; | ||
|
||
@RestController | ||
@RequestMapping | ||
@CrossOrigin(origins = "*", allowedHeaders = "*") | ||
public class FixturesController { | ||
|
||
@Autowired | ||
private FixturesService fixturesSvc; | ||
|
||
@GetMapping(path = "/fixtures/matchweek") | ||
@CrossOrigin(origins = "*", allowedHeaders = "*") | ||
public List<Fixtures> getFixtures(HttpSession sess, @RequestParam String dayID){ | ||
fixturesSvc.getFixtures(dayID); | ||
List<Fixtures> fixtures = fixturesSvc.getFixtures(dayID); | ||
return fixtures; | ||
} | ||
|
||
} |
125 changes: 125 additions & 0 deletions
125
backend/src/main/java/com/sg/backend/models/Fixtures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.sg.backend.models; | ||
|
||
import java.io.StringReader; | ||
|
||
import jakarta.json.Json; | ||
import jakarta.json.JsonObject; | ||
import jakarta.json.JsonReader; | ||
import jakarta.json.JsonValue; | ||
|
||
public class Fixtures { | ||
private String fullMatchDate; | ||
private String matchTime; | ||
private String homeClubName; | ||
private String homeClubImage; | ||
private String awayClubName; | ||
private String awayClubImage; | ||
private String result; | ||
|
||
public String getFullMatchDate() { | ||
return fullMatchDate; | ||
} | ||
|
||
public void setFullMatchDate(String fullMatchDate) { | ||
this.fullMatchDate = fullMatchDate; | ||
} | ||
|
||
public String getMatchTime() { | ||
return matchTime; | ||
} | ||
|
||
public void setMatchTime(String matchTime) { | ||
this.matchTime = matchTime; | ||
} | ||
|
||
public String getHomeClubName() { | ||
return homeClubName; | ||
} | ||
|
||
public void setHomeClubName(String homeClubName) { | ||
this.homeClubName = homeClubName; | ||
} | ||
|
||
public String getHomeClubImage() { | ||
return homeClubImage; | ||
} | ||
|
||
public void setHomeClubImage(String homeClubImage) { | ||
this.homeClubImage = homeClubImage; | ||
} | ||
|
||
public String getAwayClubName() { | ||
return awayClubName; | ||
} | ||
|
||
public void setAwayClubName(String awayClubName) { | ||
this.awayClubName = awayClubName; | ||
} | ||
|
||
public String getAwayClubImage() { | ||
return awayClubImage; | ||
} | ||
|
||
public void setAwayClubImage(String awayClubImage) { | ||
this.awayClubImage = awayClubImage; | ||
} | ||
|
||
public String getResult() { | ||
return result; | ||
} | ||
|
||
public void setResult(String result) { | ||
this.result = result; | ||
} | ||
|
||
public static Fixtures create(JsonObject json) { | ||
final Fixtures fixture = new Fixtures(); | ||
fixture.setFullMatchDate(json.getString("fullMatchDate")); | ||
fixture.setMatchTime(json.getString("matchTime")); | ||
fixture.setHomeClubName(json.getString("homeClubName")); | ||
fixture.setHomeClubImage(json.getString("homeClubImage")); | ||
fixture.setAwayClubName(json.getString("awayClubName")); | ||
fixture.setAwayClubImage(json.getString("awayClubImage")); | ||
fixture.setResult(json.getString("result")); | ||
return fixture; | ||
} | ||
|
||
public static Fixtures create(String json) { | ||
try (StringReader strReader = new StringReader(json)) { | ||
JsonReader j = Json.createReader(strReader); | ||
return create(j.readObject()); | ||
} | ||
} | ||
|
||
public JsonObject toJson() { | ||
return Json.createObjectBuilder() | ||
.add("fullMatchDate", this.fullMatchDate) | ||
.add("matchTime", this.matchTime) | ||
.add("homeClubName", this.homeClubName) | ||
.add("homeClubImage", this.homeClubImage) | ||
.add("awayClubName", this.awayClubName) | ||
.add("awayClubName", this.awayClubImage) | ||
.add("result", this.result) | ||
.build(); | ||
} | ||
|
||
public JsonValue toJsonValue() { | ||
return Json.createObjectBuilder() | ||
.add("fullMatchDate", this.fullMatchDate) | ||
.add("matchTime", this.matchTime) | ||
.add("homeClubName", this.homeClubName) | ||
.add("homeClubImage", this.homeClubImage) | ||
.add("awayClubName", this.awayClubName) | ||
.add("awayClubName", this.awayClubImage) | ||
.add("result", this.result) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Fixtures [fullMatchDate=" + fullMatchDate + ", matchTime=" + matchTime + ", homeClubName=" | ||
+ homeClubName + ", homeClubImage=" + homeClubImage + ", awayClubName=" + awayClubName | ||
+ ", awayClubImage=" + awayClubImage + ", result=" + result + "]"; | ||
} | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
backend/src/main/java/com/sg/backend/service/FixturesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.sg.backend.service; | ||
|
||
import java.io.StringReader; | ||
import java.util.Collections; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import com.sg.backend.models.Fixtures; | ||
|
||
import jakarta.json.Json; | ||
import jakarta.json.JsonArray; | ||
import jakarta.json.JsonObject; | ||
import jakarta.json.JsonReader; | ||
import jakarta.json.JsonValue; | ||
|
||
@Service | ||
public class FixturesService { | ||
|
||
private static final String URL = "https://transfermarket.p.rapidapi.com/matches/list-by-game-plan"; | ||
|
||
@Value("${X_RapidAPI_Key}") | ||
private String rapidAPI; | ||
|
||
public List<Fixtures> getFixtures(String dayID) { | ||
String payload; | ||
System.out.println("Attempting request to TransferMarkt.com...."); | ||
|
||
try { | ||
|
||
String url = UriComponentsBuilder | ||
.fromUriString(URL) | ||
.queryParam("seasonID", "2022") | ||
.queryParam("leagueID", "GB1") | ||
.queryParam("domain", "com") | ||
.queryParam("dayID", dayID) | ||
.encode() | ||
.toUriString(); | ||
|
||
RequestEntity<Void> req = RequestEntity | ||
.get(url) | ||
.header("X-RapidAPI-Key", "%s".formatted(rapidAPI)) | ||
.build(); | ||
|
||
System.out.println(">>> [url]: " + url); | ||
|
||
System.out.println("-----------------------------------------------------------"); | ||
|
||
RestTemplate template = new RestTemplate(); | ||
|
||
ResponseEntity<String> resp; | ||
resp = template.exchange(req, String.class); | ||
|
||
payload = resp.getBody(); | ||
|
||
System.out.println(">>> [payload]: " + payload); | ||
System.out.println("-----------------------------------------------------------"); | ||
|
||
} catch (Exception ex) { | ||
System.err.printf("Error: %s\n", ex.getMessage()); | ||
return Collections.emptyList(); | ||
} | ||
|
||
List<Fixtures> fixtures = new LinkedList<>(); | ||
|
||
try (StringReader strReader = new StringReader(payload)) { | ||
JsonReader r = Json.createReader(strReader); | ||
JsonObject j = r.readObject(); | ||
|
||
JsonArray fixturesArr = j.getJsonArray("playDayMatches"); | ||
|
||
System.out.println("Total number of fixtures: " + fixturesArr.size()); | ||
System.out.println("-----------------------------------------------------------"); | ||
|
||
for (JsonValue v : j.getJsonArray("playDayMatches")) { | ||
if (v.getValueType() == JsonValue.ValueType.OBJECT) { | ||
try { | ||
fixtures.add(Fixtures.create((JsonObject) v)); | ||
} catch (Exception ex) { | ||
System.err.printf("Error: %s\n", ex.getMessage()); | ||
} | ||
} | ||
} | ||
for (Fixtures fixture : fixtures) { | ||
System.out.println(fixture.getFullMatchDate() + ": " + fixture.getMatchTime() + ": " | ||
+ fixture.getHomeClubName() + ": " + fixture.getHomeClubImage() + ": " | ||
+ fixture.getAwayClubName() + ": " + fixture.getAwayClubImage() + ": " + fixture.getResult()); | ||
} | ||
|
||
} | ||
return fixtures; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
018a090
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vttpminiproject-02 – ./
vttpminiproject-02-git-main-augustinecyr.vercel.app
vttpminiproject-02.vercel.app
vttpminiproject-02-augustinecyr.vercel.app