Skip to content

Commit

Permalink
Remove From Grocery List Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Harin329 committed Apr 3, 2022
1 parent 609b82d commit a9485dc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions backend/app/route/grocery_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def read_grocery_list(user_id: str):
}

@router.put("/")
async def update_grocery_list(grocery_list_item_id: int, user_id: str, obtained_status: bool):
async def update_grocery_list(grocery_list_item_id: str, user_id: str, obtained_status: bool):
try:
conn, cursor = init_conn()
if user_id:
Expand All @@ -77,7 +77,7 @@ async def update_grocery_list(grocery_list_item_id: int, user_id: str, obtained_
}

@router.delete("/")
async def delete_grocery_list_item(grocery_list_item_id: int, user_id: str):
async def delete_grocery_list_item(grocery_list_item_id: str, user_id: str):
try:
conn, cursor = init_conn()
if user_id:
Expand Down
8 changes: 4 additions & 4 deletions database/sproc/groceryListSproc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ DELIMITER ;
DELIMITER $$

CREATE PROCEDURE `deleteGroceryListItem` (
IN `_grocery_list_item_id` INT,
IN `_grocery_list_item_id` VARCHAR(255),
IN `_user_id` VARCHAR(50)
) BEGIN
DELETE FROM `grocery_list_table`
WHERE `grocery_list_item_id` = `_grocery_list_item_id` AND `user_id` = `_user_id`;
WHERE `ingredient_id` = `_grocery_list_item_id` AND `user_id` = `_user_id`;

END $$

Expand All @@ -53,14 +53,14 @@ DELIMITER ;
DELIMITER $$

CREATE PROCEDURE `updateGroceryListObtainedStatus` (
IN `_grocery_list_item_id` INT,
IN `_grocery_list_item_id` VARCHAR(255),
IN `_user_id` VARCHAR(50),
IN `_obtained` BOOLEAN
) BEGIN

UPDATE `grocery_list_table`
SET `obtained` = `_obtained`
WHERE `grocery_list_item_id` = `_grocery_list_item_id` AND `user_id` = `_user_id`;
WHERE `ingredient_id` = `_grocery_list_item_id` AND `user_id` = `_user_id`;

END $$

Expand Down
9 changes: 2 additions & 7 deletions frontend/src/saga/groceryListSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,12 @@ function* addIngredientCall(param) {

function* removeIngredientCall(param) {
try {
const data = JSON.stringify({
user_id: param.payload.userID,
ingredient_id: param.payload.item.id,
});
const apiConfig = {
method: 'delete',
url: `${API_URL}/grocery_list`,
url: `${API_URL}/grocery_list?user_id=${param.payload.userID}&grocery_list_item_id=${param.payload.item.id}`,
headers: {
'Content-Type': 'application/json',
},
data,
};

const response = yield call(axios, apiConfig);
Expand Down Expand Up @@ -215,7 +210,7 @@ export function* addGroceryIngredient() {
yield takeLatest(ADD_GROCERY_INGREDIENT, addIngredientCall);
}

export function* removeIngredient() {
export function* removeGroceryIngredient() {
yield takeLatest(REMOVE_INGREDIENT, removeIngredientCall);
}

Expand Down
6 changes: 4 additions & 2 deletions frontend/src/saga/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
import {
getGroceryList,
addGroceryIngredient,
addRecipeIngredient
addRecipeIngredient,
removeGroceryIngredient,
} from './groceryListSaga';
import {
deleteRecipe,
Expand Down Expand Up @@ -53,6 +54,7 @@ export default function* rootSaga() {
fork(getMyNotifications),
fork(removeRecipeIngredient),
fork(addGroceryIngredient),
fork(addRecipeIngredient)
fork(addRecipeIngredient),
fork(removeGroceryIngredient)
]);
}
1 change: 0 additions & 1 deletion frontend/src/screens/tab2/groceryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {ADD_PANTRY_INGREDIENT} from '../../actions/pantryActions';
import {
// ADD_INGREDIENT,
GET_ALL_INGREDIENTS,
REMOVE_INGREDIENT,
SEARCH_INGREDIENTS,
} from '../../actions/groceryListActions';
import Alerts from '../../components/Alerts';
Expand Down

0 comments on commit a9485dc

Please sign in to comment.