Creating admin pages, new brand API endpoint

This commit is contained in:
2024-09-25 15:42:05 +02:00
parent 6dd49f630d
commit 0856540441
28 changed files with 417 additions and 76 deletions

View File

@@ -0,0 +1,7 @@
import axios from "axios";
let BASE_URL = "http://localhost:3000/brands"
export async function getAllBrands() {
return await axios.get(BASE_URL)
}

View File

@@ -10,7 +10,8 @@ export class ProductModel {
price: number = 0
discount: number = 0
rating: number = 1
inStock: number
inStock: number = 0
offered: boolean = true
specs: Array<string> = []
images: Array<string> = [""]
}

View File

View File

@@ -1,25 +0,0 @@
import { useLocalStorage } from "@vueuse/core";
import { defineStore } from "pinia";
import { CategoryModel } from "../models/categoryModel";
import { getAllCategories } from "../api/categoryApi";
export const useCategoryStore = defineStore("categoryStore", {
state: () => ({
categories: useLocalStorage<Array<CategoryModel>>("hackmycart/categoryStore/categories", [])
}),
actions: {
async fetchAllCategories() {
await getAllCategories()
.then(categories => {
this.categories = categories.data
})
},
getProductById(id: number): CategoryModel {
return this.categories.find(category =>
category.id === id
)
}
}
})

View File

@@ -4,6 +4,9 @@ import { getAllProducts } from "../api/productApi";
import { SortOrder } from "../enums/sortOrderEnum";
import { CategoryModel } from "../models/categoryModel";
import { ProductModel } from "../models/productModel";
import { BrandModel } from "../models/brandModel";
import { getAllCategories } from "../api/categoryApi";
import { getAllBrands } from "../api/brandApi";
export const useProductStore = defineStore("productStore", {
@@ -12,7 +15,9 @@ export const useProductStore = defineStore("productStore", {
filteredProducts: useLocalStorage<Array<ProductModel>>("hackmycart/productStore/filteredProducts", []),
sortOrder: useLocalStorage<SortOrder>("hackmycart/productStore/sortOrder", SortOrder.NAMEATOZ),
filteredCategory: useLocalStorage<CategoryModel>("hackmycart/productStore/filteredCategory", new CategoryModel()),
onlyDiscounts: useLocalStorage<Boolean>("hackmycart/productStore/onlyDiscounts", false)
onlyDiscounts: useLocalStorage<Boolean>("hackmycart/productStore/onlyDiscounts", false),
brands: useLocalStorage<Array<BrandModel>>("hackmycart/productStore/brands", []),
categories: useLocalStorage<Array<CategoryModel>>("hackmycart/productStore/categories", [])
}),
actions: {
@@ -24,6 +29,20 @@ export const useProductStore = defineStore("productStore", {
})
},
async fetchAllCategories() {
await getAllCategories()
.then(categories => {
this.categories = categories.data
})
},
async fetchAllBrands() {
await getAllBrands()
.then(brands => {
this.brands = brands.data
})
},
async filterProducts() {
if (this.filteredCategory.id == -1 || this.filteredCategory.id == 0) {
this.filteredProducts = this.products