Commit c08395c9 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Se agrego multilenguaje a las peticiones de la api

parent 47a5f1f0
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import { ProfileRepository } from "../../profile/domain/repositories/profile_rep
import { ProfileDataSourceDev } from "../../profile/infrastructure/datasources/dev/profile_datasource";
import { ProfileRepositoryImpl } from "../../profile/infrastructure/repositories/profile_repository";
import { ActivityDatasourceProd } from "../../infrastructure/datasource/prod/activity_datasource";
import { useTranslation } from "react-i18next";
import { ProfileDataSourceProd } from "../../profile/infrastructure/datasources/prod/profile_datasource";

type DataContextType = {
    statesRepository: StateRepository | null;
@@ -42,20 +44,26 @@ const DataContext = createContext<DataContextType>({
});

export const DataContextProvider = ({ children }: DataContextProviderProps) => {
    //const statesDataSource = new StateDataSourceDev();
    const statesDataSource = new StateDataSourceProd();
    const { i18n:{ language } } = useTranslation();
    const statesDataSource = new StateDataSourceDev();
    //const statesDataSource = new StateDataSourceProd(language);
    const statesRepository = new StateRepositoryImpl(statesDataSource);
    //const authDataSource = new AuthDataSourceDev();
    const authDataSource = new AuthDatasourceProd();
    //
    const authDataSource = new AuthDataSourceDev();
    //const authDataSource = new AuthDatasourceProd();
    const authRepository = new AuthRepositoryImpl(authDataSource);
    //const activityDataSource = new ActivityDatasourceDev();
    const activityDataSource = new ActivityDatasourceProd();
    //
    const activityDataSource = new ActivityDatasourceDev();
    //const activityDataSource = new ActivityDatasourceProd();
    const activityRepository = new ActivityRepositoryDev(activityDataSource);
    //
    const travelDatasource = new TravelDatasourceDev();
    const travelRepository = new TravelRepositoryImpl(travelDatasource);
    //
    const routeDatasource = new RouteDataSourceDev();
    const routeRepository = new RouteRepositoryImpl(routeDatasource);
    const profileDataSource = new ProfileDataSourceDev();
    //
    const profileDataSource = new ProfileDataSourceProd();
    const profileRepository = new ProfileRepositoryImpl(profileDataSource);
    
    const value = {
+3 −1
Original line number Diff line number Diff line
@@ -4,10 +4,12 @@ import { ActivityPlaceEntity } from "../../../domain/entities/activity_place_ent
import { API_URL } from "../../../common/constants/api";
import { ActivityPlaceModel } from "../../models/prod/activity_place_model";
import { activityPlaceModelToEntity } from "../../utils/activity_utils";
import { Languages } from "../../../lang/translations";

export class ActivityDatasourceProd implements ActivityDataSource {
    constructor(private lang: string = Languages.SPANISH) {}
    async getPlaceActivity(activityId: number, townId: number, stateId: number, placeNumber: number): Promise<ActivityPlaceEntity> {
        const { data, status } = await axios.get<ActivityPlaceModel>(`${API_URL}/point/${placeNumber}lang?lang=es`);
        const { data, status } = await axios.get<ActivityPlaceModel>(`${API_URL}/point/${placeNumber}lang?lang=${this.lang}`);
        if (status !== 200) {
            throw new Error("Error al obtener la información del lugar");
        }
+7 −6
Original line number Diff line number Diff line
@@ -12,6 +12,10 @@ import { ActivityModel } from "../../models/prod/activity_model";
import { placeModelToEntity } from "../../utils/place_utils";

export class StateDataSourceProd implements StateDataSource {
    private lang: string;
    constructor(lang: string = 'es') {
        this.lang = lang;
    }
    async getStates(): Promise<StateEntity[]> {
        const {status, data} = await axios.get<StateModel[]>(API_URL + '/state');
        if (status !== 200) {
@@ -20,18 +24,15 @@ export class StateDataSourceProd implements StateDataSource {
        return data.map(stateModelToEntity);
    }
    async getTowns(stateId: number): Promise<TownEntity[]> {
        // TODO: get lang from user preferences
        const {status, data} = await axios.get<TownModel[]>(API_URL + '/state/' + stateId + '/town?lang=es');
        const {status, data} = await axios.get<TownModel[]>(`${API_URL}/state/${stateId}/town?lang=${this.lang}`);
        if (status !== 200) {
            throw new Error('Error fetching towns');
        }
        return data.map(townModelToEntity);
    }
    async getTownActivities(townId: number): Promise<ActivityInfoEntity[]> {
        // TODO: get lang from user preferences
        // TODO: get townId from user preferences
        console.log('townId', townId);
        const {status, data} = await axios.get<ActivityModel[]>(API_URL + `/place/town/${townId}/place?lang=es`);
        const {status, data} = await axios.get<ActivityModel[]>(`${API_URL}/place/town/${townId}/place?lang=${this.lang}`);
        if (status !== 200) {
            throw new Error('Error fetching activities');
        }
@@ -41,7 +42,7 @@ export class StateDataSourceProd implements StateDataSource {
    async getActivityInfo(activityId: number): Promise<ActivityInfoEntity | undefined> {
        // TODO: get lang from user preferences
        // TODO: get townId from user preferences
        const {status, data} = await axios.get<ActivityModel>(API_URL + `/place/${activityId}`);
        const {status, data} = await axios.get<ActivityModel>(`${API_URL}/place/${activityId}?lang=${this.lang}`);
        if (status !== 200) {
            throw new Error('Error fetching activity');
        }