mirror of
https://github.com/KevinMidboe/leifsopplevelser.git
synced 2025-10-29 09:40:21 +00:00
All api calls are now piped through utils script to easier control base url.
This commit is contained in:
@@ -34,6 +34,8 @@ import DayElement from '@/components/calendar/DayElement'
|
|||||||
import MonthSummary from '@/components/calendar/MonthSummary'
|
import MonthSummary from '@/components/calendar/MonthSummary'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
|
||||||
|
import { adventureList } from '@/utils/leifsbackend-api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { DayElement, MonthSummary },
|
components: { DayElement, MonthSummary },
|
||||||
props: {
|
props: {
|
||||||
@@ -95,8 +97,7 @@ export default {
|
|||||||
.then(events => this.populateCalendar(events))
|
.then(events => this.populateCalendar(events))
|
||||||
},
|
},
|
||||||
getEvents() {
|
getEvents() {
|
||||||
return fetch('http://localhost:5000/api/adventure')
|
return adventureList()
|
||||||
.then(resp => resp.json())
|
|
||||||
.then(events => {
|
.then(events => {
|
||||||
console.log('events', events)
|
console.log('events', events)
|
||||||
this.eventsFound = events;
|
this.eventsFound = events;
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ import VueGridLayout from 'vue-grid-layout';
|
|||||||
import ClickOutside from 'vue-click-outside'
|
import ClickOutside from 'vue-click-outside'
|
||||||
import EventForm from './EventForm'
|
import EventForm from './EventForm'
|
||||||
|
|
||||||
|
import { adventureById, createAdventure } from '@/utils/leifsbackend-api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
GridLayout: VueGridLayout.GridLayout,
|
GridLayout: VueGridLayout.GridLayout,
|
||||||
@@ -147,12 +149,11 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchById(id) {
|
fetchById(id) {
|
||||||
fetch('http://localhost:5000/api/adventure/' + id)
|
adventureById(id)
|
||||||
.then(resp => resp.json())
|
.then(data => {
|
||||||
.then(data => {
|
this.formData = data;
|
||||||
this.formData = data;
|
console.log('data', data)
|
||||||
console.log('data', data)
|
})
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
processForm: function() {
|
processForm: function() {
|
||||||
@@ -166,19 +167,7 @@ export default {
|
|||||||
mapboxData: this.selectedPlace
|
mapboxData: this.selectedPlace
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch('http://localhost:5000/api/adventure', {
|
createAdventure(data)
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data)
|
|
||||||
})
|
|
||||||
// axios.post('localhost:5000/api/adventure', {
|
|
||||||
// body: JSON.stringify(data)
|
|
||||||
// })
|
|
||||||
.then((resp) => console.log('response from posting to server:', resp))
|
|
||||||
.catch((error) => console.error('error from post request:', error))
|
|
||||||
},
|
},
|
||||||
processFile(event) {
|
processFile(event) {
|
||||||
this.files = event.target.files;
|
this.files = event.target.files;
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ import FormElementLocation from './form/FormElementLocation'
|
|||||||
import FormElementUpload from './form/FormElementUpload'
|
import FormElementUpload from './form/FormElementUpload'
|
||||||
import { dateToDayMonthYearDashed } from '@/utils/dates'
|
import { dateToDayMonthYearDashed } from '@/utils/dates'
|
||||||
|
|
||||||
|
import { createAdventure } from '@/utils/leifsbackend-api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
FormElementLocation,
|
FormElementLocation,
|
||||||
@@ -118,20 +120,7 @@ export default {
|
|||||||
console.log('Processing form to post to backend with data', data)
|
console.log('Processing form to post to backend with data', data)
|
||||||
|
|
||||||
|
|
||||||
fetch('http://localhost:5000/api/adventure', {
|
createAdventure(data)
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data)
|
|
||||||
})
|
|
||||||
|
|
||||||
// axios.post('localhost:5000/api/adventure', {
|
|
||||||
// body: JSON.stringify(data)
|
|
||||||
// })
|
|
||||||
.then((resp) => console.log('response from posting to server:', resp))
|
|
||||||
.catch((error) => console.error('error from post request:', error))
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ import Gallery from '@/components/Gallery'
|
|||||||
import MapView from '@/components/MapView'
|
import MapView from '@/components/MapView'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
|
||||||
|
import { locationByName } from '@/utils/leifsbackend-api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
Gallery, MapView
|
Gallery, MapView
|
||||||
@@ -74,12 +76,8 @@ export default {
|
|||||||
const id = this.$route.params.id;
|
const id = this.$route.params.id;
|
||||||
console.log('id found', id)
|
console.log('id found', id)
|
||||||
if (id) {
|
if (id) {
|
||||||
fetch('http://localhost:5000/api/adventure/' + id)
|
adventureById(id)
|
||||||
.then(resp => {
|
.then(data => this.eventData = data)
|
||||||
console.log('resp', resp)
|
|
||||||
resp.json()
|
|
||||||
})
|
|
||||||
.then(data => this.eventData = data)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -93,16 +91,12 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = new URL('http://localhost:5000/api/location')
|
locationByName(this.eventData.locationName)
|
||||||
url.search = new URLSearchParams({ name: this.eventData.locationName })
|
.then(data => {
|
||||||
|
this.mapboxData = data.mapboxData;
|
||||||
fetch(url)
|
this.showMap = true;
|
||||||
.then(resp => resp.json())
|
})
|
||||||
.then(data => {
|
.catch((err) => console.log('error fetching locations by name from server. Error:', err))
|
||||||
this.mapboxData = data.mapboxData;
|
|
||||||
this.showMap = true;
|
|
||||||
})
|
|
||||||
.catch((err) => console.log('error fetching locations by name from server. Error:', err))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ import GalleryText from '@/components/GalleryText'
|
|||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
|
|
||||||
|
import { imagesByAdventureId } from '@/utils/leifsbackend-api'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Gallery-Item',
|
name: 'Gallery-Item',
|
||||||
components: { GalleryImage, GalleryText },
|
components: { GalleryImage, GalleryText },
|
||||||
@@ -49,8 +52,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
fetch('http://localhost:5000/api/images/' + this.id)
|
imagesByAdventureId(this.id)
|
||||||
.then(resp => resp.json())
|
|
||||||
.then(images => {
|
.then(images => {
|
||||||
console.log('events', images)
|
console.log('events', images)
|
||||||
images.forEach(image => {
|
images.forEach(image => {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import EventPage from '@/components/EventPage'
|
|||||||
import Calendar from '@/components/Calendar'
|
import Calendar from '@/components/Calendar'
|
||||||
import Footer from '@/components/Footer'
|
import Footer from '@/components/Footer'
|
||||||
|
|
||||||
|
import { adventureList } from '@/utils/leifsbackend-api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { Header, EventPage, Calendar, Footer },
|
components: { Header, EventPage, Calendar, Footer },
|
||||||
data() {
|
data() {
|
||||||
@@ -41,13 +43,12 @@ export default {
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
fetchEvents() {
|
fetchEvents() {
|
||||||
fetch('http://localhost:5000/api/adventure')
|
adventureList()
|
||||||
.then(resp => resp.json())
|
.then((data) => {
|
||||||
.then((data) => {
|
console.log('response from fetch events', data)
|
||||||
console.log('response from fetch events', data)
|
this.events = data;
|
||||||
this.events = data;
|
})
|
||||||
})
|
.catch((error) => console.log('unable to fetch events from api; error message:', error))
|
||||||
.catch((error) => console.log('unable to fetch events from api; error message:', error))
|
|
||||||
},
|
},
|
||||||
navigate: function() {
|
navigate: function() {
|
||||||
console.log(this.$router)
|
console.log(this.$router)
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
|
|
||||||
|
import { createImages } from '@/utils/leifsbackend-api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -43,9 +45,11 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('formdata', formData)
|
console.log('formdata', formData)
|
||||||
axios.post('http://localhost:5000/api/upload/' + 1, formData, { onUploadProgress: progressEvent => console.log(100 * (progressEvent.loaded / progressEvent.totalSize))} )
|
createImages(formData, 1, this.progressEvent) // passes formData (fileList of images) and adventureId
|
||||||
.then((resp) => console.log('response from posting to server:', resp))
|
},
|
||||||
.catch((error) => console.error('error from post request:', error))
|
|
||||||
|
progressEvent(event) {
|
||||||
|
console.log(100 * (event.loaded / event.totalSize))
|
||||||
},
|
},
|
||||||
|
|
||||||
processFiles(event) {
|
processFiles(event) {
|
||||||
|
|||||||
68
src/utils/leifsbackend-api.js
Normal file
68
src/utils/leifsbackend-api.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
const BASE_URL = 'http://localhost:5000/api/'
|
||||||
|
|
||||||
|
function adventureList() {
|
||||||
|
const url = BASE_URL + 'adventure';
|
||||||
|
|
||||||
|
return fetch(url)
|
||||||
|
.then(resp => resp.json())
|
||||||
|
.catch(err => console.log('unable to fetch adventure.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function adventureById(id) {
|
||||||
|
const url = BASE_URL + 'adventure/' + id;
|
||||||
|
|
||||||
|
return fetch(url)
|
||||||
|
.then(resp => resp.json())
|
||||||
|
.catch(err => console.log('unable to fetch adventure.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAdventure(data) {
|
||||||
|
const url = BASE_URL + 'adventure';
|
||||||
|
const jsonBody = JSON.stringify(data);
|
||||||
|
const headers = {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
};
|
||||||
|
|
||||||
|
return fetch(url, { method: 'POST', headers: headers, body: jsonBody })
|
||||||
|
.then((resp) => console.log('response from posting to server:', resp))
|
||||||
|
.catch((error) => console.error('error from post request:', error))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function locationByName(locationName) {
|
||||||
|
let url = new URL(BASE_URL + 'location')
|
||||||
|
url.search = new URLSearchParams({ name: locationName })
|
||||||
|
|
||||||
|
return fetch(url)
|
||||||
|
.then(resp => resp.json())
|
||||||
|
.catch(err => console.log('unable to fetch location.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function imagesByAdventureId(adventureId) {
|
||||||
|
const url = BASE_URL + 'images/' + adventureId;
|
||||||
|
|
||||||
|
return fetch(url)
|
||||||
|
.then(resp => resp.json())
|
||||||
|
.catch(err => console.log('unable to fetch images.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function createImages(FileFormData, adventureId, progressEvent=undefined) {
|
||||||
|
const url = BASE_URL + 'upload/' + adventureId;
|
||||||
|
|
||||||
|
axios.post(url, FileFormData, { onUploadProgress: progressEvent } )
|
||||||
|
.then((resp) => console.log('response from posting to server:', resp))
|
||||||
|
.catch((error) => console.error('error from post request:', error))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export {
|
||||||
|
adventureList,
|
||||||
|
adventureById,
|
||||||
|
createAdventure,
|
||||||
|
locationByName,
|
||||||
|
imagesByAdventureId,
|
||||||
|
createImages
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user