) : (
- recommendedSongs.map(song => (
+ recommendedSongs.map((song) => (
{song.title}
diff --git a/frontend/src/utils/AddClientToStation.js b/frontend/src/utils/AddClientToStation.js
new file mode 100644
index 0000000..a0420b0
--- /dev/null
+++ b/frontend/src/utils/AddClientToStation.js
@@ -0,0 +1,33 @@
+import {
+ RADIOSTATION_URL,
+ ADD_CLIENT_ENDPOINT,
+} from "../constants/ApiConstants";
+
+export async function addClientToStation(username, joinCode) {
+ const body = {
+ username,
+ joinCode,
+ };
+
+ try {
+ const response = await fetch(RADIOSTATION_URL + ADD_CLIENT_ENDPOINT, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(body),
+ });
+
+ const data = await response.json();
+
+ if (!response.ok || !data.success) {
+ console.error("Failed to connect to station:", data.message);
+ throw new Error(data.message || "Unknown error");
+ }
+
+ return data.data.clientToken;
+ } catch (error) {
+ console.error("Error connecting client to station:", error);
+ throw error;
+ }
+}
diff --git a/frontend/src/utils/GetStations.js b/frontend/src/utils/GetStations.js
index 21d954e..886f5c0 100644
--- a/frontend/src/utils/GetStations.js
+++ b/frontend/src/utils/GetStations.js
@@ -4,17 +4,22 @@ import {
} from "../constants/ApiConstants";
export async function getStations() {
- fetch(RADIOSTATION_URL + LIST_RADIOSTATIONS_ENDPOINT, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- },
- })
- .then((response) => response.json())
- .then((data) => {
- console.log("Station:", data);
- })
- .catch((error) => {
- console.error("Error creating station:", error);
- });
+ try {
+ const response = await fetch(
+ RADIOSTATION_URL + LIST_RADIOSTATIONS_ENDPOINT,
+ {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
+
+ const data = await response.json();
+ console.log("Station:", data.data);
+ return data.data;
+ } catch (error) {
+ console.error("Error fetching stations:", error);
+ return [];
+ }
}
diff --git a/frontend/src/utils/StationsCreate.js b/frontend/src/utils/StationsCreate.js
index 34ac305..640629a 100644
--- a/frontend/src/utils/StationsCreate.js
+++ b/frontend/src/utils/StationsCreate.js
@@ -7,22 +7,32 @@ import {
export async function createStation(name, description) {
const body = {
- name: "My Awesome Station",
- description: "The best music station ever",
+ name: name,
+ description: description,
};
- fetch(RADIOSTATION_URL + CREATE_RADIOSTATION_ENDPOINT, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(body),
- })
- .then((response) => response.json())
- .then((data) => {
- console.log("Station created:", data);
- })
- .catch((error) => {
- console.error("Error creating station:", error);
- });
+ try {
+ const response = await fetch(
+ RADIOSTATION_URL + CREATE_RADIOSTATION_ENDPOINT,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(body),
+ }
+ );
+
+ const data = await response.json();
+
+ if (!response.ok || !data.success) {
+ console.error("Failed to create station:", data.message);
+ throw new Error(data.message || "Unknown error");
+ }
+
+ return data.data.station.joinCode;
+ } catch (error) {
+ console.error("Error connecting client to station:", error);
+ throw error;
+ }
}