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 { setItemAsync } from "expo-secure-store";
|
||||
import { AbstractService as AbstractAPIService } from "../abstract.service";
|
||||
import { IUserService } from "./user.service.interface";
|
||||
|
||||
export class UserAPIService extends AbstractAPIService implements IUserService {
|
||||
async login(email: string, password: string): Promise<User> {
|
||||
return this.request(async () => {
|
||||
const response = await apiClient.get(AUTH.LOGIN);
|
||||
return response.data.data;
|
||||
const body = new URLSearchParams({
|
||||
grant_type: "password",
|
||||
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,19 +1,17 @@
|
||||
import { Stack } from "expo-router";
|
||||
import React from "react";
|
||||
import {Stack} from "expo-router";
|
||||
|
||||
export default function RootoLayout() {
|
||||
return (
|
||||
<Stack screenOptions={{
|
||||
<Stack
|
||||
screenOptions={{
|
||||
headerShown: false,
|
||||
}}
|
||||
initialRouteName={"ExercicesScreen"}
|
||||
>
|
||||
<Stack.Screen name="ExercicesScreen" />
|
||||
|
||||
<Stack.Screen name="WorkoutScreen"/>
|
||||
|
||||
<Stack.Screen name="WorkoutScreen" />
|
||||
</Stack>
|
||||
|
||||
);
|
||||
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
import {SafeAreaView, Text, View} from "react-native";
|
||||
import React from "react";
|
||||
import Blocked from "@/components/error/BlockedProblem";
|
||||
import React from "react";
|
||||
import { SafeAreaView, View } from "react-native";
|
||||
|
||||
export default function HelpsScreen() {
|
||||
return (
|
||||
<SafeAreaView>
|
||||
<View>
|
||||
<Blocked/>
|
||||
<Blocked />
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
|
||||
);
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
import { Stack } from "expo-router";
|
||||
import React from "react";
|
||||
import {Stack} from "expo-router";
|
||||
import HelpsScreen from "@/app/(tabs)/(help)/HelpsScreen";
|
||||
|
||||
export default function RootoLayout() {
|
||||
return (
|
||||
<Stack screenOptions={{
|
||||
<Stack
|
||||
screenOptions={{
|
||||
headerShown: false,
|
||||
}}>
|
||||
}}
|
||||
>
|
||||
<Stack.Screen name="HelpsScreen" />
|
||||
</Stack>
|
||||
|
||||
);
|
||||
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
import {SafeAreaView, Text, View} from "react-native";
|
||||
import React from "react";
|
||||
import HomeScreen from "@/app/(tabs)/(home)/HomeScreen";
|
||||
import React from "react";
|
||||
|
||||
export default function App() {
|
||||
|
||||
return (
|
||||
<HomeScreen/>
|
||||
);
|
||||
return <HomeScreen />;
|
||||
}
|
@ -1,10 +1,118 @@
|
||||
export interface Workout {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
duration: number;
|
||||
image: string;
|
||||
video: string;
|
||||
nbSeries: number;
|
||||
nbRepetitions: number;
|
||||
export class Workout {
|
||||
private _id?: string;
|
||||
private _name?: string;
|
||||
private _description?: string;
|
||||
private _duration?: number;
|
||||
private _image?: string;
|
||||
private _video?: string;
|
||||
private _nbSeries?: 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