Skip to content

Commit

Permalink
working search with flat endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Feb 29, 2024
1 parent e47bdd0 commit 1cac34d
Show file tree
Hide file tree
Showing 143 changed files with 14,791 additions and 6,160 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ data/

/docker-compose.override.yml
vue/node_modules
plugins
/recipes/plugins
.vscode/
vetur.config.js
cookbook/static/vue
Expand Down
43 changes: 24 additions & 19 deletions cookbook/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,25 +593,26 @@ def get_serializer_class(self):
return FoodSimpleSerializer
return self.serializer_class

@decorators.action(detail=True, methods=['PUT'], serializer_class=FoodShoppingUpdateSerializer, )
# TODO DRF only allows one action in a decorator action without overriding get_operation_id_base() this should be PUT and DELETE probably
def shopping(self, request, pk):
if self.request.space.demo:
raise PermissionDenied(detail='Not available in demo', code=None)
obj = self.get_object()
shared_users = list(self.request.user.get_shopping_share())
shared_users.append(request.user)
if request.data.get('_delete', False) == 'true':
ShoppingListEntry.objects.filter(food=obj, checked=False, space=request.space, created_by__in=shared_users).delete()
content = {'msg': _(f'{obj.name} was removed from the shopping list.')}
return Response(content, status=status.HTTP_204_NO_CONTENT)

amount = request.data.get('amount', 1)
unit = request.data.get('unit', None)
content = {'msg': _(f'{obj.name} was added to the shopping list.')}

ShoppingListEntry.objects.create(food=obj, amount=amount, unit=unit, space=request.space, created_by=request.user)
return Response(content, status=status.HTTP_204_NO_CONTENT)
# TODO I could not find any usage of this and it causes schema generation issues, so commenting it for now
# @decorators.action(detail=True, methods=['PUT'], serializer_class=FoodShoppingUpdateSerializer, )
# # TODO DRF only allows one action in a decorator action without overriding get_operation_id_base() this should be PUT and DELETE probably
# def shopping(self, request, pk):
# if self.request.space.demo:
# raise PermissionDenied(detail='Not available in demo', code=None)
# obj = self.get_object()
# shared_users = list(self.request.user.get_shopping_share())
# shared_users.append(request.user)
# if request.data.get('_delete', False) == 'true':
# ShoppingListEntry.objects.filter(food=obj, checked=False, space=request.space, created_by__in=shared_users).delete()
# content = {'msg': _(f'{obj.name} was removed from the shopping list.')}
# return Response(content, status=status.HTTP_204_NO_CONTENT)
#
# amount = request.data.get('amount', 1)
# unit = request.data.get('unit', None)
# content = {'msg': _(f'{obj.name} was added to the shopping list.')}
#
# ShoppingListEntry.objects.create(food=obj, amount=amount, unit=unit, space=request.space, created_by=request.user)
# return Response(content, status=status.HTTP_204_NO_CONTENT)

@decorators.action(detail=True, methods=['POST'], )
def fdc(self, request, pk):
Expand Down Expand Up @@ -1089,8 +1090,12 @@ def related(self, request, pk):
qs = obj.get_related_recipes(levels=levels) # TODO: make levels a user setting, included in request data?, keep solely in the backend?
return Response(self.serializer_class(qs, many=True).data)

