Skip to content

Commit

Permalink
Release: v1.0.4 (fix buisness logic bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
XPH0816 committed Jun 14, 2024
1 parent 668e107 commit 9d7689d
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libraryroombookingsystem",
"private": true,
"version": "1.0.0",
"version": "1.0.4",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "LibraryRoomBookingSystem"
version = "1.0.0"
version = "1.0.4"
description = "A Library Room Booking System built with Tauri and Rust"
authors = ["Lim Shi Song limshisong123@gmail.com"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/migrations/20240607083248_payment.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE
'debit_card',
'bank transfer'
) NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
amount SMALLINT UNSIGNED NOT NULL,
payment_status ENUM ('completed', 'failed', 'canceled') NOT NULL,
FOREIGN KEY (booking_id) REFERENCES booking (booking_id) ON DELETE CASCADE ON UPDATE CASCADE
);
2 changes: 1 addition & 1 deletion src-tauri/migrations/20240607083253_bill.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CREATE TABLE
bill_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL,
payment_id INT UNSIGNED NOT NULL,
datetime DATETIME NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
amount SMALLINT UNSIGNED NOT NULL,
status ENUM ('completed', 'failed', 'canceled') NOT NULL,
FOREIGN KEY (payment_id) REFERENCES payment (payment_id) ON DELETE CASCADE ON UPDATE CASCADE
);
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "library-room-booking-system",
"version": "1.0.3"
"version": "1.0.4"
},
"tauri": {
"allowlist": {
Expand Down
39 changes: 39 additions & 0 deletions src/lib/components/Modal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script>
import {
Button,
Card,
CardBody,
CardFooter,
CardHeader,
CardTitle,
Modal,
} from "@sveltestrap/sveltestrap";
let instance;
export let show = false;
export let title = "Title";
export let msg = "Enter your message here";
export let close = () => {
instance.$destroy();
};
</script>

<Modal bind:isOpen={show} bind:this={instance} on:close={close} centered>
<Card>
<CardHeader>
<CardTitle>{title}</CardTitle>
</CardHeader>
<CardBody>
<p>{msg}</p>
</CardBody>
<CardFooter class="d-flex">
<Button
class="ms-auto"
on:click={() => {
show = false;
}}>Close</Button
>
</CardFooter>
</Card>
</Modal>
36 changes: 3 additions & 33 deletions src/lib/components/pages/Admin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
} from "$lib/helper";
import { getBillByPaymentId } from "$lib/models/bill";
import { getPaymentByBookingId } from "$lib/models/payment";
import showModal from "$lib/showModal";
let list = [];
let show = false;
let approveSuccess = false;
let rejectSuccess = false;
let booking;
let payment;
Expand All @@ -46,14 +45,14 @@
};
let approve = (event) => {
approveSuccess = true;
showModal("Success", "Booking approved successfully");
let booking = list.find((b) => b.no === event.detail.no);
booking.status = "approved";
list = list;
};
let reject = (event) => {
rejectSuccess = true;
showModal("Success", "Booking rejected successfully");
let booking = list.find((b) => b.no === event.detail.no);
booking.status = "rejected";
list = list;
Expand Down Expand Up @@ -153,35 +152,6 @@
</CardFooter>
</Card>
</Modal>
<Modal bind:isOpen={approveSuccess} centered>
<Card>
<CardHeader>
<CardTitle>Success</CardTitle>
</CardHeader>
<CardBody>
<p>Booking approved successfully</p>
</CardBody>
<CardFooter class="d-flex">
<Button
class="ms-auto"
on:click={() => (approveSuccess = false)}>Close</Button
>
</CardFooter>
</Card>
</Modal>
<Modal bind:isOpen={rejectSuccess} centered>
<Card>
<CardHeader>
<CardTitle>Success</CardTitle>
</CardHeader>
<CardBody>
<p>Booking rejected successfully</p>
</CardBody>
<CardFooter class="ms-auto">
<Button on:click={() => (rejectSuccess = false)}>Close</Button>
</CardFooter>
</Card>
</Modal>
<TableCard
title="Booking List"
bind:datas={list}
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/pages/User.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</script>

<main class="container-fluid gap-3">
<div id="modal"></div>
<div class="container">
<SearchBar bind:room bind:date bind:time {search} />
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/lib/models/booking.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export async function getBookingById(booking_id) {
return new Booking(result.pop());
}

/**
* @param {String} startDateTime
* @param {String} endDateTime
* @returns boolean
*/
export async function checkAvailability(room_id, startDateTime, endDateTime) {
let db = await getDB();
let query = `SELECT * FROM booking WHERE room_id = ? AND (start_datetime BETWEEN ? AND ? OR end_datetime BETWEEN ? AND ?)`;
let result = await db.select(query, [room_id, startDateTime, endDateTime, startDateTime, endDateTime]);
return result.length === 0;
}

export function approveBooking(booking_id) {
return async () => {
let db = await getDB();
Expand Down
12 changes: 12 additions & 0 deletions src/lib/showModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Modal from "$lib/components/Modal.svelte";
export default function showModal(title, msg) {
const modal = new Modal({
target: document.body,
props: {
show: true,
title,
msg,
close: () => { modal.$destroy() },
},
});
}
36 changes: 26 additions & 10 deletions src/routes/(authed)/booking/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
import BookingForm from "$lib/components/forms/BookingForm.svelte";
import { toDateTime } from "$lib/helper";
import { Booking } from "$lib/models/booking";
import { Booking, checkAvailability } from "$lib/models/booking";
import showModal from "$lib/showModal";
import { user } from "$lib/store";
let roomId;
Expand All @@ -14,16 +15,31 @@
let submit = async () => {
success = false;
let booking = new Booking({
room_id: roomId,
user_id: $user.id,
start_datetime: toDateTime(checkInDate, checkInTime),
end_datetime: toDateTime(checkOutDate, checkOutTime),
reason,
try {
if (
!(await checkAvailability(
roomId,
toDateTime(checkInDate, checkInTime),
toDateTime(checkOutDate, checkOutTime),
))
)
throw new Error(
"Room is not available for the selected time period",
);
let booking = new Booking({
room_id: roomId,
user_id: $user.id,
start_datetime: toDateTime(checkInDate, checkInTime),
end_datetime: toDateTime(checkOutDate, checkOutTime),
reason,
});
if (await booking.save()) success = true;
throw new Error("Booking failed");
} catch (e) {
console.error(e);
if (e.message) showModal("Failed", e.message);
else showModal("Failed", "Booking failed");
}
);
if (await booking.save()) success = true;
else console.log("Booking failed");
};
</script>

Expand Down
1 change: 1 addition & 0 deletions src/routes/(authed)/feedback/form/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
bind:success
bind:failure
{view}
button="Close"
/>
{:else}
<FeedBackForm />
Expand Down
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from "vite";
import { sveltekit } from "@sveltejs/kit/vite";

// https://vitejs.dev/config/
export default defineConfig(async () => ({
export default defineConfig(() => ({
plugins: [sveltekit()],

// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
Expand Down

0 comments on commit 9d7689d

Please sign in to comment.