Skip to content

Commit

Permalink
feat: frontend, backend
Browse files Browse the repository at this point in the history
frontend - using state management and api service create category api is called, backend - create category api response is updated
  • Loading branch information
rkshaon committed Jun 22, 2024
1 parent ae553b0 commit 8b3103b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
5 changes: 1 addition & 4 deletions backend/category_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ def create(self, request):

if serializer.is_valid():
serializer.save()
return Response({
'status': True,
'data': serializer.data,
}, status=status.HTTP_201_CREATED)
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response({
'status': False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<script>
import { Modal } from 'bootstrap';
import adminCategoryAPI from "@/services/adminCategoryAPI";
import { mapActions } from 'vuex';
export default {
name: 'AdminAddCategoryComponent',
Expand All @@ -51,9 +51,10 @@ export default {
}
},
methods: {
...mapActions('category', ['addCategory']),
showAddCategoryModal() {
const modalElement = this.$refs.addCategoryModal;
console.log(modalElement);
if (modalElement) {
const modal = new Modal(modalElement);
Expand All @@ -78,18 +79,12 @@ export default {
if (this.categoryForm.icon) {
formData.append('icon', this.categoryForm.icon);
}
console.log(formData);
try {
const response = await adminCategoryAPI.createCategoryForAdmin(formData);
console.log('Create...', response.data);
this.successMessage = 'Category created successfully!';
try {
const addedCategory = await this.addCategory(formData);
this.$emit('categoryAdded', addedCategory);
} catch (error) {
console.error('Failed...', error);
this.errorMessages.push({
'title': 'Create Category',
'message': 'Failed to create a new category.',
});
console.log('Failed:', error);
}
const modalElement = this.$refs.addCategoryModal;
Expand Down

0 comments on commit 8b3103b

Please sign in to comment.