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 React, { useContext, useState } from 'react';
import { StyleSheet, Text, View, Image, Pressable } from 'react-native'; import { StyleSheet, Text, View, Image, Pressable } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import ListWithoutSelect from './ListWithoutSelect'; import ListWithoutSelect from './ListWithoutSelect';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';

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

Loading…
Cancel
Save