parent
a3e567f291
commit
90b1e450e1
@ -1,12 +0,0 @@
|
|||||||
import apiClient from "@/api/client";
|
|
||||||
import { EXERCICES } from "@/api/endpoints";
|
|
||||||
import { AbstractService } from "../abstract.service";
|
|
||||||
|
|
||||||
export class ExerciceService extends AbstractService {
|
|
||||||
async getExercices() {
|
|
||||||
return this.request(async () => {
|
|
||||||
const response = await apiClient.get(EXERCICES.GETALL);
|
|
||||||
return response.data.data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,14 @@
|
|||||||
|
import { EXERCICES } from "@/api/endpoints";
|
||||||
|
import { Workout } from "@/model/Workout";
|
||||||
|
import { AbstractService } from "../abstract.service";
|
||||||
|
import { IExerciceInterface } from "./exercice.service.interface";
|
||||||
|
|
||||||
|
export class ExerciceAPIService
|
||||||
|
extends AbstractService
|
||||||
|
implements IExerciceInterface
|
||||||
|
{
|
||||||
|
async getExercices(): Promise<Workout[]> {
|
||||||
|
const data = await this.request(EXERCICES.GETALL);
|
||||||
|
return data.data.map((item: any) => Workout.fromJson(item));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
export interface IExerciceInterface {
|
||||||
|
getExercices(): Promise<any>;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import { AbstractService } from "../abstract.service";
|
||||||
|
import { IExerciceInterface } from "./exercice.service.interface";
|
||||||
|
|
||||||
|
export class ExerciceStubService
|
||||||
|
extends AbstractService
|
||||||
|
implements IExerciceInterface
|
||||||
|
{
|
||||||
|
async getExercices() {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,31 @@
|
|||||||
import apiClient from "@/api/client";
|
|
||||||
import { AUTH } from "@/api/endpoints";
|
|
||||||
import { User } from "@/model/User";
|
import { User } from "@/model/User";
|
||||||
|
import { setItemAsync } from "expo-secure-store";
|
||||||
import { AbstractService as AbstractAPIService } from "../abstract.service";
|
import { AbstractService as AbstractAPIService } from "../abstract.service";
|
||||||
import { IUserService } from "./user.service.interface";
|
import { IUserService } from "./user.service.interface";
|
||||||
|
|
||||||
export class UserAPIService extends AbstractAPIService implements IUserService {
|
export class UserAPIService extends AbstractAPIService implements IUserService {
|
||||||
async login(email: string, password: string): Promise<User> {
|
async login(email: string, password: string): Promise<User> {
|
||||||
return this.request(async () => {
|
const body = new URLSearchParams({
|
||||||
const response = await apiClient.get(AUTH.LOGIN);
|
grant_type: "password",
|
||||||
return response.data.data;
|
client_id: email,
|
||||||
|
client_secret: this.CLIENT_SECRET,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
scope: this.SCOPES,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const res = await fetch(`${this.IDP_URL}/connect/token`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||||
|
body: body.toString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) throw new Error(`Auth failed: ${res.status}`);
|
||||||
|
const json = await res.json();
|
||||||
|
|
||||||
|
await setItemAsync(this.ACCESS_TOKEN_PATH, json.access_token);
|
||||||
|
await setItemAsync(this.REFRESH_TOKEN_PATH, json.refresh_token);
|
||||||
|
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import React from "react";
|
|
||||||
import { Stack } from "expo-router";
|
import { Stack } from "expo-router";
|
||||||
import HelpsScreen from "@/app/(tabs)/(help)/HelpsScreen";
|
import React from "react";
|
||||||
|
|
||||||
export default function RootoLayout() {
|
export default function RootoLayout() {
|
||||||
return (
|
return (
|
||||||
<Stack screenOptions={{
|
<Stack
|
||||||
|
screenOptions={{
|
||||||
headerShown: false,
|
headerShown: false,
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
<Stack.Screen name="HelpsScreen" />
|
<Stack.Screen name="HelpsScreen" />
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +1,6 @@
|
|||||||
import {SafeAreaView, Text, View} from "react-native";
|
|
||||||
import React from "react";
|
|
||||||
import HomeScreen from "@/app/(tabs)/(home)/HomeScreen";
|
import HomeScreen from "@/app/(tabs)/(home)/HomeScreen";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
return <HomeScreen />;
|
||||||
return (
|
|
||||||
<HomeScreen/>
|
|
||||||
);
|
|
||||||
}
|
}
|
@ -1,10 +1,118 @@
|
|||||||
export interface Workout {
|
export class Workout {
|
||||||
id: string;
|
private _id?: string;
|
||||||
name: string;
|
private _name?: string;
|
||||||
description: string;
|
private _description?: string;
|
||||||
duration: number;
|
private _duration?: number;
|
||||||
image: string;
|
private _image?: string;
|
||||||
video: string;
|
private _video?: string;
|
||||||
nbSeries: number;
|
private _nbSeries?: number;
|
||||||
nbRepetitions: number;
|
private _nbRepetitions?: number;
|
||||||
|
|
||||||
|
constructor({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
duration,
|
||||||
|
image,
|
||||||
|
video,
|
||||||
|
nbSeries,
|
||||||
|
nbRepetitions,
|
||||||
|
}: {
|
||||||
|
id?: string;
|
||||||
|
name?: string;
|
||||||
|
description?: string;
|
||||||
|
duration?: number;
|
||||||
|
image?: string;
|
||||||
|
video?: string;
|
||||||
|
nbSeries?: number;
|
||||||
|
nbRepetitions?: number;
|
||||||
|
} = {}) {
|
||||||
|
this._id = id;
|
||||||
|
this._name = name;
|
||||||
|
this._description = description;
|
||||||
|
this._duration = duration;
|
||||||
|
this._image = image;
|
||||||
|
this._video = video;
|
||||||
|
this._nbSeries = nbSeries;
|
||||||
|
this._nbRepetitions = nbRepetitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
get id(): string | undefined {
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name(): string | undefined {
|
||||||
|
return this._name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get description(): string | undefined {
|
||||||
|
return this._description;
|
||||||
|
}
|
||||||
|
|
||||||
|
get duration(): number | undefined {
|
||||||
|
return this._duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
get image(): string | undefined {
|
||||||
|
return this._image;
|
||||||
|
}
|
||||||
|
|
||||||
|
get video(): string | undefined {
|
||||||
|
return this._video;
|
||||||
|
}
|
||||||
|
|
||||||
|
get nbSeries(): number | undefined {
|
||||||
|
return this._nbSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
get nbRepetitions(): number | undefined {
|
||||||
|
return this._nbRepetitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
set id(value: string | undefined) {
|
||||||
|
this._id = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set name(value: string | undefined) {
|
||||||
|
this._name = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set description(value: string | undefined) {
|
||||||
|
this._description = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set duration(value: number | undefined) {
|
||||||
|
this._duration = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set image(value: string | undefined) {
|
||||||
|
this._image = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set video(value: string | undefined) {
|
||||||
|
this._video = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set nbSeries(value: number | undefined) {
|
||||||
|
this._nbSeries = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set nbRepetitions(value: number | undefined) {
|
||||||
|
this._nbRepetitions = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(json: any): Workout {
|
||||||
|
return new Workout({
|
||||||
|
id: json.id,
|
||||||
|
name: json.name,
|
||||||
|
description: json.description,
|
||||||
|
duration: json.duration,
|
||||||
|
image: json.image,
|
||||||
|
video: json.video,
|
||||||
|
nbSeries: json.nbSeries,
|
||||||
|
nbRepetitions: json.nbRepetitions,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue