feat(daily recipe page): [A] 增加重新生成每日菜单接口

[A] 增加重新生成每日菜单接口

Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
Ching 2021-10-04 20:40:30 +08:00
parent 0cd1fd9358
commit 1b27f47771
3 changed files with 43 additions and 1 deletions

View File

@ -37,6 +37,14 @@
</template></el-table-column
>
</el-table>
<el-button
type="primary"
plain
class="re-generate"
@click="reGenerateRecipe()"
>
重新生成
</el-button>
</template>
<script>
@ -71,6 +79,35 @@ export default {
this.daily_recipe = [data];
});
},
methods: {
reGenerateRecipe() {
axios
.post('//localhost:8000/recipe/daily-recipe/' + this.$route.params.id)
.then((response) => {
response;
return axios.get(
'//localhost:8000/recipe/daily-recipe/' + this.$route.params.id
);
})
.then((response) => {
var data = {
meat: [],
vegetable: [],
soup: [],
};
for (let i = 0; i < response.data.recipes.length; i++) {
if (response.data.recipes[i].recipe_type == 'meat') {
data.meat.push(response.data.recipes[i]);
} else if (response.data.recipes[i].recipe_type == 'vegetable') {
data.vegetable.push(response.data.recipes[i]);
} else if (response.data.recipes[i].recipe_type == 'soup') {
data.soup.push(response.data.recipes[i]);
}
}
this.daily_recipe = [data];
});
},
},
};
</script>

View File

@ -41,7 +41,7 @@
>
</template></el-table-column
>
<el-table-column label="操作">
<el-table-column label="操作" width="80px">
<template #default="scope">
<el-button size="mini" @click="editDailyRecipe(scope.row)">
编辑

View File

@ -69,3 +69,8 @@ class DailyRecipeAPI(rest_framework.generics.RetrieveUpdateAPIView):
queryset = recipe.models.DailyRecipe.objects.all()
serializer_class = recipe.serializers.DailyRecipeSerializer
def post(self, request, *args, **kwargs):
daily_recipe = recipe.models.DailyRecipe.objects.get(id=kwargs['pk'])
daily_recipe.generate_recipe()
return Response({}, status=status.HTTP_201_CREATED, headers={})