Skip to content

Commit

Permalink
fix: made base api endpoint consistent between all services
Browse files Browse the repository at this point in the history
  • Loading branch information
DOOduneye committed Nov 27, 2023
1 parent 2469c6f commit da9b366
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 40 deletions.
12 changes: 6 additions & 6 deletions client-new/src/screens/app/SubTaskScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { IAction, IActionList } from '@/interfaces/IAction';
import { getActions } from '@/services/SubTaskService';
import { ENDPOINT } from '@/services/const';
import { API_BASE_URL } from '@/services/const';
import FormComponent from '@/utils/Actions';
import { Text } from 'native-base';

import { useEffect, useState } from 'react';
import React from 'react';
import { useQuery } from 'react-query';
import { useQuery } from '@tanstack/react-query';

const SubTaskScreen = ({ subtask_id }) => {
const [state, setState] = useState<IActionList>(null);
// props should include a id field

const { isLoading, error, data } = useQuery(
['fetchActions', subtask_id],
() => getActions(subtask_id)
);
const { isLoading, error, data } = useQuery({
queryKey: ['actions', subtask_id],
queryFn: () => getActions(subtask_id)
});

console.log('action fetched: ', data); // {"actions": [{"action_type": "input", "label": "Full Legal Name", "name": "full_name", "placeholder": "Enter your full legal name", "required": true, "type": "text"}, {"action_type": "input", "description": "Please enter your date of birth in the format: MM/DD/YYYY", "label": "Date of Birth", "name": "date_of_birth", "placeholder": "MM/DD/YYYY", "required": true, "type": "date"}, {"action_type": "input", "description": "Please provide your 9-digit social security number", "label": "Social Security Number", "name": "ssn", "placeholder": "Enter your social security number", "required": true, "type": "text"}, {"action_type": "input", "description": "Please provide your complete current residential address", "label": "Current Address", "name": "current_address", "placeholder": "Enter your current address", "required": true, "type": "text"}, {"action_type": "input", "description": "Please provide a valid phone number where you can be reached", "label": "Phone Number", "name": "phone_number", "placeholder": "Enter your phone number", "required": true, "type": "tel"}, {"action_type": "input", "description": "Please provide a valid email address for communication purposes", "label": "Email Address", "name": "email", "placeholder": "Enter your email address", "required": true, "type": "email"}, {"action_type": "select", "description": "Please select your current marital status from the options provided", "label": "Marital Status", "name": "marital_status", "options": [Array], "placeholder": "Select your marital status", "required": true}, {"action_type": "textarea", "description": "Feel free to provide any additional information or comments here", "label": "Additional Comments", "name": "additional_comments", "placeholder": "Enter any additional comments", "required": false}, {"action_type": "checkbox", "description": "Select the services you require", "label": "Select Services", "name": "services", "options": [Array], "required": true}, {"action_type": "radio", "description": "Select your preferred method of payment", "label": "Select Payment Method", "name": "payment_method", "options": [Array], "required": true}]}

Expand Down
22 changes: 6 additions & 16 deletions client-new/src/services/FileService.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { IFile } from '@/interfaces/IFile';
import axios from 'axios';
import { API_BASE_URL } from '@/services/const';

import { ENDPOINT } from './const';

export const getUserFilesList = (userId: number): Promise<IFile[]> => {
return new Promise((resolve, reject) => {
setTimeout(() => {
axios
.get<IFile[]>(`${ENDPOINT}/api/files/${userId}/user`)
.then((res) => {
resolve(res.data);
})
.catch((error) => {
reject(error.response.data);
});
});
});
};
export const getUserFilesList = async (userId: number): Promise<IFile[]> => {
const response = await axios.get(`${API_BASE_URL}/files/${userId}/user`);
return response.data;
// return response.status === 200 ? response.data : [];
};
7 changes: 3 additions & 4 deletions client-new/src/services/GuideService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import axios from 'axios';

import { IGuide } from '@/interfaces/IGuide';
import { sleep } from '@/utils/MockDelayUtil';

const API_BASE_URL = 'http://localhost:8080/api';
import { API_BASE_URL } from '@/services/const';

export const fetchAllGuides = async () => {
await sleep(1000)
await sleep(1000) // Simulate network delay
const response = await axios.get(`${API_BASE_URL}/guides/`);
return response.data as IGuide[];
}

export const fetchGuideByName = async (name: string) => {
await sleep(10000)
await sleep(10000) // Simulate network delay
const response = await axios.get(`${API_BASE_URL}/guides/${name}`);
return response.data as IGuide;
}
10 changes: 4 additions & 6 deletions client-new/src/services/PersonaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import axios from 'axios';

import { IPersona } from '../interfaces/IPersona';
import { IUser } from '../interfaces/IUser';
import { API_BASE_URL } from '@/services/const';

export const fetchUserPersona = async (user_id: number) => {
const response = await axios.get(
`http://localhost:8080/api/users/${user_id}/persona`
);

return response.data as IPersona;
export const fetchUserPersona = async (user_id: number): Promise<IPersona> => {
const response = await axios.get(`${API_BASE_URL}/users/${user_id}/persona`);
return response.data;
};
3 changes: 1 addition & 2 deletions client-new/src/services/ProfileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import axios from 'axios';

import { IOnboardingFlowState } from '../interfaces/IOnboardingFlowState';
import { IProfile } from '../interfaces/IProfile';

const API_BASE_URL = 'http://localhost:8080/api';
import { API_BASE_URL } from '@/services/const';

export const getProfile = async (user_id: string) => {
const response = await axios.get(`${API_BASE_URL}/users/${user_id}/profile`);
Expand Down
3 changes: 1 addition & 2 deletions client-new/src/services/SubTaskService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IAction, IActionList } from '@/interfaces/IAction';
import axios from 'axios';

import { ENDPOINT } from './const';
import { API_BASE_URL } from '@/services/const';

export const getActions = async (subtask_id: number) => {
try {
Expand Down
3 changes: 1 addition & 2 deletions client-new/src/services/TaskService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ITask } from '@/interfaces/ITask';
import axios from 'axios';

const API_BASE_URL = 'http://localhost:8080/api';
import { API_BASE_URL } from '@/services/const';

export const fetchAllUserTasks = async (userId: string) => {
const response = await axios.get(`${API_BASE_URL}/tasks/${userId}/user`);
Expand Down
2 changes: 1 addition & 1 deletion client-new/src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { z } from 'zod';
import { IProfile } from '@/interfaces/IProfile';
import { IUser } from '@/interfaces/IUser';

const API_BASE_URL = 'http://localhost:8080/api';
import { API_BASE_URL } from '@/services/const';

export const fetchUser = async (firebaseID: string): Promise<AxiosResponse<IUser>> => {
const response = await axios.get(`${API_BASE_URL}/users/firebase/${firebaseID}`);
Expand Down
6 changes: 5 additions & 1 deletion client-new/src/services/const.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const ENDPOINT = 'https://legacy.loca.lt';
/**
* API_BASE_URL is a constant that is used to determine the base URL for the API.
*/
export const API_BASE_URL = true ? 'http://localhost:8080/api' : 'https://legacy.loca.lt/api';

0 comments on commit da9b366

Please sign in to comment.