@extend_schema(
responses=RecipeFlatSerializer(many=True)
)
@decorators.action(
detail=False,
pagination_class=None,
methods=['GET'],
serializer_class=RecipeFlatSerializer,
)
Expand Down
5 changes: 2 additions & 3 deletions vue3/src/components/inputs/GlobalSearchDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ export default defineComponent({
})
const api = new ApiApi()
api.flatRecipe().then(r => {
console.log(r)
this.flat_recipes = [] // TODO fix API schema generation to generate valid API response (schema type array)
api.apiRecipeFlatList().then(r => {
this.flat_recipes = r
})
},
methods: {
Expand Down
117 changes: 61 additions & 56 deletions vue3/src/openapi/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apis/ApiApi.ts
apis/ApiImportOpenDataApi.ts
apis/ApiTokenAuthApi.ts
apis/OpenapiApi.ts
apis/index.ts
index.ts
models/AccessToken.ts
Expand All @@ -10,99 +11,103 @@ models/BookmarkletImport.ts
models/BookmarkletImportList.ts
models/ConnectorConfigConfig.ts
models/CookLog.ts
models/CookLogCreatedBy.ts
models/CustomFilter.ts
models/CustomFilterSharedInner.ts
models/DefaultPageEnum.ts
models/ExportLog.ts
models/Food.ts
models/FoodInheritField.ts
models/FoodInheritFieldsInner.ts
models/FoodPropertiesFoodUnit.ts
models/FoodPropertiesInner.ts
models/FoodPropertiesInnerPropertyType.ts
models/FoodRecipe.ts
models/FoodShoppingUpdate.ts
models/FoodSubstituteInner.ts
models/FoodSupermarketCategory.ts
models/FoodSimple.ts
models/Group.ts
models/ImportLog.ts
models/ImportLogKeyword.ts
models/Ingredient.ts
models/IngredientFood.ts
models/InviteLink.ts
models/InviteLinkGroup.ts
models/Keyword.ts
models/ListAutomations200Response.ts
models/ListCookLogs200Response.ts
models/ListCustomFilters200Response.ts
models/ListExportLogs200Response.ts
models/ListFoods200Response.ts
models/ListImportLogs200Response.ts
models/ListIngredients200Response.ts
models/ListKeywords200Response.ts
models/ListRecipes200Response.ts
models/ListSteps200Response.ts
models/ListSupermarketCategoryRelations200Response.ts
models/ListSyncLogs200Response.ts
models/ListUnits200Response.ts
models/ListUserSpaces200Response.ts
models/ListViewLogs200Response.ts
models/KeywordLabel.ts
models/MealPlan.ts
models/MealPlanMealType.ts
models/MealPlanRecipe.ts
models/MealPlanRecipeKeywordsInner.ts
models/MealType.ts
models/OpenDataCategory.ts
models/OpenDataConversion.ts
models/OpenDataConversionFood.ts
models/OpenDataConversionFoodPreferredUnitMetric.ts
models/OpenDataConversionFoodPropertiesFoodUnit.ts
models/OpenDataConversionFoodPropertiesInner.ts
models/OpenDataConversionFoodPropertiesInnerProperty.ts
models/OpenDataFood.ts
models/OpenDataProperty.ts
models/OpenDataStore.ts
models/OpenDataStoreCategoryToStoreInner.ts
models/OpenDataStoreCategoryToStoreInnerCategory.ts
models/OpenDataUnit.ts
models/OpenDataUnitVersion.ts
models/OpenDataVersion.ts
models/MethodEnum.ts
models/NutritionInformation.ts
models/PaginatedAutomationList.ts
models/PaginatedCookLogList.ts
models/PaginatedCustomFilterList.ts
models/PaginatedExportLogList.ts
models/PaginatedFoodList.ts
models/PaginatedImportLogList.ts
models/PaginatedIngredientList.ts
models/PaginatedKeywordList.ts
models/PaginatedRecipeOverviewList.ts
models/PaginatedStepList.ts
models/PaginatedSupermarketCategoryRelationList.ts
models/PaginatedSyncLogList.ts
models/PaginatedUnitList.ts
models/PaginatedUserSpaceList.ts
models/PaginatedViewLogList.ts
models/PatchedAccessToken.ts
models/PatchedAutomation.ts
models/PatchedBookmarkletImport.ts
models/PatchedConnectorConfigConfig.ts
models/PatchedCookLog.ts
models/PatchedCustomFilter.ts
models/PatchedExportLog.ts
models/PatchedFood.ts
models/PatchedImportLog.ts
models/PatchedIngredient.ts
models/PatchedInviteLink.ts
models/PatchedKeyword.ts
models/PatchedMealPlan.ts
models/PatchedMealType.ts
models/PatchedProperty.ts
models/PatchedPropertyType.ts
models/PatchedRecipe.ts
models/PatchedRecipeBook.ts
models/PatchedRecipeBookEntry.ts
models/PatchedShoppingListEntry.ts
models/PatchedShoppingListRecipe.ts
models/PatchedSpace.ts
models/PatchedStep.ts
models/PatchedStorage.ts
models/PatchedSupermarket.ts
models/PatchedSupermarketCategory.ts
models/PatchedSupermarketCategoryRelation.ts
models/PatchedSync.ts
models/PatchedUnit.ts
models/PatchedUnitConversion.ts
models/PatchedUser.ts
models/PatchedUserPreference.ts
models/PatchedUserSpace.ts
models/PatchedViewLog.ts
models/Property.ts
models/PropertyType.ts
models/Recipe.ts
models/RecipeBook.ts
models/RecipeBookEntry.ts
models/RecipeBookFilter.ts
models/RecipeFlat.ts
models/RecipeImage.ts
models/RecipeKeywordsInner.ts
models/RecipeNutrition.ts
models/RecipeOverview.ts
models/RecipeShoppingUpdate.ts
models/RecipeSimple.ts
models/RecipeStepsInner.ts
models/RecipeStepsInnerFile.ts
models/RecipeStepsInnerIngredientsInner.ts
models/ShoppingListEntry.ts
models/ShoppingListEntryBulk.ts
models/ShoppingListEntryRecipeMealplan.ts
models/ShoppingListRecipe.ts
models/Space.ts
models/SpaceNavTextColorEnum.ts
models/SpaceThemeEnum.ts
models/Step.ts
models/Storage.ts
models/Supermarket.ts
models/SupermarketCategory.ts
models/SupermarketCategoryRelation.ts
models/SupermarketCategoryToSupermarketInner.ts
models/SupermarketCategoryToSupermarketInnerCategory.ts
models/Sync.ts
models/SyncLog.ts
models/ThemeEnum.ts
models/TypeEnum.ts
models/Unit.ts
models/UnitConversion.ts
models/UnitConversionBaseUnit.ts
models/User.ts
models/UserFile.ts
models/UserFileView.ts
models/UserPreference.ts
models/UserPreferenceNavTextColorEnum.ts
models/UserSpace.ts
models/ViewLog.ts
models/index.ts
Loading

0 comments on commit 1cac34d

Please sign in to comment.