addToFavorite

This commit is contained in:
p11037 2023-11-24 10:55:09 +07:00
parent 725a999e9a
commit 0f8b04bf15
4 changed files with 280 additions and 337 deletions

View file

@ -34,7 +34,7 @@
/>
</v-avatar>
</template>
<v-list-item-title class="text-decoration-underline">{{nearestStructureData.lat}} , {{nearestStructureData.lon}}</v-list-item-title>
<v-list-item-title class="text-decoration-underline">{{nearestStructureData.lon}} , {{nearestStructureData.lat}}</v-list-item-title>
</v-list-item>
<v-list-item>
@ -52,7 +52,7 @@
</v-list>
<v-card-actions class="stick-bottom btnlist-height justify-sa">
<v-btn rounded="xl" variant="tonal" width="45vw" height="44px">
<v-btn @click="addToFavorites" rounded="xl" variant="tonal" width="45vw" height="44px">
เพมลงในสถานทโปรด</v-btn>
<v-btn @click="viewRoute" rounded="xl" variant="flat" class="text-white" width="45vw" height="44px" color="#f16322">
เสนทาง</v-btn>
@ -238,7 +238,7 @@ export default {
data() {
return {
showPopup: true,
showRoute: false,
showRoute: false
};
},
computed: {
@ -257,6 +257,36 @@ export default {
viewPopup(){
this.showPopup = true;
this.showRoute = false;
},
addToFavorites() {
console.log('on click');
fetch("https://little-lines-backend.techtransthai.org/api/favorites/create",{
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
user_id: '123456789',
place_name: this.nearestStructureData.display_name,
location: {
type: "Point",
coordinates: [parseFloat(this.nearestStructureData.lon), parseFloat(this.nearestStructureData.lat)]
},
wheelchair_access: 'Accessible',
highway_type: 'Highway'
})
})
.then((res) => {
if (res.ok) {
console.log('Add to favorites success');
return res.json();
} else {
throw Error(`Add to favorited faild (${res.status})`);
}
})
.catch((err) => {
console.log(err);
});
}
},

View file

@ -116,6 +116,8 @@ export default {
}
})
.then((data) => {
// localStorage.setItem('isLoggedIn', true);
// console.log(isLoggedIn);
console.log(data.success);
sessionStorage.setItem('current_user', data.user.username);
this.$router.push({ name: 'home' });