diff --git a/frontend/src/services/v1/publisherAPIService.js b/frontend/src/services/v1/publisherAPIService.js index 963efab..711b40b 100644 --- a/frontend/src/services/v1/publisherAPIService.js +++ b/frontend/src/services/v1/publisherAPIService.js @@ -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 } -}; +} diff --git a/frontend/src/store/modules/publishers/publishers.js b/frontend/src/store/modules/publishers/publishers.js new file mode 100644 index 0000000..004c8c0 --- /dev/null +++ b/frontend/src/store/modules/publishers/publishers.js @@ -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, + // }); + // } + // }, + } +}