Commit addc6689 authored by Đinh Quang Vinh's avatar Đinh Quang Vinh

commit

parent d3b3f983
...@@ -21,18 +21,18 @@ ...@@ -21,18 +21,18 @@
<li> <li>
<router-link to="/" class="nav-link px-2 text-secondary">Dashboard</router-link> <router-link to="/" class="nav-link px-2 text-secondary">Dashboard</router-link>
</li> </li>
<li v-if="$store.state.isLoggedIn && $store.getters.currentUser.user.role == 'admin'"> <li>
<router-link to="/user-list" class="nav-link px-2 text-secondary">User list</router-link> <router-link to="/user-list" class="nav-link px-2 text-secondary">User list</router-link>
</li> </li>
<li v-if="$store.state.isLoggedIn" class="text-end"> <li class="text-end">
<button @click="$store.commit('logout')" class="btn btn-danger">Logout</button> <button @click="$store.commit('logout')" class="btn btn-danger">Logout</button>
</li> </li>
</ul> </ul>
</div> </div>
<div class="text-end"> <div class="text-end">
<router-link to="/login" v-if="!$store.state.isLoggedIn" <router-link to="/login"
class="btn btn-outline-light me-2">Login</router-link> class="btn btn-outline-light me-2">Login</router-link>
<router-link to="/register" v-if="!$store.state.isLoggedIn" class="btn btn-warning">Register</router-link> <router-link to="/register" class="btn btn-warning">Register</router-link>
</div> </div>
</div> </div>
</header> </header>
......
<template> <template>
<footer class="bg-dark text-white py-3"> <div class="bg-dark text-white py-3">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-12 col-md-6"> <div class="col-12 col-md-6">
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
</div> </div>
</div> </div>
</div> </div>
</footer> </div>
</template> </template>
<script> <script>
......
...@@ -16,5 +16,4 @@ export default { ...@@ -16,5 +16,4 @@ export default {
} }
</script> </script>
<style> <style></style>
</style>
import axios from 'axios'
const $axios = axios.create({
baseURL: 'http://localhost:8000/api',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('token')}`
}
})
export default $axios
...@@ -17,3 +17,4 @@ app.use(router).mount('#app') ...@@ -17,3 +17,4 @@ app.use(router).mount('#app')
import axios from "axios";
import router from "@/router"; import router from "@/router";
import axios from "../config";
const storeConfig = { const storeConfig = {
state: { state: {
isLoggedIn: false, isLoggedIn: false,
user: null, token: null,
}, },
mutations: { mutations: {
login(state, user) { login(state, token) {
state.isLoggedIn = true; state.isLoggedIn = true;
state.user = user; state.token = token;
localStorage.setItem('token', token)
localStorage.setItem('isLoggedIn', state.isLoggedIn)
}, },
logout(state) { logout(state) {
state.isLoggedIn = false; state.isLoggedIn = false
state.user = null; state.token = null
router.push("/login");
localStorage.removeItem('isLoggedIn')
localStorage.removeItem('token')
}, },
}, },
actions: { actions: {
async login({ commit }, { username, password }) { async login({ commit }, { username, password }) {
try { const response = await axios.post('auth/login', {
console.log("logging")
const response = await axios.post("http://127.0.0.1:8000/api/login", {
username, username,
password, password
}); })
const user = response.data; const token = response.data.access_token
commit("login", user); console.log(token)
router.push({ name: 'Dashboard' }) commit('login', token)
} catch (error) { router.push( '/' )
alert(error.response.data.error)
alert(error.response.data.message)
console.error(error.response.data);
}
}, },
logout({ commit }) { logout({ commit }) {
commit("logout"); commit("logout");
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<script> <script>
import { defineComponent, ref } from "vue"; import { defineComponent, ref } from "vue";
import axios from "axios"; import axios from '../config';
export default defineComponent({ export default defineComponent({
name: "BookingView", name: "BookingView",
...@@ -58,7 +58,7 @@ export default defineComponent({ ...@@ -58,7 +58,7 @@ export default defineComponent({
* @return {void} * @return {void}
*/ */
const getBooking = async () => { const getBooking = async () => {
const response = await axios.get("http://127.0.0.1:8000/api/booking"); const response = await axios.get("booking");
bookings.value = response.data; bookings.value = response.data;
}; };
...@@ -72,7 +72,7 @@ export default defineComponent({ ...@@ -72,7 +72,7 @@ export default defineComponent({
const checkin = async (id) => { const checkin = async (id) => {
console.log(id); console.log(id);
try { try {
const response = await axios.post("http://127.0.0.1:8000/api/checked", { const response = await axios.post("checked", {
id: id, id: id,
}); });
console.log(response.data); console.log(response.data);
...@@ -93,7 +93,7 @@ export default defineComponent({ ...@@ -93,7 +93,7 @@ export default defineComponent({
console.log(id); console.log(id);
try { try {
const response = await axios.delete( const response = await axios.delete(
"http://127.0.0.1:8000/api/checked/delBook", "checked/delBook",
{ {
data: { data: {
id: id, id: id,
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<td> <td>
<form @submit.prevent="addFee(checkin.id)"> <form @submit.prevent="addFee(checkin.id)">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" v-model="fee" name="fee" id="fee" placeholder="Fee"> <input type="text" class="form-control" v-model="checkin.id" name="fee" id="fee" placeholder="Fee">
<button type="submit" class="btn btn-secondary"> <button type="submit" class="btn btn-secondary">
<i class="bi bi-currency-dollar"></i> Submit <i class="bi bi-currency-dollar"></i> Submit
</button> </button>
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<script> <script>
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import axios from 'axios' import axios from '../config'
export default defineComponent({ export default defineComponent({
name: 'CheckinView', name: 'CheckinView',
...@@ -67,7 +67,7 @@ export default defineComponent({ ...@@ -67,7 +67,7 @@ export default defineComponent({
* @return {void} * @return {void}
*/ */
const getCheckin = async () => { const getCheckin = async () => {
const response = await axios.get('http://127.0.0.1:8000/api/checkin') const response = await axios.get('checkin')
checkins.value = response.data checkins.value = response.data
} }
...@@ -82,7 +82,7 @@ export default defineComponent({ ...@@ -82,7 +82,7 @@ export default defineComponent({
const checkout = async (id, bookingId) => { const checkout = async (id, bookingId) => {
console.log(id, bookingId) console.log(id, bookingId)
try { try {
const response = await axios.post('http://127.0.0.1:8000/api/checked/checkout', { const response = await axios.post('checked/checkout', {
id: id, id: id,
bookingId: bookingId bookingId: bookingId
}) })
...@@ -102,7 +102,7 @@ export default defineComponent({ ...@@ -102,7 +102,7 @@ export default defineComponent({
*/ */
const destroy = async (id) => { const destroy = async (id) => {
try { try {
const response = await axios.delete('http://127.0.0.1:8000/api/checked/delCheck', { const response = await axios.delete('checked/delCheck', {
data: { data: {
id: id id: id
} }
...@@ -125,7 +125,7 @@ export default defineComponent({ ...@@ -125,7 +125,7 @@ export default defineComponent({
const addFee = async (id) => { const addFee = async (id) => {
try { try {
console.log(id, fee.value); console.log(id, fee.value);
const response = await axios.post('http://127.0.0.1:8000/api/checked/addFee', { const response = await axios.post('checked/addFee', {
id: id, id: id,
fee: fee.value fee: fee.value
}) })
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<script> <script>
import { ref, defineComponent } from 'vue' import { ref, defineComponent } from 'vue'
import axios from 'axios' import axios from '../config'
import router from '@/router' import router from '@/router'
export default defineComponent({ export default defineComponent({
...@@ -47,7 +47,7 @@ export default defineComponent({ ...@@ -47,7 +47,7 @@ export default defineComponent({
const addBooking = async () => { const addBooking = async () => {
console.log(guest_name.value, guest_number.value, room_id.value) console.log(guest_name.value, guest_number.value, room_id.value)
try { try {
const response = await axios.post('http://127.0.0.1:8000/api/create-booking', { const response = await axios.post('create-booking', {
guest_name: guest_name.value, guest_name: guest_name.value,
guest_number: guest_number.value, guest_number: guest_number.value,
room_id: room_id.value room_id: room_id.value
...@@ -56,7 +56,7 @@ export default defineComponent({ ...@@ -56,7 +56,7 @@ export default defineComponent({
alert('Create booking successfully'); alert('Create booking successfully');
router.push({ name: 'Booking' }) router.push({ name: 'Booking' })
} catch (error) { } catch (error) {
console.error(error.response.data) alert(error.response.data.message)
} }
} }
......
...@@ -4,6 +4,18 @@ ...@@ -4,6 +4,18 @@
<label for="name" class="form-label">Room Name</label> <label for="name" class="form-label">Room Name</label>
<input type="text" id="name" name="name" v-model="name" class="form-control"> <input type="text" id="name" name="name" v-model="name" class="form-control">
</div> </div>
<div class="col-md-6">
<label for="image_first" class="form-label">First Image</label>
<input type="file" ref="fileInput" @change="imageFirst" id="image_first" name="image_first" class="form-control">
</div>
<div class="col-md-6">
<label for="image_second" class="form-label">Second Image</label>
<input type="file" ref="fileInput" @change="imageSecond" id="image_second" name="image_second" class="form-control">
</div>
<div class="col-md-6">
<label for="image_third" class="form-label">Third Image</label>
<input type="file" ref="fileInput" @change="imageThird" id="image_third" name="image_third" class="form-control">
</div>
<div class="col-md-6"> <div class="col-md-6">
<label for="type" class="form-label">Type</label> <label for="type" class="form-label">Type</label>
<input type="text" id="type" name="type" v-model="type" class="form-control"> <input type="text" id="type" name="type" v-model="type" class="form-control">
...@@ -24,16 +36,10 @@ ...@@ -24,16 +36,10 @@
<label class="form-label">Balcony</label> <label class="form-label">Balcony</label>
<div> <div>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="radio" name="balcony" id="balcony-true" value="true" v-model="balcony"> <select name="balcony" id="balcony" v-model="balcony" class="form-select">
<label class="form-check-label" for="balcony-true"> <option value="1">True</option>
True <option value="0">False</option>
</label> </select>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="balcony" id="balcony-false" value="false" v-model="balcony">
<label class="form-check-label" for="balcony-false">
False
</label>
</div> </div>
</div> </div>
</div> </div>
...@@ -41,20 +47,18 @@ ...@@ -41,20 +47,18 @@
<label for="view" class="form-label">View</label> <label for="view" class="form-label">View</label>
<input type="text" id="view" name="view" v-model="view" class="form-control"> <input type="text" id="view" name="view" v-model="view" class="form-control">
</div> </div>
<div class="col-md-6">
<label for="description" class="form-label">Description</label>
<input type="text" id="description" name="description" v-model="description" class="form-control">
</div>
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label">Smoking</label> <label class="form-label">Smoking</label>
<div> <div>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="radio" name="smoking" id="smoking-true" value="true" v-model="smoking"> <select name="smoking" id="smoking" v-model="smoking" class="form-select">
<label class="form-check-label" for="smoking-true"> <option value="1">True</option>
True <option value="0">False</option>
</label> </select>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="smoking" id="smoking-false" value="false" v-model="smoking">
<label class="form-check-label" for="smoking-false">
False
</label>
</div> </div>
</div> </div>
</div> </div>
...@@ -66,16 +70,10 @@ ...@@ -66,16 +70,10 @@
<label class="form-label">Bathtub</label> <label class="form-label">Bathtub</label>
<div> <div>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="radio" name="bathtub" id="bathtub-true" value="true" v-model="bathtub"> <select name="bathtub" id="bathtub" v-model="bathtub" class="form-select">
<label class="form-check-label" for="bathtub-true"> <option value="1">True</option>
True <option value="0">False</option>
</label> </select>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="bathtub" id="bathtub-false" value="false" v-model="bathtub">
<label class="form-check-label" for="bathtub-false">
False
</label>
</div> </div>
</div> </div>
</div> </div>
...@@ -89,7 +87,7 @@ ...@@ -89,7 +87,7 @@
<script> <script>
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import axios from 'axios' import axios from '../config'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
...@@ -100,52 +98,89 @@ export default defineComponent({ ...@@ -100,52 +98,89 @@ export default defineComponent({
const router = useRouter(); const router = useRouter();
const route = useRoute() const route = useRoute()
const id = route.params.id const id = route.params.id
const name = ref(null) // const name = ref(null)
const type = ref(null) // const type = ref(null)
const hour_price = ref(null) // const hour_price = ref(null)
const day_price = ref(null) // const day_price = ref(null)
const size = ref(null) // const size = ref(null)
const balcony = ref(null) // const balcony = ref(null)
const view = ref(null) // const view = ref(null)
const smoking = ref(null) // const smoking = ref(null)
const floor = ref(null) // const floor = ref(null)
const bathtub = ref(null) // const bathtub = ref(null)
const imageFirstFile = ref(null);
const imageSecondFile = ref(null);
const imageThirdFile = ref(null);
const imageFirst = (event) => {
imageFirstFile.value = event.target.files[0];
}
const imageSecond = (event) => {
imageSecondFile.value = event.target.files[0];
}
const imageThird = (event) => {
imageThirdFile.value = event.target.files[0];
}
/** /**
* Get room data * Get room data
* *
* @return void * @return void
*/ */
const update = async () => { const update = async () => {
await axios.put('http://127.0.0.1:8000/api/modify', {
name: name.value, const formData = new FormData()
type: type.value, const form = document.querySelector('form')
hour_price: hour_price.value, formData.append('id', id)
day_price: day_price.value, for (let input of form) {
size: size.value, if (input.value !== '') {
balcony: balcony.value, if (input.name == 'image_first') {
view: view.value, formData.append(input.name, imageFirstFile.value)
smoking: smoking.value, }
floor: floor.value, if (input.name == 'image_second') {
bathtub: bathtub.value, formData.append(input.name, imageSecondFile.value)
id: id }
if (input.name == 'image_third') {
formData.append(input.name, imageThirdFile.value)
}
else {
formData.append(input.name, input.value)
}
}
}
console.log(formData)
await axios.post('modify', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}) })
router.push({ name: 'Room' }) router.push({ name: 'Room' })
}
}
return { return {
update, update,
name, // name,
type, // type,
hour_price, // hour_price,
day_price, // day_price,
size, // size,
balcony, // balcony,
view, // view,
smoking, // smoking,
floor, // floor,
bathtub, // bathtub,
id,
router,
imageFirst,
imageSecond,
imageThird,
} }
} }
}) })
</script> </script>
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
</template> </template>
<script> <script>
import axios from 'axios' import axios from '../config'
import { ref, defineComponent } from 'vue' import { ref, defineComponent } from 'vue'
import storeConfig from '../store'; import storeConfig from '../store';
import { createStore } from 'vuex'; import { createStore } from 'vuex';
...@@ -67,7 +67,7 @@ export default defineComponent({ ...@@ -67,7 +67,7 @@ export default defineComponent({
*/ */
const register = async () => { const register = async () => {
try { try {
const response = await axios.post('http://127.0.0.1:8000/api/register', { const response = await axios.post('register', {
username: username.value, username: username.value,
password: password.value, password: password.value,
confirm_password: confirm_password.value, confirm_password: confirm_password.value,
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<script> <script>
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import axios from 'axios' import axios from '../config'
export default defineComponent({ export default defineComponent({
name: 'UserListView', name: 'UserListView',
...@@ -42,7 +42,7 @@ export default defineComponent({ ...@@ -42,7 +42,7 @@ export default defineComponent({
* @return {void} * @return {void}
*/ */
const getUser = async () => { const getUser = async () => {
const response = await axios.get('http://127.0.0.1:8000/api/userlist') const response = await axios.get('userlist')
users.value = response.data users.value = response.data
} }
...@@ -56,7 +56,7 @@ export default defineComponent({ ...@@ -56,7 +56,7 @@ export default defineComponent({
const deleteUser = async (id) => { const deleteUser = async (id) => {
console.log(id) console.log(id)
try { try {
const response = await axios.delete('http://127.0.0.1:8000/api/userlist/del', { const response = await axios.delete('userlist/del', {
data: { data: {
id: id, id: id,
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment