feat: add IProfileService and ProfileService

pull/23/head
Rémi REGNAULT 1 year ago
parent f622179de1
commit 05ffc72303

@ -0,0 +1,6 @@
import Profil from "../../Models/Profil";
export default interface IProfileService {
getProfiles(): Promise<Profil[]>,
addProfile(new_profile: Profil): void
}

@ -0,0 +1,14 @@
import Profil from "../../Models/Profil";
import IProfileService from "./IProfileService";
import AsyncStorage from "@react-native-async-storage/async-storage";
export default class ProfileService implements IProfileService {
async getProfiles(): Promise<Profil[]> {
const existingProfiles = await AsyncStorage.getItem('profiles');
return JSON.parse(existingProfiles) || [];
}
addProfile(new_profile : Profil): void {
throw new Error("Method not implemented.");
}
}

@ -1,5 +1,6 @@
import React, { useContext, useState } from 'react';
import { StyleSheet, Text, View, Image, Pressable } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import ListWithoutSelect from './ListWithoutSelect';
import ColorContext from '../theme/ColorContext';

@ -11,9 +11,11 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter';
import Profil from '../Models/Profil';
import { PaperProvider, Portal } from 'react-native-paper';
import ProfileService from '../Services/Profiles/ProfileService';
export default function Profiles({navigation, props}) {
const colors = useContext(ColorContext).colors
const profile_service = new ProfileService()
const all = []
const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
@ -56,10 +58,9 @@ export default function Profiles({navigation, props}) {
erasePopUp();
};
const handleGetProfiles = async () => {
const handleGetProfiles = async () => {
try {
const existingProfiles = await AsyncStorage.getItem('profiles');
return JSON.parse(existingProfiles) || [];
return await profile_service.getProfiles()
} catch (error) {
console.log("ça maaaaaaaaarche poaaaaaaaaaaaas");
return [];

Loading…
Cancel
Save