Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use json-big to parse main query response #24

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import axios from 'axios'
import JSONbig from 'json-big'

// Defines the API instance in Axios with special handling for big integers.
export const apiInstance = axios.create({
albireox marked this conversation as resolved.
Show resolved Hide resolved
baseURL: import.meta.env.VITE_API_URL,
timeout: 5000,
transformResponse: [
function transform(data) {
// Replacing the default transformResponse in axios because this uses JSON.parse and causes problems
// with precision of big numbers.
if (typeof data === 'string') {
try {
data = JSONbig.parse(data)
} catch (e) {
/* Ignore */
}
}
return data
}
]
})
14 changes: 6 additions & 8 deletions src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@

<script setup lang="ts">

import axios from 'axios'
import { ref, onMounted, watch } from 'vue'
import TextInput from '@/components/TextInput.vue'
import DropdownSelect from '@/components/DropdownSelect.vue';
import { useRouter } from 'vue-router';
import { useAppStore } from '@/store/app'
import { apiInstance } from '@/api'

// get the application state store and router
const store = useAppStore()
const router = useRouter()


// set up a form reference, is the name in v-form ref="form"
let form = ref(null);

Expand Down Expand Up @@ -163,13 +164,11 @@ async function submit_form(this: any) {
[formData.value.ra, formData.value.dec] = formData.value.coords ? formData.value.coords.split(',') : ["", ""]
console.log('submitting', formData.value)

// submit the POST request to Valis
await axios.post(import.meta.env.VITE_API_URL + '/query/main',
formData.value,
{headers: {'Content-Type': 'application/json'}})
await apiInstance.post('/query/main',
formData.value, {headers: {'Content-Type': 'application/json'}})
.then((response) => {
// handle the initial response
console.log(response.data)
console.log(response)

// check for good status in response
if (response.data['status'] != 'success') {
Expand Down Expand Up @@ -248,7 +247,7 @@ onMounted(() => {
}

// await the promises and cache the results in the store
Promise.all(endpoints.map((endpoint) => axios.get(endpoint)))
Promise.all(endpoints.map((endpoint) => apiInstance.get(endpoint)))
.then(([{data: carts}, {data: progs}, {data: progmap}] )=> {
console.log({ carts, progs, progmap })
store.store_cartons(carts, progs, progmap)
Expand Down Expand Up @@ -277,4 +276,3 @@ onMounted(() => {
// }, { immediate: true, deep: true })

</script>

23 changes: 4 additions & 19 deletions src/views/Target.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@

<script setup lang="ts">

import axios from 'axios'
import { useAppStore } from '@/store/app'
import { useRoute } from 'vue-router'
import { ref, onMounted } from 'vue'
import JSONbig from 'json-big'

import Solara from '@/components/Solara.vue'
import AladinLite from '@/components/AladinLite.vue'
import TargetResolver from '@/components/TargetResolver.vue'
import DataDownload from '@/components/DataDownload.vue'

import { apiInstance } from '@/api'

// get the application state store and router
const store = useAppStore()
const route = useRoute()
Expand Down Expand Up @@ -171,23 +171,8 @@ async function get_target_info() {
import.meta.env.VITE_API_URL + `/target/pipelines/${sdss_id}?release=${rel}`
albireox marked this conversation as resolved.
Show resolved Hide resolved
]

// axios config
// see https://axios-http.com/docs/req_config
const config = {
transformResponse: [function transform(data) {
// Replacing the default transformResponse in axios because this uses JSON.parse and causes problems
// with precision of big numbers.
if (typeof data === 'string') {
try {
data = JSONbig.parse(data);
} catch (e) { /* Ignore */ }
}
return data
}],
}

// await the promises
await Promise.all(endpoints.map((endpoint) => axios.get(endpoint, config)))
await Promise.all(endpoints.map((endpoint) => apiInstance.get(endpoint)))
.then(([{data: target}, {data: cartons}, {data: catalogs}, {data: pipes}] )=> {
console.log({ target, cartons, catalogs, pipes })
loading.value = false
Expand Down Expand Up @@ -225,7 +210,7 @@ async function get_db_info() {
return
}

await axios.get(import.meta.env.VITE_API_URL + '/info/database')
await apiInstance.get(import.meta.env.VITE_API_URL + '/info/database')
albireox marked this conversation as resolved.
Show resolved Hide resolved
.then((response) => {
console.log('db info', response.data)
// store the db metadata
Expand Down
Loading