-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
// }); | ||
// } | ||
// }, | ||
} | ||
} |