Skip to content

Integrate category CRUD APIs#249

Open
gTanusri wants to merge 4 commits into
rdodiya:gssoc_developfrom
gTanusri:codex/issue-230-category-crud
Open

Integrate category CRUD APIs#249
gTanusri wants to merge 4 commits into
rdodiya:gssoc_developfrom
gTanusri:codex/issue-230-category-crud

Conversation

@gTanusri
Copy link
Copy Markdown
Contributor

@gTanusri gTanusri commented Jun 1, 2026

Summary

  • Integrated the existing category UI with backend Category APIs.
  • Added active category listing with loading, empty/error handling, and refresh support.
  • Added edit and delete actions for categories in the sidebar list.
  • Reused the category modal for both create and update flows.
  • Added frontend validation, delete confirmation, and success/error toast feedback.

Issue

Closes #230

Validation

  • npm run build passes.
  • ./gradlew.bat compileJava passes.
  • git diff --check passes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates the admin Category UI (sidebar + modal) with the backend Category CRUD endpoints, enabling listing active categories and supporting edit/delete actions directly from the sidebar while reusing the same modal for create/update.

Changes:

  • Category sidebar now loads active categories from /secure/api/v1/categories/activecategories with loading/error states and manual refresh.
  • Added edit/delete actions for categories in the sidebar (including delete confirmation + toast feedback).
  • Reused the Category modal for both create and update, including basic client-side validation and toast messaging.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
RestroHub-FrontEnd/src/components/admin/menu/Menus.jsx Wires CategorySidebar edit flow into CategoryFormModal and triggers refreshes after modal close.
RestroHub-FrontEnd/src/components/admin/menu/menuCard/CategorySidebar.jsx Implements active category fetching, refresh, edit/delete actions, and UI states.
RestroHub-FrontEnd/src/components/admin/menu/menuCard/CategoryFormModal.jsx Adds edit support, form validation, and success/error feedback for create/update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to +84
const openEditCategoryModal = async (category) => {
try {
const response = await api.get(`/secure/api/v1/categories/${category.categoryId}`);
setEditingCategory(response.data?.data || response.data);
setIsCategoryModalOpen(true);
} catch (err) {
console.error('Failed to fetch category:', err.response?.data || err);
toast.error(err.response?.data?.message || 'Failed to load category details');
}
};
Comment on lines 86 to 91
const closeCategoryModal = () => {
setIsCategoryModalOpen(false);
setEditingCategory(null);
categorySidebarRef.current?.refreshCategories();
menuGridRef.current?.refreshFoods();
};
<div className="flex items-center gap-3">
<div className="w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center">
<Tag className="w-5 h-5 text-white" />
<Dialog open={isOpen} onClose={onClose} className="relative z-50">
Comment on lines 115 to 119
<button
type="button"
onClick={onClose}
className="flex-1 px-4 py-2.5 border border-gray-200 rounded-xl
hover:bg-gray-50 transition-colors font-medium text-gray-600"
>
Cancel
</button>
<button
type="submit"
disabled={submitting}
className="flex-1 flex items-center justify-center gap-2 px-4 py-2.5
bg-gradient-to-r from-blue-600 to-indigo-600 text-white
rounded-xl hover:from-blue-700 hover:to-indigo-700
transition-all font-semibold disabled:opacity-50
shadow-lg shadow-blue-600/25 hover:shadow-xl
hover:shadow-blue-600/30"
className="p-2 hover:bg-white/20 rounded-xl transition-colors"
>
@kashyapRathod03
Copy link
Copy Markdown
Collaborator

Hi @gTanusri,

Bug Fix Needed

1:
Issue: Category item counts in sidebar don't refresh when food items are added/deleted.

Fix: After food item operations (add/delete/edit), call categorySidebarRef.current?.refreshCategoryCounts() to update the counts in the sidebar.

Affected Files:

Menus.jsx - add refresh call in food item handlers
MenuFormModal.jsx - trigger refresh after save/delete

2:
SQL Injection / NoSQL Injection Vulnerability
File: CategorySidebar.jsx
[ await api.delete(/secure/api/v1/categories/delete/${category.categoryId});
await api.put(/secure/api/v1/categories/update/${editingCategory.categoryId}, payload); ]

Issue: Category IDs are directly interpolated into URLs without validation/sanitization. If a malicious user manipulates the categoryId object property, it could craft SQL/NoSQL injection payloads.
Fix: Validate that categoryId is a valid UUID/number before using it, or use parameterized queries on the backend.

Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Category CRUD UI Integration

4 participants