diff --git a/front/API.ts b/front/API.ts new file mode 100644 index 0000000..faa9214 --- /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, + mainSkill: '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/Artist.ts b/front/models/Artist.ts new file mode 100644 index 0000000..28b9610 --- /dev/null +++ b/front/models/Artist.ts @@ -0,0 +1,7 @@ +import Model from "./Model"; + +interface Artist extends Model { + name: string; +} + +export default Artist; \ No newline at end of file diff --git a/front/models/AuthToken.ts b/front/models/AuthToken.ts new file mode 100644 index 0000000..25bb4f9 --- /dev/null +++ b/front/models/AuthToken.ts @@ -0,0 +1,3 @@ +type AuthToken = string; + +export default AuthToken; \ No newline at end of file diff --git a/front/models/Chapter.ts b/front/models/Chapter.ts new file mode 100644 index 0000000..538a1ad --- /dev/null +++ b/front/models/Chapter.ts @@ -0,0 +1,14 @@ +import Skill from "./Skill"; +import Model from "./Model"; + +interface Chapter extends Model { + start: number; + end: number; + songId: number; + name: string; + type: 'chorus' | 'verse'; + key_aspect: Skill; + difficulty: number +} + +export default Chapter; \ No newline at end of file diff --git a/front/models/Genre.ts b/front/models/Genre.ts new file mode 100644 index 0000000..5d8bf2f --- /dev/null +++ b/front/models/Genre.ts @@ -0,0 +1,7 @@ +import Model from "./Model"; + +interface Genre extends Model { + name: string; +} + +export default Genre; \ No newline at end of file diff --git a/front/models/Lesson.ts b/front/models/Lesson.ts new file mode 100644 index 0000000..f45511b --- /dev/null +++ b/front/models/Lesson.ts @@ -0,0 +1,26 @@ +import Skill from "./Skill"; +import Model from "./Model"; + +/** + * A Lesson is an exercice that the user can try to practice a skill + */ +interface Lesson extends Model { + /** + * The title of the lesson + */ + title: string, + /** + * Short description of the lesson + */ + description: string; + /** + * The minimum level required for the user to access this lesson + */ + requiredLevel: number; + /** + * The main skill learnt in this lesson + */ + mainSkill: Skill; +} + +export default Lesson; \ No newline at end of file diff --git a/front/models/LessonHistory.ts b/front/models/LessonHistory.ts new file mode 100644 index 0000000..5a5410f --- /dev/null +++ b/front/models/LessonHistory.ts @@ -0,0 +1,6 @@ +interface LessonHistory { + lessonId: number; + userId: number +} + +export default LessonHistory; \ No newline at end of file diff --git a/front/models/Metrics.ts b/front/models/Metrics.ts new file mode 100644 index 0000000..9e1a4f1 --- /dev/null +++ b/front/models/Metrics.ts @@ -0,0 +1,5 @@ +interface Metrics { + +} + +export default Metrics; \ No newline at end of file diff --git a/front/models/Model.ts b/front/models/Model.ts new file mode 100644 index 0000000..e5a23ce --- /dev/null +++ b/front/models/Model.ts @@ -0,0 +1,5 @@ +interface Model { + id: number; +} + +export default Model; \ No newline at end of file diff --git a/front/models/Skill.ts b/front/models/Skill.ts new file mode 100644 index 0000000..cb96d2d --- /dev/null +++ b/front/models/Skill.ts @@ -0,0 +1,15 @@ +type Skill = 'rhythm' + | 'two-hands' + | 'combos' + | 'arpeggio' + | 'distance' + | 'left-hand' + | 'right-hand' + | 'lead-head-change' + | 'chord-complexity' + | 'chord-timing' + | 'pedal' + | 'precision' + + +export default Skill; \ No newline at end of file diff --git a/front/models/Song.ts b/front/models/Song.ts new file mode 100644 index 0000000..0b148dd --- /dev/null +++ b/front/models/Song.ts @@ -0,0 +1,11 @@ +import Metrics from "./Metrics"; +import Model from "./Model"; + +interface Song extends Model { + title: string; + description: string; + album: string + metrics: Metrics; +} + +export default Song; \ No newline at end of file diff --git a/front/models/SongHistory.ts b/front/models/SongHistory.ts new file mode 100644 index 0000000..a8c04c4 --- /dev/null +++ b/front/models/SongHistory.ts @@ -0,0 +1,7 @@ +interface LessonHistory { + songId: number; + userId: number; + score: number; +} + +export default LessonHistory; \ No newline at end of file diff --git a/front/models/User.ts b/front/models/User.ts new file mode 100644 index 0000000..aaf5e28 --- /dev/null +++ b/front/models/User.ts @@ -0,0 +1,14 @@ +import Metrics from "./Metrics"; +import Model from "./Model"; +import UserSettings from "./UserSettings"; + +interface User extends Model { + name: string; + email: string; + xp: number; + premium: boolean; + metrics: Metrics; + settings: UserSettings; +} + +export default User; \ No newline at end of file diff --git a/front/models/UserSettings.ts b/front/models/UserSettings.ts new file mode 100644 index 0000000..a576b1a --- /dev/null +++ b/front/models/UserSettings.ts @@ -0,0 +1,5 @@ +interface UserSettings { + +} + +export default UserSettings \ No newline at end of file diff --git a/front/state/UserSlice.ts b/front/state/UserSlice.ts index 46da6ee..a7904f7 100644 --- a/front/state/UserSlice.ts +++ b/front/state/UserSlice.ts @@ -1,12 +1,13 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; +import AuthToken from '../models/AuthToken'; export const userSlice = createSlice({ name: 'user', initialState: { - token: undefined as string | undefined + token: undefined as AuthToken | undefined }, reducers: { - setUserToken: (state, action: PayloadAction) => { + setUserToken: (state, action: PayloadAction) => { state.token = action.payload; }, unsetUserToken: (state) => {