From d48d05581f0912a6788516338db9cd9fca0d9364 Mon Sep 17 00:00:00 2001 From: Arthi-chaud Date: Mon, 15 Aug 2022 10:54:00 +0200 Subject: [PATCH] Front: Basic API Wrapper with hard-coded values --- front/API.ts | 135 +++++++++++++++++++++++++++++++++++++++++++ front/models/User.ts | 2 +- 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 front/API.ts diff --git a/front/API.ts b/front/API.ts new file mode 100644 index 0000000..852eadb --- /dev/null +++ b/front/API.ts @@ -0,0 +1,135 @@ +import AuthToken from "./models/AuthToken"; +import Chapter from "./models/Chapter"; +import Lesson from "./models/Lesson"; +import LessonHistory from "./models/LessonHistory"; +import Song from "./models/Song"; +import SongHistory from "./models/SongHistory"; +import User from "./models/User"; + +declare type AuthenticationInput = { email: string, password: string }; + +export default class API { + + /*** + * Retrieve information of the currently authentified user + */ + static async getUserInfo(): Promise { + return { + name: "User", + email: "user@chromacase.com", + xp: 0, + premium: false, + metrics: {}, + settings: {}, + id: 1 + } + } + + /** + * Logs the user in, with an email and a password + * @param _credentials the credentials to get an authentication token + * @returns an authentication token, that must be used for authentified requests + */ + static async login(_credentials: AuthenticationInput): Promise { + return "12345"; + } + + /** + * Create a new user profile, with an email and a password + * @param _credentials the credentials to create a new profile + * @returns an empty promise. On error, the promise will not be resolved + */ + static async register(_credentials: AuthenticationInput): Promise { + return; + } + + /** + * Authentify a new user through Google + */ + static async authWithGoogle(): Promise { + return "11111"; + } + + /** + * Retrive a song + * @param songId the id to find the song + */ + static async getSong(songId: number): Promise { + return { + title: "Song", + description: "A song", + album: "Album", + metrics: {}, + id: songId + }; + + } + + /** + * Retrive a song's chapters + * @param songId the id to find the song + */ + static async getSongChapters(songId: number): Promise { + return [{ + start: 0, + end: 100, + songId: songId, + name: "Chapter", + type: "chorus", + key_aspect: "rhythm", + difficulty: 1, + id: 1 + }]; + } + + /** + * Retrieve a song's play history + * @param songId the id to find the song + */ + static async getSongHistory(songId: number): Promise { + return [{ + songId: songId, + userId: 1, + score: 2 + }]; + } + + /** + * Search a song by its name + * @param query the string used to find the songs + */ + static async searchSongs(query: string): Promise { + return [{ + title: "Song", + description: "A song", + album: "Album", + metrics: {}, + id: 1 + }]; + } + + /** + * Retrieve a lesson + * @param lessonId the id to find the lesson + */ + static async getLesson(lessonId: number): Promise { + return { + title: "Song", + description: "A song", + requiredLevel: 1, + mainCompetency: 'lead-head-change', + id: lessonId + }; + } + + /** + * Retrieve a lesson's history + * @param lessonId the id to find the lesson + */ + static async getLessonHistory(lessonId: number): Promise { + return [{ + lessonId, + userId: 1 + }]; + } +} \ No newline at end of file diff --git a/front/models/User.ts b/front/models/User.ts index c8734ae..aaf5e28 100644 --- a/front/models/User.ts +++ b/front/models/User.ts @@ -1,4 +1,4 @@ -import { Metrics } from "react-native-safe-area-context"; +import Metrics from "./Metrics"; import Model from "./Model"; import UserSettings from "./UserSettings";