How should I write the PATCH method that allows me to add and remove items of an array inside an array?
ItemClass:
export class ItemClass {
constructor(public person: string, public name: string, public quantity: number, public price: number){}
}
MenuModel:
import { ItemClass } from './item.model';
export class MenuModel {
id: number;
name: string;
items: ItemClass[];
constructor( id: number, name: string, items: ItemClass[]){
this.id = id;
this.name = name;
this.items = items;
}
}
I have a menu component and a menu service. I need a patch method that adds elements to the ItemClass[] array inside Menu and is able to remove them as well.
The API method looks like :
@PATCH
@Path("/add/{menuId}")
public void removeMenuItem(
@PathParam("menuId") final int menuId,
final Item item) { // Item represents the Request Body
final List<Item> items = this.menuRepository.get(menuId).getItems();
items.add(item);
}