Skip to content

Commit

Permalink
done: #124 - publisher search store
Browse files Browse the repository at this point in the history
  • Loading branch information
rkshaon committed Nov 28, 2024
1 parent eefa9c4 commit 2e07992
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 14 deletions.
28 changes: 14 additions & 14 deletions frontend/src/services/v1/publisherAPIService.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// src/services/v1/publisherAPIService.js

import api from "@/services/axiosInstance";
import api from '@/services/axiosInstance'

const API_BASE_URL = process.env.VUE_APP_BACKEND_URL;
const content = "publisher";
const version = "v1";
const API_BASE_URL = process.env.VUE_APP_BACKEND_URL
const content = 'publisher'
const version = 'v1'

export const searchV1Publishers = async (
query = "",
query = '',
page = 1,
pageSize = 8
) => {
page = page ?? 1;
pageSize = pageSize ?? 10;
page = page ?? 1
pageSize = pageSize ?? 10

const URL = `${API_BASE_URL}/${content}/${version}/?search=${encodeURIComponent(
query
)}`;
)}`

console.log("Search Publisher API:", URL);
console.log('Search Publisher API:', URL)

try {
const response = await api.get(URL);
return response.data;
const response = await api.get(URL)
return response.data
} catch (error) {
console.error("Error searching publishers:", error);
throw error;
console.error('Error searching publishers:', error)
throw error
}
};
}
93 changes: 93 additions & 0 deletions frontend/src/store/modules/publishers/publishers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// src/store/modules/publishers/publishers.js

import { searchV1Publisher } from '@/services/v1/publisherAPIService'

export default {
state: {
publishers: []
// searchResults: [],
// nextPageUrl: null,
// previousPageUrl: null,
// pageSize: 8,
// searchQuery: "",
// searchNextPageUrl: null,
// searchPreviousPageUrl: null,
},
getters: {
publishers: (state) => state.publishers,
// searchResults: (state) => state.searchResults,
// nextPageUrl: (state) => state.nextPageUrl,
// previousPageUrl: (state) => state.previousPageUrl,
// currentPageSize: (state) => state.pageSize,
searchQuery: (state) => state.searchQuery
// searchNextPageUrl: (state) => state.searchNextPageUrl,
// searchPreviousPageUrl: (state) => state.searchPreviousPageUrl,
},
mutations: {
SET_PUBLISHERS (state, publishers) {
state.publishers = publishers
},
// SET_NEXT_PAGE(state, url) {
// state.nextPageUrl = url;
// },
// SET_PREVIOUS_PAGE(state, url) {
// state.previousPageUrl = url;
// },
// SET_PAGE_SIZE(state, pageSize) {
// state.currentPageSize = pageSize;
// },
// SET_SEARCH_RESULTS(state, results) {
// state.searchResults = results;
// },
SET_SEARCH_QUERY (state, query) {
state.searchQuery = query
}
// SET_SEARCH_NEXT_PAGE(state, url) {
// state.searchNextPageUrl = url;
// },
// SET_SEARCH_PREVIOUS_PAGE(state, url) {
// state.searchPreviousPageUrl = url;
// },
},
actions: {
async searchBooks (
{ commit, state },
{ query, page = 1, pageSize = 8 } = {}
) {
commit('SET_SEARCH_QUERY', query)
try {
const response = await searchV1Publisher(query, page, pageSize)
// commit("SET_SEARCH_RESULTS", response.results);
// commit("SET_SEARCH_NEXT_PAGE", response.next);
// commit("SET_SEARCH_PREVIOUS_PAGE", response.previous);
console.log('Search Books:', response)
} catch (error) {
console.error('Error searching books:', error)
}
}
// async searchNextPage({ dispatch, state }) {
// if (state.searchNextPageUrl) {
// const nextPageNumber = new URL(
// state.searchNextPageUrl
// ).searchParams.get("page");
// await dispatch("searchBooks", {
// query: state.searchQuery,
// page: nextPageNumber,
// pageSize: state.pageSize,
// });
// }
// },
// async searchPreviousPage({ dispatch, state }) {
// if (state.searchPreviousPageUrl) {
// const previousPageNumber = new URL(
// state.searchPreviousPageUrl
// ).searchParams.get("page");
// await dispatch("searchBooks", {
// query: state.searchQuery,
// page: previousPageNumber,
// pageSize: state.pageSize,
// });
// }
// },
}
}

0 comments on commit 2e07992

Please sign in to comment.