Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shared pantry feature #67

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.DS_Store
.env.local
.env.development.local
.env.development
.env.test.local
.env.production.local

Expand Down
6 changes: 6 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"serviceId": "grocery-be"
}
},
{
"source": "/api/pantry/**",
"run": {
"serviceId": "grocery-be"
}
},
{
"source": "/api/meal/**",
"run": {
Expand Down
8 changes: 6 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ server {
}

location /api/item {
proxy_pass http://grocery-be-service.grocery.svc.cluster.local:8000/api/item;
proxy_pass http://grocery-be-service.grocery.svc.cluster.local:8000/api;
}

location /api/pantry {
proxy_pass http://grocery-be-service.grocery.svc.cluster.local:8000/api;
}

location /api/meal {
proxy_pass http://food-track-be-service.grocery.svc.cluster.local:8080/api/meal;
proxy_pass http://food-track-be-service.grocery.svc.cluster.local:8080/api;
}
}
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-localization": "^1.0.19",
"react-qr-code": "^2.0.15",
"react-redux": "^9.1.2",
"react-router-dom": "^6.26.2",
"recharts": "^2.12.7",
Expand Down Expand Up @@ -64,4 +65,4 @@
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.3.2"
}
}
}
10 changes: 10 additions & 0 deletions src/action/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import {FoodConsumption} from "../model/foodConsumption";
import {User} from "../model/user";
import {ShoppingItem} from "../model/shoppingItem";
import {UnknownAction} from "redux";
import {Pantry} from "../model/pantry";

export interface CustomAction extends UnknownAction{
payload?: any;
}

export const SET_CURRENT_PANTRY_TYPE = "SET_CURRENT_PANTRY";

export const SET_CURRENT_ITEM_TYPE = "SET_CURRENT_ITEM";

export const SET_CURRENT_TRANSACTION_TYPE = "SET_CURRENT_TRANSACTION";
Expand Down Expand Up @@ -38,6 +41,13 @@ export const SET_CURRENT_MEAL_DATE_TYPE = "SET_CURRENT_MEAL_DATE";
export const SET_LANGUAGE_TYPE = "SET_LANGUAGE";


export const setCurrentPantry = (pantry?: Pantry): CustomAction => {
return {
type: SET_CURRENT_PANTRY_TYPE,
payload: pantry
};
}

