-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f79a9b
commit 652626f
Showing
28 changed files
with
1,651 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { errorOnGetSearchActivity, | ||
errorOnGetTrackedCaloriesBurned, | ||
errorOnPostAddActivity, errorOnDeleteRemoveActivity, | ||
errorOnPutTrackedCaloriesBurned | ||
} from "../errors/calories-burned.errors" | ||
|
||
// calories burned api requests | ||
|
||
// helper functions | ||
async function processSearchedActivity(trackedDayInfo, activityResults) { | ||
console.log(trackedDayInfo) | ||
|
||
return activityResults.map((activityResult) => { | ||
return { | ||
activity: String(activityResult.name), | ||
searchedActivity: String(trackedDayInfo.activity), | ||
dateTracked: String(trackedDayInfo.dateTracked), | ||
caloriesBurnedPerHour: Number(activityResult.calories_per_hour), | ||
durationMinutes: Number(activityResult.duration_minutes), | ||
totalCaloriesBurned: Number(activityResult.total_calories) | ||
} | ||
}) | ||
} | ||
|
||
// searching activity | ||
export async function getSearchActivity(trackedDayInfo) { | ||
try { | ||
let url = `${process.env.REACT_APP_API_NINJAS_CALORIES_BURNED_URL}${trackedDayInfo.activity}` | ||
|
||
if (trackedDayInfo.weightPounds !== "") { | ||
url = url + `&weight=${trackedDayInfo.weightPounds}` | ||
} | ||
if (trackedDayInfo.durationMinutes !== "") { | ||
url = url + `&duration=${trackedDayInfo.durationMinutes}` | ||
} | ||
|
||
const resActivityResults = await fetch(`${url}`, { | ||
method: "GET", | ||
headers: { | ||
"X-Api-Key": `${process.env.REACT_APP_API_NINJAS_KEY}` | ||
} | ||
}) | ||
|
||
const resJSON = await resActivityResults.json() | ||
const res = await processSearchedActivity(trackedDayInfo, resJSON) | ||
return res | ||
} catch (error) { | ||
errorOnGetSearchActivity() | ||
|
||
if (error) { | ||
return console.error("Request failed: ", error) | ||
} | ||
} | ||
} | ||
|
||
// signing in | ||
export async function getTrackedCaloriesBurned(userId, email) { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}`) | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}`) | ||
|
||
return response.json() | ||
} catch (error) { | ||
console.log(error) | ||
errorOnGetTrackedCaloriesBurned() | ||
} | ||
} | ||
|
||
// calories burned operations | ||
export async function postAddActivity(userId, email, trackedDayInfo, activityId) { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}/${process.env.REACT_APP_API_URL_POST_TRACKED_CALORIES_BURNED}`) | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}/${process.env.REACT_APP_API_URL_POST_TRACKED_CALORIES_BURNED}`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ | ||
dateTracked: trackedDayInfo.dateTracked, | ||
activity: trackedDayInfo.activity, | ||
durationMinutes: trackedDayInfo.durationMinutes, | ||
caloriesBurnedPerHour: trackedDayInfo.caloriesBurnedPerHour, | ||
totalCaloriesBurned: trackedDayInfo.totalCaloriesBurned, | ||
activityId: activityId | ||
}) | ||
}) | ||
|
||
console.log("resp") | ||
|
||
return response.status | ||
} catch (error) { | ||
console.log(error) | ||
errorOnPostAddActivity() | ||
} | ||
} | ||
|
||
export async function deleteRemoveActivity(userId, email, activityId) { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}/${process.env.REACT_APP_API_URL_DELETE_TRACKED_CALORIES_BURNED}`) | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}/${process.env.REACT_APP_API_URL_DELETE_TRACKED_CALORIES_BURNED}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "text/plain" | ||
}, | ||
body: String(activityId) | ||
}) | ||
|
||
console.log("removed") | ||
|
||
return response.status | ||
} catch (error) { | ||
console.log(error) | ||
errorOnDeleteRemoveActivity() | ||
} | ||
} | ||
|
||
// signing out | ||
export async function putTrackedCaloriesBurned(userId, email, trackedCaloriesBurned) { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}/${process.env.REACT_APP_API_URL_PUT_TRACKED_CALORIES_BURNED}`) | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_TRACKED_CALORIES_BURNED}/${userId}/${email}/${process.env.REACT_APP_API_URL_PUT_TRACKED_CALORIES_BURNED}`, { | ||
method: "PUT", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ | ||
trackedCaloriesBurned: trackedCaloriesBurned | ||
}) | ||
}) | ||
|
||
return response.status | ||
} catch (error) { | ||
console.log(error) | ||
errorOnPutTrackedCaloriesBurned() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { errorOnGetChatBotResponse } from "../errors/chatbot.errors"; | ||
|
||
// chatbot api requests | ||
|
||
// response | ||
export const getChatBotResponse = async (messageInput) => { | ||
try { | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_CHATBOT}`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "text/plain" | ||
}, | ||
body: String(messageInput) | ||
}) | ||
|
||
const { message } = await response.json() | ||
return message | ||
} catch (error) { | ||
console.log("Error getting chatbot response") | ||
errorOnGetChatBotResponse() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { errorOnGetNutrientPredictions } from "../errors/nutrient-predictor.errors"; | ||
|
||
// helper functions | ||
const processNutrientPredictions = async (nutrientPredictions) => { | ||
return nutrientPredictions.map((nutrientPrediction) => { | ||
return { | ||
name: nutrientPrediction.name, | ||
servingSizeG: nutrientPrediction.serving_size_g, | ||
calories: nutrientPrediction.calories, | ||
macronutrients: { | ||
carbohydratesTotalG: nutrientPrediction.carbohydrates_total_g, | ||
proteinG: nutrientPrediction.protein_g, | ||
fatTotalG: nutrientPrediction.fat_total_g, | ||
fatSaturatedG: nutrientPrediction.fat_saturated_g, | ||
}, | ||
micronutrients: { | ||
sodiumMG: nutrientPrediction.sodium_mg, | ||
potassiumMG: nutrientPrediction.potassium_mg, | ||
cholesterolMg: nutrientPrediction.cholesterol_mg, | ||
fiberG: nutrientPrediction.fiber_g, | ||
sugarG: nutrientPrediction.sugar_g | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// nutrient predictor api requests | ||
|
||
export const getMealPredictions = async (image) => { | ||
return "1 pound of steak with mashed potatoes and a can of sprite" | ||
}; | ||
|
||
export const getNutrientPredictions = async (mealDescription) => { | ||
try { | ||
const resNutrientPredictions = await fetch(`${process.env.REACT_APP_API_NINJAS_NUTRIENT_PREDICTOR_URL}${mealDescription}`, { | ||
method: "GET", | ||
headers: { | ||
"X-Api-Key": `${process.env.REACT_APP_API_NINJAS_KEY}` | ||
} | ||
}) | ||
|
||
const resJSON = await resNutrientPredictions.json() | ||
const res = await processNutrientPredictions(resJSON) | ||
console.log(res) | ||
return res | ||
} catch (error) { | ||
errorOnGetNutrientPredictions() | ||
|
||
if (error) { | ||
return console.error("Request failed: ", error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { errorOnGetNutritionTrackedDaysData, errorOnGetNutritionTrackedDaysSummaryData, | ||
errorOnPostNutritionTrackedDay, errorOnDeleteNutritionTrackedDay, errorOnPutNutritionTrackedDay, | ||
errorOnPutNutritionTrackedDays, errorOnPutNutritionTrackedDaysSummary } from "../errors/nutrition-tracker.errors"; | ||
|
||
// nutrition tracker api requests | ||
|
||
// sign in | ||
export const getNutritionTrackedDaysData = async (userId, email) => { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}`); | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}`); | ||
|
||
return response.json(); | ||
} catch (error) { | ||
console.log(error); | ||
errorOnGetNutritionTrackedDaysData(); | ||
} | ||
}; | ||
|
||
export const getNutritionTrackedDaysSummaryData = async (userId, email) => { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS_SUMMARY}/${userId}/${email}`); | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS_SUMMARY}/${userId}/${email}`); | ||
|
||
return response.json(); | ||
} catch (error) { | ||
console.log(error); | ||
errorOnGetNutritionTrackedDaysSummaryData(); | ||
} | ||
}; | ||
|
||
// nutrition tracked days operations | ||
export const postNutritionTrackedDay = async (userId, email, nutritionTrackedDay) => { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}/${process.env.REACT_APP_API_URL_POST_NUTRITION_TRACKED_DAY}`); | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}/${process.env.REACT_APP_API_URL_POST_NUTRITION_TRACKED_DAY}`, { | ||
method: 'POST', | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(nutritionTrackedDay) | ||
}); | ||
|
||
return response.status; | ||
} catch (error) { | ||
console.log(error); | ||
errorOnPostNutritionTrackedDay(); | ||
} | ||
}; | ||
|
||
export const deleteNutritionTrackedDay = async (userId, email, trackedDay) => { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}/${process.env.REACT_APP_API_URL_DELETE_NUTRITION_TRACKED_DAY}`) | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}/${process.env.REACT_APP_API_URL_DELETE_NUTRITION_TRACKED_DAY}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "text/plain" | ||
}, | ||
body: String(trackedDay) | ||
}) | ||
|
||
console.log("removed") | ||
|
||
return response.status | ||
} catch (error) { | ||
console.log(error) | ||
errorOnDeleteNutritionTrackedDay() | ||
} | ||
} | ||
|
||
export const putNutritionTrackedDay = async (userId, email, originalNutritionTrackedDay, updatedNutritionTrackedDay) => { | ||
try { | ||
const nutritionTrackedDayInfo = { | ||
originalNutritionTrackedDay: originalNutritionTrackedDay, | ||
updatedNutritionTrackedDay: updatedNutritionTrackedDay, | ||
} | ||
|
||
console.log(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}/${process.env.REACT_APP_API_URL_PUT_NUTRITION_TRACKED_DAY}`); | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}/${process.env.REACT_APP_API_URL_PUT_NUTRITION_TRACKED_DAY}`, { | ||
method: 'PUT', | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(nutritionTrackedDayInfo) | ||
}); | ||
|
||
return response.status; | ||
} catch (error) { | ||
console.log(error); | ||
errorOnPutNutritionTrackedDay(); | ||
} | ||
}; | ||
|
||
// sign out | ||
export const putNutritionTrackedDays = async (userId, email, nutritionTrackedDays) => { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}`); | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS}/${userId}/${email}`, { | ||
method: "PUT", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ | ||
nutritionTrackedDays: nutritionTrackedDays | ||
}) | ||
}); | ||
|
||
return response.status; | ||
} catch (error) { | ||
console.log(error); | ||
errorOnPutNutritionTrackedDays(); | ||
} | ||
}; | ||
|
||
export const putNutritionTrackedDaysSummary = async (userId, email, nutritionTrackedDaysSummary) => { | ||
try { | ||
console.log(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS_SUMMARY}/${userId}/${email}`); | ||
const response = await fetch(`${process.env.REACT_APP_API_URL_NUTRITION_TRACKED_DAYS_SUMMARY}/${userId}/${email}`, { | ||
method: "PUT", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ | ||
nutritionTrackedDaysSummary: nutritionTrackedDaysSummary | ||
}) | ||
}); | ||
|
||
return response.status; | ||
} catch (error) { | ||
console.log(error); | ||
errorOnPutNutritionTrackedDaysSummary(); | ||
} | ||
}; |
Oops, something went wrong.