COP4331-LargeGroupProject-Fall22 / backend

Backend for SmartChef project, see https://github.com/COP4331-LargeGroupProject-Fall22/SmartChef
0 stars 1 forks source link

Upd: shopping list logic #90

Closed mplekunov closed 1 year ago

mplekunov commented 1 year ago

Depends on #88

mplekunov commented 1 year ago

All sorting parameters except sortByRecipe have isReverse implemented which allows to do reverse of every sorting type.

Sorting methods:

  1. By Category (assigns items to categories and then sort categories themselves in lexicographical order) (e.g CatA: [ ], CatB: [ ], CatC: [ ], etc.)
  2. By Recipe
  3. By lexicographicalOrder (based on name)

Abstracted some similar sorting algorithms in the new BaseIngredientController class

mplekunov commented 1 year ago

isReverse for sortRecipe cannot be implemented as for right now because in this sorting key (property) of the object would be a number. As per https://tc39.es/ecma262/#sec-ordinaryownpropertykeys number properties are considered as indexes during Object.fromEntries conversion. Therefore the sorting applied before Object conversion will not be persistent.

nashirj commented 1 year ago

isReverse for sortRecipe cannot be implemented as for right now because in this sorting key (property) of the object would be a number. As per https://tc39.es/ecma262/#sec-ordinaryownpropertykeys number properties are considered as indexes during Object.fromEntries conversion. Therefore the sorting applied before Object conversion will not be persistent.

We discussed this over DM and our approach is to not convert to object before returning; the format of the response will be (afaiu) an array of arrays, where each nested array corresponds to a single item of the response. @mplekunov Can you type out a a sample response here so that it's clear what the frontend should expect?

mplekunov commented 1 year ago

isReverse for sortRecipe cannot be implemented as for right now because in this sorting key (property) of the object would be a number. As per https://tc39.es/ecma262/#sec-ordinaryownpropertykeys number properties are considered as indexes during Object.fromEntries conversion. Therefore the sorting applied before Object conversion will not be persistent.

We discussed this over DM and our approach is to not convert to object before returning; the format of the response will be (afaiu) an array of arrays, where each nested array corresponds to a single item of the response. @mplekunov Can you type out a a sample response here so that it's clear what the frontend should expect?

    "itemsWithRecipeID": [
        [
            "1",
            [
                {
                    "id": 184271,
                    "name": "B",
                    "category": "catA",
                    "quantityUnits": [
                        "g",
                        "kg"
                    ],
                    "quantity": {
                        "unit": "gas",
                        "value": 2
                    },
                    "recipeID": 1,
                    "itemID": "6379561ec592584f35a64f30"
                }
            ]
        ],
        [
            "2",
            [
                {
                    "id": 184270,
                    "name": "B",
                    "category": "catA",
                    "quantityUnits": [
                        "g",
                        "kg"
                    ],
                    "quantity": {
                        "unit": "gas",
                        "value": 2
                    },
                    "recipeID": 2,
                    "itemID": "6379553582a1557016d9a784"
                },
                {
                    "id": 184271,
                    "name": "B",
                    "category": "catA",
                    "quantityUnits": [
                        "g",
                        "kg"
                    ],
                    "quantity": {
                        "unit": "gas",
                        "value": 2
                    },
                    "recipeID": 2,
                    "itemID": "637955f6c592584f35a64f2f"
                }
            ]
        ]
    ],
    "itemsWithoutRecipeID": []
}
mplekunov commented 1 year ago

isReverse for sortRecipe cannot be implemented as for right now because in this sorting key (property) of the object would be a number. As per https://tc39.es/ecma262/#sec-ordinaryownpropertykeys number properties are considered as indexes during Object.fromEntries conversion. Therefore the sorting applied before Object conversion will not be persistent.

We discussed this over DM and our approach is to not convert to object before returning; the format of the response will be (afaiu) an array of arrays, where each nested array corresponds to a single item of the response. @mplekunov Can you type out a a sample response here so that it's clear what the frontend should expect?

    "itemsWithRecipeID": [
        [
            "1",
            [
                {
                    "id": 184271,
                    "name": "B",
                    "category": "catA",
                    "quantityUnits": [
                        "g",
                        "kg"
                    ],
                    "quantity": {
                        "unit": "gas",
                        "value": 2
                    },
                    "recipeID": 1,
                    "itemID": "6379561ec592584f35a64f30"
                }
            ]
        ],
        [
            "2",
            [
                {
                    "id": 184270,
                    "name": "B",
                    "category": "catA",
                    "quantityUnits": [
                        "g",
                        "kg"
                    ],
                    "quantity": {
                        "unit": "gas",
                        "value": 2
                    },
                    "recipeID": 2,
                    "itemID": "6379553582a1557016d9a784"
                },
                {
                    "id": 184271,
                    "name": "B",
                    "category": "catA",
                    "quantityUnits": [
                        "g",
                        "kg"
                    ],
                    "quantity": {
                        "unit": "gas",
                        "value": 2
                    },
                    "recipeID": 2,
                    "itemID": "637955f6c592584f35a64f2f"
                }
            ]
        ]
    ],
    "itemsWithoutRecipeID": []
}

where 1 and 2 are recipeIDs