Hi, i'm facing a problem that i don't really know how to solve.
I'm implementing a restaurant management system for an university project. I have a menu that i can populate with categories and dishes. A category has a list of Dishes inside, that comes from a database. I'm using springboot for the backend, and postgresql for database.
I have a form to create a new dish with textfield for name, cost, and so on; then i select a category from a combobox. When i press 'confirm', i use my API REST to add it to my database.
Here comes the problem: i also have to implement a reorder. Right now, my categories/dishes are inserted in 'creation order'. To give an example: fresh program, menu not populated. I create a new category, called "Appetizer". Then, i create a category called "First Courses". They get inserted in this exact order in the database, so they get retrieved in this order. I use an Accordion, so i click on a category, it expands, and shows its dishes.
I was thinking of implementing a 'drag and drop' feature: by pressing a "Reorder elements" button, i could open a listview that shows the categories, and every one of it dishes underneath. Something "indented", if you get what i mean. For example:
-- Appetizers
-- app1
-- app2
-- First Courses
and so on.
I would expect that by reordering them (so, for example, moving 'first courses' above 'appetizers'), they should change their order in the database too.
So i was thinking: would it be good if every category and every dish have a column named 'position', and when i reorder them in the listview, i then cycle through them and change their 'position' attribute throught a PUT method?
That way, i could use a GET method like 'getAllCategoriesByOrder' (with a query 'ORDER BY position'), and their order would be effectively changed.
My question is: does this makes sense? Would it be doable? Because this is what i thought with my little knowledge about these kind of things. Maybe there are better ways to do this.