export const setCurrentItem = (item?: Item): CustomAction => {
return {
type: SET_CURRENT_ITEM_TYPE,
Expand Down
40 changes: 20 additions & 20 deletions src/api/itemApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const addShoppingItemList = async (shoppingItemList: ShoppingItem[], cont
return baseResponse.body;
}

export const getAllItems = async (onlyAvailable: boolean = false, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/?onlyAvailable=${onlyAvailable}`;
export const getAllItems = async (onlyAvailable: boolean = false, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/?onlyAvailable=${onlyAvailable}&pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.get(url, {
headers: {
Expand All @@ -62,8 +62,8 @@ export const getAllItems = async (onlyAvailable: boolean = false, userid: string
return baseResponse.body;
}

export const getItemStatistics = async (userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/statistics`;
export const getItemStatistics = async (pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/statistics?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.get(url, {
headers: {
Expand All @@ -78,8 +78,8 @@ export const getItemStatistics = async (userid: string, controller: AbortControl
return baseResponse.body;
}

export const getItemDetail = async (itemId: string, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/detail`;
export const getItemDetail = async (itemId: string, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/detail?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.get(url, {
headers: {
Expand All @@ -94,8 +94,8 @@ export const getItemDetail = async (itemId: string, userid: string, controller:
return baseResponse.body;
}

export const updateItem = async (item: Item, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/${item.id}`;
export const updateItem = async (item: Item, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${item.id}?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.patch(url, item, {
headers: {
Expand All @@ -110,8 +110,8 @@ export const updateItem = async (item: Item, userid: string, controller: AbortCo
return baseResponse.body;
}

export const deleteItem = async (id: string, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/${id}`;
export const deleteItem = async (id: string, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${id}?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.delete(url, {
headers: {
Expand All @@ -126,8 +126,8 @@ export const deleteItem = async (id: string, userid: string, controller: AbortCo
return baseResponse.body;
}

export const getFoodKcal = async (foodId: string, quantity: number, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/${foodId}/kcal?quantity=${quantity}`;
export const getFoodKcal = async (foodId: string, quantity: number, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${foodId}/kcal?quantity=${quantity}?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.get(url, {
headers: {
Expand All @@ -142,8 +142,8 @@ export const getFoodKcal = async (foodId: string, quantity: number, userid: stri
return baseResponse.body;
}

export const addTransactionToItem = async (itemId: string, transaction: Transaction, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction`;
export const addTransactionToItem = async (itemId: string, transaction: Transaction, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.post(url, transaction, {
headers: {
Expand All @@ -158,8 +158,8 @@ export const addTransactionToItem = async (itemId: string, transaction: Transact
return baseResponse.body;
}

export const getAllItemTransaction = async (itemId: string, onlyAvailable: boolean = false, userId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction?onlyAvailable=${onlyAvailable}`;
export const getAllItemTransaction = async (itemId: string, onlyAvailable: boolean = false, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction?onlyAvailable=${onlyAvailable}&pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.get(url, {
headers: {
Expand All @@ -174,8 +174,8 @@ export const getAllItemTransaction = async (itemId: string, onlyAvailable: boole
return baseResponse.body;
}

export const updateItemTransaction = async (itemId: string, transaction: Transaction, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction`;
export const updateItemTransaction = async (itemId: string, transaction: Transaction, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.patch(url, transaction, {
headers: {
Expand All @@ -190,8 +190,8 @@ export const updateItemTransaction = async (itemId: string, transaction: Transac
return baseResponse.body;
}

export const deleteItemTransaction = async (itemId: string, transactionId: string, userid: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction/${transactionId}`;
export const deleteItemTransaction = async (itemId: string, transactionId: string, pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/item/${itemId}/transaction/${transactionId}?pantryId=${pantryId}`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.delete(url, {
headers: {
Expand Down
18 changes: 9 additions & 9 deletions src/api/mealApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const getAllMeals = async (controller: AbortController) => {
return baseResponse.body;
}

export const getAllMealInDateRange = async (startDate: Date, endDate: Date, userid: string, controller: AbortController) => {
export const getAllMealInDateRange = async (startDate: Date, endDate: Date, controller: AbortController) => {
const formattedStartDate = format(new Date(startDate), "dd-MM-yyyy")
const formattedEndDate = format(new Date(endDate), "dd-MM-yyyy")
const url = `${baseUrl}/meal/?startRange=${formattedStartDate}&endRange=${formattedEndDate}`;
Expand All @@ -60,7 +60,7 @@ export const getAllMealInDateRange = async (startDate: Date, endDate: Date, user
return baseResponse.body;
}

export const getMealStatistics = async (userid: string, controller: AbortController) => {
export const getMealStatistics = async (controller: AbortController) => {
const url = `${baseUrl}/meal/statistics/`;
const token = await getFirebaseUserToken();
const axiosResponse = await axios.get(url, {
Expand All @@ -76,7 +76,7 @@ export const getMealStatistics = async (userid: string, controller: AbortControl
return baseResponse.body;
}

export const getMealStatisticsInDateRange = async (startDate: Date, endDate: Date, userid: string, controller: AbortController) => {
export const getMealStatisticsInDateRange = async (startDate: Date, endDate: Date, controller: AbortController) => {
const formattedStartDate = format(new Date(startDate), "dd-MM-yyyy")
const formattedEndDate = format(new Date(endDate), "dd-MM-yyyy")
const token = await getFirebaseUserToken();
Expand All @@ -94,7 +94,7 @@ export const getMealStatisticsInDateRange = async (startDate: Date, endDate: Dat
return baseResponse.body;
}

export const updateMeal = async (meal: Meal, userid: string, controller: AbortController) => {
export const updateMeal = async (meal: Meal, controller: AbortController) => {
const url = `${baseUrl}/meal/${meal.id}/`;
const token = await getFirebaseUserToken();
const axiosResponse = await axios.patch(url, meal, {
Expand All @@ -110,7 +110,7 @@ export const updateMeal = async (meal: Meal, userid: string, controller: AbortCo
return baseResponse.body;
}

export const deleteMeal = async (id: string, userid: string, controller: AbortController) => {
export const deleteMeal = async (id: string, controller: AbortController) => {
const url = `${baseUrl}/meal/${id}/`;
const token = await getFirebaseUserToken();
const axiosResponse = await axios.delete(url, {
Expand All @@ -126,7 +126,7 @@ export const deleteMeal = async (id: string, userid: string, controller: AbortCo
return baseResponse.body;
}

export const getMealFoodConsumptions = async (mealId: string, userid: string, controller: AbortController) => {
export const getMealFoodConsumptions = async (mealId: string, controller: AbortController) => {
const url = `${baseUrl}/meal/${mealId}/consumption/`;
const token = await getFirebaseUserToken();
const axiosResponse = await axios.get(url, {
Expand All @@ -142,7 +142,7 @@ export const getMealFoodConsumptions = async (mealId: string, userid: string, co
return baseResponse.body;
}

export const addMealFoodConsumption = async (mealId: string, foodConsumption: FoodConsumption, userid: string, controller: AbortController) => {
export const addMealFoodConsumption = async (mealId: string, foodConsumption: FoodConsumption, controller: AbortController) => {
const url = `${baseUrl}/meal/${mealId}/consumption/`;
const token = await getFirebaseUserToken();
const axiosResponse = await axios.post(
Expand All @@ -162,7 +162,7 @@ export const addMealFoodConsumption = async (mealId: string, foodConsumption: Fo
return baseResponse.body;
}

export const updateMealFoodConsumption = async (mealId: string, foodConsumption: FoodConsumption, userid: string, controller: AbortController) => {
export const updateMealFoodConsumption = async (mealId: string, foodConsumption: FoodConsumption, controller: AbortController) => {
const url = `${baseUrl}/meal/${mealId}/consumption/${foodConsumption.id}/`;
const token = await getFirebaseUserToken();
const axiosResponse = await axios.patch(url, foodConsumption, {
Expand All @@ -178,7 +178,7 @@ export const updateMealFoodConsumption = async (mealId: string, foodConsumption:
return baseResponse.body;
}

export const deleteMealFoodConsumption = async (mealId: string, foodConsumptionId: string, userid: string, controller: AbortController) => {
export const deleteMealFoodConsumption = async (mealId: string, foodConsumptionId: string, controller: AbortController) => {
const token = await getFirebaseUserToken();
const url = `${baseUrl}/meal/${mealId}/consumption/${foodConsumptionId}/`;
const axiosResponse = await axios.delete(url, {
Expand Down
57 changes: 57 additions & 0 deletions src/api/pantryApis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {getFirebaseUserToken} from "../utils/firebaseUtils";
import axios from "axios";
import {BaseResponse} from "../model/baseResponse";
import {Pantry} from "../model/pantry";

export const baseUrl = import.meta.env.VITE_BASE_URL

export const createPantry = async (pantry: Pantry, controller: AbortController) => {
const url = `${baseUrl}/pantry/`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.post(
url,
pantry,
{
headers: {
"Authorization": `Bearer ${token}`
},
signal: controller.signal,
}
);
const baseResponse: BaseResponse<Pantry> = axiosResponse.data;
return baseResponse.body;
}

export const getAllPantries = async (controller: AbortController) => {
const url = `${baseUrl}/pantry/`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.get(url, {
headers: {
"Authorization": `Bearer ${token}`
},
signal: controller.signal,
});
const baseResponse: BaseResponse<Pantry[]> = axiosResponse.data;
if (baseResponse.errorMessage !== null && baseResponse.errorMessage !== "") {
throw new Error(baseResponse.errorMessage);
}
return baseResponse.body;
}

export const addSharedPantry = async (pantryId: string, controller: AbortController) => {
const url = `${baseUrl}/pantry/${pantryId}/share`;
const token = await getFirebaseUserToken()
const axiosResponse = await axios.post(
url,
{},
{
headers: {
"Authorization": `Bearer ${token}`
},
signal: controller.signal,
}
);
const baseResponse: BaseResponse<Pantry> = axiosResponse.data;
return baseResponse.body;
}

6 changes: 3 additions & 3 deletions src/component/ChooseFoodComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {StepperComponentProps} from "../page/addFoodConsumption/AddFoodConsumpti
import {Button, Grid2, List, Paper} from "@mui/material";
import {SimpleItemRowComponent} from "./SimpleItemRowComponent";
import {setCurrentItem, setError} from "../action/Action";
import {getCurrentItem, getUser} from "../selector/Selector";
import {getCurrentItem, getCurrentPantry} from "../selector/Selector";
import {useFoodList} from "../hooks/useFoodList";
import {ListLoadingComponent} from "./ListLoadingComponent";
import {strings} from "../localization/strings";
Expand All @@ -15,10 +15,10 @@ import SearchComponent from "./SearchComponent";
const ChooseFoodComponent = (props: StepperComponentProps) => {
const dispatch = useDispatch();
const currentFood = useSelector(getCurrentItem);
const currentUser = useSelector(getUser);
const currentPantry = useSelector(getCurrentPantry);
const [search, setSearch] = useState("");

const foodList = useFoodList( true, currentUser?.id || "");
const foodList = useFoodList( true, currentPantry?.id || "");

const onFoodClicked = (item: Item) => {
dispatch(setCurrentItem(item));
Expand Down
Loading
Loading