Skip to content

Commit

Permalink
Merge pull request #353 from CodeForNagasaki/development
Browse files Browse the repository at this point in the history
#352 直近のデータから取得できるようにパラメータにソートを追加
  • Loading branch information
sugasaki authored Aug 25, 2021
2 parents 0012252 + 863e823 commit a3dac3f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pages/cards/_card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default {
},
async mounted() {
// 動的に最新情報を取得する
await this.$store.dispatch('GET_BODIK_JSONP')
// await this.$store.dispatch('GET_BODIK_JSONP')
},
head() {
const url = 'https://nagasaki.stopcovid19.jp'
Expand Down
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default Vue.extend({
async mounted() {
// 動的に最新情報を取得する
await sleep(50)
await this.$store.dispatch('GET_BODIK_JSONP')
// await this.$store.dispatch('GET_BODIK_JSONP')
},
head(): MetaInfo {
return {
Expand Down
11 changes: 7 additions & 4 deletions services/bodikApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ const nagasakiOtherInfoId = '438f03f1-0ee8-466d-a5d9-e874f5367507'

// Bodikからのデータ取得上限
const limit = 10000
const sort = '_id desc'

export const fetchNagasakiPrefectureTestedCases = () =>
callFetchJsonp(baseUrl, nagasakiPrefectureTestedCasesId, { limit })
callFetchJsonp(baseUrl, nagasakiPrefectureTestedCasesId, { limit, sort })
export const fetchNagasakiPrefectureConfirmedCases = () =>
callFetchJsonp(baseUrl, nagasakiPrefectureConfirmedCasesId, { limit })
callFetchJsonp(baseUrl, nagasakiPrefectureConfirmedCasesId, { limit, sort })
export const fetchNagasakiCityNews = () =>
callFetchJsonp(baseUrl, nagasakiCityNewsId, { limit })
export const fetchNagasakiOtherInfo = () =>
callFetchJsonp(baseUrl, nagasakiOtherInfoId, { limit })

export const axiosNagasakiPrefectureTestedCases = axios =>
axios.$get(baseUrl + nagasakiPrefectureTestedCasesId, { params: { limit } })
axios.$get(baseUrl + nagasakiPrefectureTestedCasesId, {
params: { limit, sort }
})
export const axiosNagasakiPrefectureConfirmedCases = axios =>
axios.$get(baseUrl + nagasakiPrefectureConfirmedCasesId, {
params: { limit }
params: { limit, sort }
})
export const axiosNagasakiCityNews = axios =>
axios.$get(baseUrl + nagasakiCityNewsId, { params: { limit } })
Expand Down
22 changes: 16 additions & 6 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,19 @@ export const actions = {
try {
const result1 = await bodikApi.axiosNagasakiPrefectureTestedCases($axios)
// console.log(result1, 'result1')
if (result1.result.records)
commit('setPrefectureTestedCases', result1.result.records)
if (result1.result.records) {
const result = result1.result.records.reverse()
commit('setPrefectureTestedCases', result)
}

const result2 = await bodikApi.axiosNagasakiPrefectureConfirmedCases(
$axios
)
// console.log(result2, 'result2')
if (result2.result.records)
commit('PrefectureConfirmedCases', result2.result.records)
if (result2.result.records) {
const result = result2.result.records.reverse()
commit('PrefectureConfirmedCases', result)
}

const newsRes = await bodikApi.axiosNagasakiCityNews($axios)
if (newsRes.result.records)
Expand All @@ -141,12 +145,18 @@ export const actions = {
// 長崎県新型コロナウイルス感染症検査実施数のロード
const result1 = await bodikApi.fetchNagasakiPrefectureTestedCases()
// console.log(result1, 'fetchNagasakiPrefectureTestedCases')
if (result1.records) commit('setPrefectureTestedCases', result1.records)
if (result1.records) {
const result = result1.records.reverse()
commit('setPrefectureTestedCases', result)
}

// 長崎県新型コロナウイルス感染症陽性患者発表情報のロード
await sleep(500)
const result2 = await bodikApi.fetchNagasakiPrefectureConfirmedCases()
if (result2.records) commit('PrefectureConfirmedCases', result2.records)
if (result2.records) {
const result = result2.recordsreverse()
commit('PrefectureConfirmedCases', result)
}

await sleep(500)
const newsRes = await bodikApi.fetchNagasakiCityNews()
Expand Down

0 comments on commit a3dac3f

Please sign in to comment.