abstract merge function to handle all related models

This commit is contained in:
smilerz 2021-08-15 15:29:47 -05:00
parent 24a575c2d5
commit a605113b00
8 changed files with 455 additions and 90 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,12 @@
import json
import pytest
from django.urls import reverse
from django_scopes import scopes_disabled
from cookbook.models import Food, Ingredient
from django.contrib import auth
from django_scopes import scopes_disabled
from django.urls import reverse
from cookbook.models import Food, Ingredient, ShoppingList, ShoppingListEntry
# ------------------ IMPORTANT -------------------
#
@ -47,25 +49,54 @@ def obj_3(space_2):
@pytest.fixture()
def step_1_s1(obj_1, space_1):
def ing_1_s1(obj_1, space_1):
return Ingredient.objects.create(food=obj_1, space=space_1)
@pytest.fixture()
def step_2_s1(obj_2, space_1):
def ing_2_s1(obj_2, space_1):
return Ingredient.objects.create(food=obj_2, space=space_1)
@pytest.fixture()
def step_3_s2(obj_3, space_2):
def ing_3_s2(obj_3, space_2):
return Ingredient.objects.create(food=obj_3, space=space_2)
@pytest.fixture()
def step_1_1_s1(obj_1_1, space_1):
def ing_1_1_s1(obj_1_1, space_1):
return Ingredient.objects.create(food=obj_1_1, space=space_1)
@pytest.fixture()
def sle_1_s1(obj_1, u1_s1, space_1):
e = ShoppingListEntry.objects.create(food=obj_1)
s = ShoppingList.objects.create(created_by=auth.get_user(u1_s1), space=space_1, )
s.entries.add(e)
return e
@pytest.fixture()
def sle_2_s1(obj_2, u1_s1, space_1):
return ShoppingListEntry.objects.create(food=obj_2)
@pytest.fixture()
def sle_3_s2(obj_3, u1_s2, space_2):
e = ShoppingListEntry.objects.create(food=obj_3)
s = ShoppingList.objects.create(created_by=auth.get_user(u1_s2), space=space_2, )
s.entries.add(e)
return e
@pytest.fixture()
def sle_1_1_s1(obj_1_1, u1_s1, space_1):
e = ShoppingListEntry.objects.create(food=obj_1_1)
s = ShoppingList.objects.create(created_by=auth.get_user(u1_s1), space=space_1, )
s.entries.add(e)
return e
@pytest.mark.parametrize("arg", [
['a_u', 403],
['g1_s1', 403],
@ -264,7 +295,8 @@ def test_move(u1_s1, obj_1, obj_1_1, obj_1_1_1, obj_2, obj_3, space_1):
def test_merge(
u1_s1,
obj_1, obj_1_1, obj_1_1_1, obj_2, obj_3,
step_1_s1, step_2_s1, step_3_s2, step_1_1_s1,
ing_1_s1, ing_2_s1, ing_3_s2, ing_1_1_s1,
sle_1_s1, sle_2_s1, sle_3_s2, sle_1_1_s1,
space_1
):
with scopes_disabled():
@ -277,8 +309,13 @@ def test_merge(
assert obj_3.ingredient_set.count() == 1
assert obj_1_1.ingredient_set.count() == 1
assert obj_1_1_1.ingredient_set.count() == 0
assert obj_1.shoppinglistentry_set.count() == 1
assert obj_2.shoppinglistentry_set.count() == 1
assert obj_3.shoppinglistentry_set.count() == 1
assert obj_1_1.shoppinglistentry_set.count() == 1
assert obj_1_1_1.shoppinglistentry_set.count() == 0
# merge food with no children and no ingredient with another food, only HTTP put method should work
# merge food with no children and no ingredient/shopping list entry with another food, only HTTP put method should work
url = reverse(MERGE_URL, args=[obj_1_1_1.id, obj_2.id])
r = u1_s1.get(url)
assert r.status_code == 405
@ -301,8 +338,12 @@ def test_merge(
assert obj_2.ingredient_set.count() == 1
assert obj_3.ingredient_set.count() == 1
assert obj_1_1.ingredient_set.count() == 1
assert obj_1.shoppinglistentry_set.count() == 1
assert obj_2.shoppinglistentry_set.count() == 1
assert obj_3.shoppinglistentry_set.count() == 1
assert obj_1_1.shoppinglistentry_set.count() == 1
# merge food with children to another food
# merge food (with connected ingredient/shoppinglistentry) with children to another food
r = u1_s1.put(reverse(MERGE_URL, args=[obj_1.id, obj_2.id]))
assert r.status_code == 200
with scopes_disabled():
@ -314,6 +355,9 @@ def test_merge(
assert obj_2.ingredient_set.count() == 2
assert obj_3.ingredient_set.count() == 1
assert obj_1_1.ingredient_set.count() == 1
assert obj_2.shoppinglistentry_set.count() == 2
assert obj_3.shoppinglistentry_set.count() == 1
assert obj_1_1.shoppinglistentry_set.count() == 1
# attempt to merge with non-existent parent
r = u1_s1.put(

View File

@ -12,8 +12,8 @@ from django.contrib.auth.models import User
from django.contrib.postgres.search import TrigramSimilarity
from django.core.exceptions import FieldError, ValidationError
from django.core.files import File
from django.db.models import ManyToManyField, Q
from django.db.models.fields.related_descriptors import ManyToManyDescriptor
from django.db.models import Q
from django.db.models.fields.related import ForeignObjectRel
from django.http import FileResponse, HttpResponse, JsonResponse
from django_scopes import scopes_disabled
from django.shortcuts import redirect, get_object_or_404
@ -135,9 +135,63 @@ class FuzzyFilterMixin(ViewSetMixin):
return self.queryset
class TreeMixin(FuzzyFilterMixin):
class MergeMixin(ViewSetMixin): # TODO update Units to use merge API
@decorators.action(detail=True, url_path='merge/(?P<target>[^/.]+)', methods=['PUT'],)
@decorators.renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def merge(self, request, pk, target):
self.description = f"Merge {self.basename} onto target {self.basename} with ID of [int]."
try:
source = self.model.objects.get(pk=pk, space=self.request.space)
except (self.model.DoesNotExist):
content = {'error': True, 'msg': _(f'No {self.basename} with id {pk} exists')}
return Response(content, status=status.HTTP_400_BAD_REQUEST)
if int(target) == source.id:
content = {'error': True, 'msg': _('Cannot merge with the same object!')}
return Response(content, status=status.HTTP_403_FORBIDDEN)
else:
try:
target = self.model.objects.get(pk=target, space=self.request.space)
except (self.model.DoesNotExist):
content = {'error': True, 'msg': _(f'No {self.basename} with id {target} exists')}
return Response(content, status=status.HTTP_400_BAD_REQUEST)
try:
if target in source.get_descendants_and_self():
content = {'error': True, 'msg': _('Cannot merge with child object!')}
return Response(content, status=status.HTTP_403_FORBIDDEN)
for link in [field for field in source._meta.get_fields() if issubclass(type(field), ForeignObjectRel)]:
linkManager = getattr(source, link.get_accessor_name())
related = linkManager.all()
# link to foreign relationship could be OneToMany or ManyToMany
if link.one_to_many:
for r in related:
setattr(r, link.field.name, target)
r.save()
elif link.many_to_many:
for r in related:
getattr(r, link.field.name).add(target)
getattr(r, link.field.name).remove(source)
r.save()
else:
# a new scenario exists and needs to be handled
raise NotImplementedError
children = source.get_children().exclude(id=target.id)
for c in children:
c.move(target, 'sorted-child')
content = {'msg': _(f'{source.name} was merged successfully with {target.name}')}
source.delete()
return Response(content, status=status.HTTP_200_OK)
except Exception:
content = {'error': True, 'msg': _(f'An error occurred attempting to merge {source.name} with {target.name}')}
return Response(content, status=status.HTTP_400_BAD_REQUEST)
class TreeMixin(MergeMixin, FuzzyFilterMixin):
model = None
related_models = [{'model': None, 'field': None}]
schema = TreeSchema()
def get_queryset(self):
@ -202,57 +256,6 @@ class TreeMixin(FuzzyFilterMixin):
content = {'error': True, 'msg': _('An error occurred attempting to move ') + child.name}
return Response(content, status=status.HTTP_400_BAD_REQUEST)
@decorators.action(detail=True, url_path='merge/(?P<target>[^/.]+)', methods=['PUT'],)
@decorators.renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def merge(self, request, pk, target):
self.description = f"Merge {self.basename} onto target {self.basename} with ID of [int]."
try:
source = self.model.objects.get(pk=pk, space=self.request.space)
except (self.model.DoesNotExist):
content = {'error': True, 'msg': _(f'No {self.basename} with id {pk} exists')}
return Response(content, status=status.HTTP_404_NOT_FOUND)
if int(target) == source.id:
content = {'error': True, 'msg': _('Cannot merge with the same object!')}
return Response(content, status=status.HTTP_403_FORBIDDEN)
else:
try:
target = self.model.objects.get(pk=target, space=self.request.space)
except (self.model.DoesNotExist):
content = {'error': True, 'msg': _(f'No {self.basename} with id {target} exists')}
return Response(content, status=status.HTTP_404_NOT_FOUND)
try:
if target in source.get_descendants_and_self():
content = {'error': True, 'msg': _('Cannot merge with child object!')}
return Response(content, status=status.HTTP_403_FORBIDDEN)
for model in self.related_models:
if isinstance(getattr(model['model'], model['field']), ManyToManyDescriptor):
related = model['model'].objects.filter(**{model['field'] + "__id": source.id}, space=self.request.space)
else:
related = model['model'].objects.filter(**{model['field']: source}, space=self.request.space)
for r in related:
try:
getattr(r, model['field']).add(target)
getattr(r, model['field']).remove(source)
r.save()
except AttributeError:
setattr(r, model['field'], target)
r.save()
children = source.get_children().exclude(id=target.id)
for c in children:
c.move(target, 'sorted-child')
content = {'msg': _(f'{source.name} was merged successfully with {target.name}')}
source.delete()
return Response(content, status=status.HTTP_200_OK)
except Exception:
content = {'error': True, 'msg': _(f'An error occurred attempting to merge {source.name} with {target.name}')}
return Response(content, status=status.HTTP_400_BAD_REQUEST)
class UserNameViewSet(viewsets.ReadOnlyModelViewSet):
"""
@ -349,7 +352,6 @@ class SupermarketCategoryRelationViewSet(viewsets.ModelViewSet, StandardFilterMi
class KeywordViewSet(viewsets.ModelViewSet, TreeMixin):
queryset = Keyword.objects
model = Keyword
related_models = [{'model': Recipe, 'field': 'keywords'}]
serializer_class = KeywordSerializer
permission_classes = [CustomIsUser]
pagination_class = DefaultPagination
@ -368,7 +370,6 @@ class UnitViewSet(viewsets.ModelViewSet, FuzzyFilterMixin):
class FoodViewSet(viewsets.ModelViewSet, TreeMixin):
queryset = Food.objects
model = Food
related_models = [{'model': Ingredient, 'field': 'food'}]
serializer_class = FoodSerializer
permission_classes = [CustomIsUser]
pagination_class = DefaultPagination

View File

@ -137,6 +137,30 @@ export interface Food {
* @memberof Food
*/
supermarket_category?: FoodSupermarketCategory | null;
/**
*
* @type {string}
* @memberof Food
*/
image?: string;
/**
*
* @type {string}
* @memberof Food
*/
parent?: string;
/**
*
* @type {number}
* @memberof Food
*/
numchild?: number;
/**
*
* @type {string}
* @memberof Food
*/
numrecipe?: string;
}
/**
*
@ -403,11 +427,73 @@ export interface InlineResponse2001 {
previous?: string | null;
/**
*
* @type {Array<RecipeOverview>}
* @type {Array<Food>}
* @memberof InlineResponse2001
*/
results?: Array<Food>;
}
/**
*
* @export
* @interface InlineResponse2002
*/
export interface InlineResponse2002 {
/**
*
* @type {number}
* @memberof InlineResponse2002
*/
count?: number;
/**
*
* @type {string}
* @memberof InlineResponse2002
*/
next?: string | null;
/**
*
* @type {string}
* @memberof InlineResponse2002
*/
previous?: string | null;
/**
*
* @type {Array<RecipeOverview>}
* @memberof InlineResponse2002
*/
results?: Array<RecipeOverview>;
}
/**
*
* @export
* @interface InlineResponse2003
*/
export interface InlineResponse2003 {
/**
*
* @type {number}
* @memberof InlineResponse2003
*/
count?: number;
/**
*
* @type {string}
* @memberof InlineResponse2003
*/
next?: string | null;
/**
*
* @type {string}
* @memberof InlineResponse2003
*/
previous?: string | null;
/**
*
* @type {Array<SupermarketCategoryRelation>}
* @memberof InlineResponse2003
*/
results?: Array<SupermarketCategoryRelation>;
}
/**
*
* @export
@ -1692,6 +1778,30 @@ export interface StepFood {
* @memberof StepFood
*/
supermarket_category?: FoodSupermarketCategory | null;
/**
*
* @type {string}
* @memberof StepFood
*/
image?: string;
/**
*
* @type {string}
* @memberof StepFood
*/
parent?: string;
/**
*
* @type {number}
* @memberof StepFood
*/
numchild?: number;
/**
*
* @type {string}
* @memberof StepFood
*/
numrecipe?: string;
}
/**
*
@ -3927,10 +4037,15 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
},
/**
*
* @param {string} [query] Query string matched against food name.
* @param {number} [root] Return first level children of food with ID [int]. Integer 0 will return root foods.
* @param {number} [tree] Return all self and children of food with ID [int].
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listFoods: async (options: any = {}): Promise<RequestArgs> => {
listFoods: async (query?: string, root?: number, tree?: number, page?: number, pageSize?: number, options: any = {}): Promise<RequestArgs> => {
const localVarPath = `/api/food/`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
@ -3943,6 +4058,26 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
if (query !== undefined) {
localVarQueryParameter['query'] = query;
}
if (root !== undefined) {
localVarQueryParameter['root'] = root;
}
if (tree !== undefined) {
localVarQueryParameter['tree'] = tree;
}
if (page !== undefined) {
localVarQueryParameter['page'] = page;
}
if (pageSize !== undefined) {
localVarQueryParameter['page_size'] = pageSize;
}
setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
@ -4418,10 +4553,12 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
},
/**
*
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listSupermarketCategoryRelations: async (options: any = {}): Promise<RequestArgs> => {
listSupermarketCategoryRelations: async (page?: number, pageSize?: number, options: any = {}): Promise<RequestArgs> => {
const localVarPath = `/api/supermarket-category-relation/`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
@ -4434,6 +4571,14 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
if (page !== undefined) {
localVarQueryParameter['page'] = page;
}
if (pageSize !== undefined) {
localVarQueryParameter['page_size'] = pageSize;
}
setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
@ -4706,6 +4851,47 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
options: localVarRequestOptions,
};
},
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} target
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
mergeFood: async (id: string, target: string, food?: Food, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'id' is not null or undefined
assertParamExists('mergeFood', 'id', id)
// verify required parameter 'target' is not null or undefined
assertParamExists('mergeFood', 'target', target)
const localVarPath = `/api/food/{id}/merge/{target}/`
.replace(`{${"id"}}`, encodeURIComponent(String(id)))
.replace(`{${"target"}}`, encodeURIComponent(String(target)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Content-Type'] = 'application/json';
setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(food, localVarRequestOptions, configuration)
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {string} id A unique integer value identifying this keyword.
@ -4747,6 +4933,47 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
options: localVarRequestOptions,
};
},
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} parent
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
moveFood: async (id: string, parent: string, food?: Food, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'id' is not null or undefined
assertParamExists('moveFood', 'id', id)
// verify required parameter 'parent' is not null or undefined
assertParamExists('moveFood', 'parent', parent)
const localVarPath = `/api/food/{id}/move/{parent}/`
.replace(`{${"id"}}`, encodeURIComponent(String(id)))
.replace(`{${"parent"}}`, encodeURIComponent(String(parent)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Content-Type'] = 'application/json';
setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(food, localVarRequestOptions, configuration)
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {string} id A unique integer value identifying this keyword.
@ -7990,11 +8217,16 @@ export const ApiApiFp = function(configuration?: Configuration) {
},
/**
*
* @param {string} [query] Query string matched against food name.
* @param {number} [root] Return first level children of food with ID [int]. Integer 0 will return root foods.
* @param {number} [tree] Return all self and children of food with ID [int].
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async listFoods(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<Food>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.listFoods(options);
async listFoods(query?: string, root?: number, tree?: number, page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2001>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.listFoods(query, root, tree, page, pageSize, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
@ -8082,7 +8314,7 @@ export const ApiApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2001>> {
async listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2002>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
@ -8133,11 +8365,13 @@ export const ApiApiFp = function(configuration?: Configuration) {
},
/**
*
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async listSupermarketCategoryRelations(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<SupermarketCategoryRelation>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.listSupermarketCategoryRelations(options);
async listSupermarketCategoryRelations(page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2003>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.listSupermarketCategoryRelations(page, pageSize, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
@ -8221,6 +8455,18 @@ export const ApiApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.listViewLogs(options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} target
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async mergeFood(id: string, target: string, food?: Food, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Food>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.mergeFood(id, target, food, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {string} id A unique integer value identifying this keyword.
@ -8233,6 +8479,18 @@ export const ApiApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.mergeKeyword(id, target, keyword, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} parent
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async moveFood(id: string, parent: string, food?: Food, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Food>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.moveFood(id, parent, food, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {string} id A unique integer value identifying this keyword.
@ -9512,11 +9770,16 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
},
/**
*
* @param {string} [query] Query string matched against food name.
* @param {number} [root] Return first level children of food with ID [int]. Integer 0 will return root foods.
* @param {number} [tree] Return all self and children of food with ID [int].
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listFoods(options?: any): AxiosPromise<Array<Food>> {
return localVarFp.listFoods(options).then((request) => request(axios, basePath));
listFoods(query?: string, root?: number, tree?: number, page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2001> {
return localVarFp.listFoods(query, root, tree, page, pageSize, options).then((request) => request(axios, basePath));
},
/**
*
@ -9596,7 +9859,7 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2001> {
listRecipes(query?: string, keywords?: string, foods?: string, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2002> {
return localVarFp.listRecipes(query, keywords, foods, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options).then((request) => request(axios, basePath));
},
/**
@ -9641,11 +9904,13 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
},
/**
*
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listSupermarketCategoryRelations(options?: any): AxiosPromise<Array<SupermarketCategoryRelation>> {
return localVarFp.listSupermarketCategoryRelations(options).then((request) => request(axios, basePath));
listSupermarketCategoryRelations(page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2003> {
return localVarFp.listSupermarketCategoryRelations(page, pageSize, options).then((request) => request(axios, basePath));
},
/**
*
@ -9719,6 +9984,17 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
listViewLogs(options?: any): AxiosPromise<Array<ViewLog>> {
return localVarFp.listViewLogs(options).then((request) => request(axios, basePath));
},
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} target
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
mergeFood(id: string, target: string, food?: Food, options?: any): AxiosPromise<Food> {
return localVarFp.mergeFood(id, target, food, options).then((request) => request(axios, basePath));
},
/**
*
* @param {string} id A unique integer value identifying this keyword.
@ -9730,6 +10006,17 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
mergeKeyword(id: string, target: string, keyword?: Keyword, options?: any): AxiosPromise<Keyword> {
return localVarFp.mergeKeyword(id, target, keyword, options).then((request) => request(axios, basePath));
},
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} parent
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
moveFood(id: string, parent: string, food?: Food, options?: any): AxiosPromise<Food> {
return localVarFp.moveFood(id, parent, food, options).then((request) => request(axios, basePath));
},
/**
*
* @param {string} id A unique integer value identifying this keyword.
@ -11036,12 +11323,17 @@ export class ApiApi extends BaseAPI {
/**
*
* @param {string} [query] Query string matched against food name.
* @param {number} [root] Return first level children of food with ID [int]. Integer 0 will return root foods.
* @param {number} [tree] Return all self and children of food with ID [int].
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ApiApi
*/
public listFoods(options?: any) {
return ApiApiFp(this.configuration).listFoods(options).then((request) => request(this.axios, this.basePath));
public listFoods(query?: string, root?: number, tree?: number, page?: number, pageSize?: number, options?: any) {
return ApiApiFp(this.configuration).listFoods(query, root, tree, page, pageSize, options).then((request) => request(this.axios, this.basePath));
}
/**
@ -11193,12 +11485,14 @@ export class ApiApi extends BaseAPI {
/**
*
* @param {number} [page] A page number within the paginated result set.
* @param {number} [pageSize] Number of results to return per page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ApiApi
*/
public listSupermarketCategoryRelations(options?: any) {
return ApiApiFp(this.configuration).listSupermarketCategoryRelations(options).then((request) => request(this.axios, this.basePath));
public listSupermarketCategoryRelations(page?: number, pageSize?: number, options?: any) {
return ApiApiFp(this.configuration).listSupermarketCategoryRelations(page, pageSize, options).then((request) => request(this.axios, this.basePath));
}
/**
@ -11291,6 +11585,19 @@ export class ApiApi extends BaseAPI {
return ApiApiFp(this.configuration).listViewLogs(options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} target
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ApiApi
*/
public mergeFood(id: string, target: string, food?: Food, options?: any) {
return ApiApiFp(this.configuration).mergeFood(id, target, food, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @param {string} id A unique integer value identifying this keyword.
@ -11304,6 +11611,19 @@ export class ApiApi extends BaseAPI {
return ApiApiFp(this.configuration).mergeKeyword(id, target, keyword, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @param {string} id A unique integer value identifying this food.
* @param {string} parent
* @param {Food} [food]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ApiApi
*/
public moveFood(id: string, parent: string, food?: Food, options?: any) {
return ApiApiFp(this.configuration).moveFood(id, parent, food, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @param {string} id A unique integer value identifying this keyword.