From d2848447b66236fce7cda3f0da3f6c2ad1745341 Mon Sep 17 00:00:00 2001 From: Felix-Vimalaratnam Date: Fri, 28 Mar 2025 13:53:35 +0100 Subject: [PATCH] projet --- components/app.riot | 173 ++++++++++++++++++++++++++++++++ components/favorites.riot | 33 ++++++ components/login.riot | 49 +++++++++ components/register.riot | 57 +++++++++++ components/release-details.riot | 68 +++++++++++++ index.html | 37 +++++++ services/discogsService.js | 20 ++++ services/firebaseService.js | 84 ++++++++++++++++ 8 files changed, 521 insertions(+) create mode 100644 components/app.riot create mode 100644 components/favorites.riot create mode 100644 components/login.riot create mode 100644 components/register.riot create mode 100644 components/release-details.riot create mode 100644 index.html create mode 100644 services/discogsService.js create mode 100644 services/firebaseService.js diff --git a/components/app.riot b/components/app.riot new file mode 100644 index 0000000..aa28c04 --- /dev/null +++ b/components/app.riot @@ -0,0 +1,173 @@ + + + + + +
+ + + +
+ +
+

Résultats ({searchs.pagination.items.total} résultats trouvés)

+ +
+
+ + + + + + + + + + + + + +
+ + + + + +
\ No newline at end of file diff --git a/components/favorites.riot b/components/favorites.riot new file mode 100644 index 0000000..1b22add --- /dev/null +++ b/components/favorites.riot @@ -0,0 +1,33 @@ + +

Mes favoris

+ + + +
\ No newline at end of file diff --git a/components/login.riot b/components/login.riot new file mode 100644 index 0000000..e57dfce --- /dev/null +++ b/components/login.riot @@ -0,0 +1,49 @@ + +

Connexion

+
+ + + +
+

Pas encore de compte ?

+ + +
\ No newline at end of file diff --git a/components/register.riot b/components/register.riot new file mode 100644 index 0000000..aa9d213 --- /dev/null +++ b/components/register.riot @@ -0,0 +1,57 @@ + +

Inscription

+
+ + + +
+

Déjà un compte ?

+ + +
\ No newline at end of file diff --git a/components/release-details.riot b/components/release-details.riot new file mode 100644 index 0000000..60d58e1 --- /dev/null +++ b/components/release-details.riot @@ -0,0 +1,68 @@ + +
+

{state.release.title}

+

-{state.release.year}

+ +
+ {state.release.title} +
+ Track list +
    +
  • + {track.position} - {track.title} - {track.duration} +
  • +
+ +
+ {genre} +
+
+
+ {state.release.profile} +
+
+
+ + + + +
\ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..9ce9b93 --- /dev/null +++ b/index.html @@ -0,0 +1,37 @@ + + + + + + + Music App RiotJS + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/discogsService.js b/services/discogsService.js new file mode 100644 index 0000000..97a78d0 --- /dev/null +++ b/services/discogsService.js @@ -0,0 +1,20 @@ +const baseUrlsearch = 'https://api.discogs.com/database/search'; +const baseUrlrelease = 'https://api.discogs.com/releases/'; +const key = 'NWmMhlPAbPlVnaDqVGyX'; +const secret = 'hZPaoBiGiSwlCjARrbOICOpDuITwyJAm'; +const perPage = 100; + +export async function discogsearch(query, type) { + const url = `${baseUrlsearch}?q=${query}&type=${type}&per_page=${perPage}&key=${key}&secret=${secret}`; + const response = await fetch(url); + return await response.json(); +} + + +export async function getReleaseDetails(releaseId) { + const response = await fetch(`${baseUrlrelease}${releaseId}`); + return await response.json(); +} + +window.getReleaseDetails = getReleaseDetails; +window.discogsearch = discogsearch; \ No newline at end of file diff --git a/services/firebaseService.js b/services/firebaseService.js new file mode 100644 index 0000000..90bd1b0 --- /dev/null +++ b/services/firebaseService.js @@ -0,0 +1,84 @@ +// Firebase V9 ESM seulement +import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js"; +import { + getAuth, + createUserWithEmailAndPassword, + signInWithEmailAndPassword, + onAuthStateChanged, + signOut +} from "https://www.gstatic.com/firebasejs/9.6.1/firebase-auth.js"; + +import { + getFirestore, + collection, + addDoc, + doc, + setDoc +} from "https://www.gstatic.com/firebasejs/9.6.1/firebase-firestore.js"; + +const firebaseConfig = { + apiKey: "AIzaSyBXKB6AGbTN95lOLrIVpWrSIK_uL_C6GUA", + authDomain: "music-app-riotjs.firebaseapp.com", + projectId: "music-app-riotjs", + storageBucket: "music-app-riotjs.firebasestorage.app", + messagingSenderId: "483729603961", + appId: "1:483729603961:web:122965ce7dbeb2e85103a8", + measurementId: "G-18P6WCT80" +}; + +const app = initializeApp(firebaseConfig); +const auth = getAuth(app); +const db = getFirestore(app); + +export async function login(email, password) { + await signInWithEmailAndPassword(auth, email, password); +} + +export async function sign(email, password) { + const userCred = await createUserWithEmailAndPassword(auth, email, password); + await adduserdata(userCred.user.email); +} + +export async function adduserdata(email_user) { + await addDoc(collection(db, "users"), { + email: email_user + }); +} + +export async function logout() { + await signOut(auth); +} + +window.observeAuthState = function(callback) { + onAuthStateChanged(auth, callback); +}; + +export async function favorite(releaseId) { + const user = auth.currentUser; + if (!user) return; + await addDoc(collection(db, "users", user.email, "favorites"), { + id: releaseId + }); +} + +export async function getFavorites() { + const user = auth.currentUser; + if (!user) { + console.warn("Aucun utilisateur connecté."); + return []; + } + + const userDocRef = doc(db, "users", user.email); + const favsCollection = collection(userDocRef, "favorites"); + + const snapshot = await getDocs(favsCollection); + const favorites = snapshot.docs.map(doc => doc.data()); + + return favorites; +} + +window.login = login; +window.sign = sign; +window.logout = logout; +window.favorite = favorite; +window.getFavorites = getFavorites; \ No newline at end of file