Creating admin pages, new brand API endpoint
This commit is contained in:
7
software/src/data/api/brandApi.ts
Normal file
7
software/src/data/api/brandApi.ts
Normal 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)
|
||||
}
|
||||
@@ -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> = [""]
|
||||
}
|
||||
0
software/src/data/stores/brandStore.ts
Normal file
0
software/src/data/stores/brandStore.ts
Normal 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
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user