From 56b8142675aa036b9ecfeb1d2282ff88e3d89fa2 Mon Sep 17 00:00:00 2001 From: Prithvi Chauhan Date: Fri, 25 Aug 2023 20:43:31 +0530 Subject: [PATCH 1/2] project update --- .../main/java/com/masai/entity/Customer.java | 2 +- .../com/masai/security/SecurityConfig.java | 2 +- .../com/masai/service/CustomerOpsImpl.java | 26 ++++++++++++------- Frontend/HTML/user.html | 2 +- Frontend/JavaScript/admin.js | 2 +- Frontend/JavaScript/home.js | 16 +++++++----- Frontend/JavaScript/user.js | 2 +- Frontend/{HTML => }/index.html | 4 +-- 8 files changed, 33 insertions(+), 23 deletions(-) rename Frontend/{HTML => }/index.html (99%) diff --git a/Backend/src/main/java/com/masai/entity/Customer.java b/Backend/src/main/java/com/masai/entity/Customer.java index 3f2b12c..bd92fdb 100644 --- a/Backend/src/main/java/com/masai/entity/Customer.java +++ b/Backend/src/main/java/com/masai/entity/Customer.java @@ -55,7 +55,7 @@ public class Customer { private boolean status; @NotBlank(message = "Please provide the customer password") @NotNull(message = "Please provide the customer password") - @Size(min = 10, max = 10, message = "min 10 and max 10 characters allowed only") +// @Size(min = 10, max = 10, message = "min 10 and max 10 characters allowed only") private String mobileNo; @Email(message = "email is not in correct format") diff --git a/Backend/src/main/java/com/masai/security/SecurityConfig.java b/Backend/src/main/java/com/masai/security/SecurityConfig.java index 5e33cb7..d9eef79 100644 --- a/Backend/src/main/java/com/masai/security/SecurityConfig.java +++ b/Backend/src/main/java/com/masai/security/SecurityConfig.java @@ -46,7 +46,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { }); }).authorizeHttpRequests(auth -> { - auth.requestMatchers("/**").permitAll(); +// auth.requestMatchers("/**").permitAll(); auth.requestMatchers(HttpMethod.POST, "travel/customer/signup", "travel/addAdmin").permitAll() .requestMatchers(HttpMethod.POST, "travel/updateAdmin", "travel/adddestination", diff --git a/Backend/src/main/java/com/masai/service/CustomerOpsImpl.java b/Backend/src/main/java/com/masai/service/CustomerOpsImpl.java index 5e6168e..140484a 100644 --- a/Backend/src/main/java/com/masai/service/CustomerOpsImpl.java +++ b/Backend/src/main/java/com/masai/service/CustomerOpsImpl.java @@ -34,17 +34,25 @@ public Customer addCustomer(Customer customer) { if(customer.getRole()==null){ customer.setRole("ROLE_USER"); } - if(customer.getRole().equals("ADMIN")){ - customer.setRole("ROLE_ADMIN"); - }else if(customer.getRole().equals("USER")){ - customer.setRole("ROLE_USER"); - }else if(customer.getRole().equals("ROLE_USER")){ - customer.setRole("ROLE_USER"); - }else if(customer.getRole().equals("ROLE_ADMIN")){ - customer.setRole("ROLE_ADMIN"); - }else{ + else { customer.setRole("ROLE_USER"); } + +// if(customer.getRole().equals("ADMIN")){ +// customer.setRole("ROLE_ADMIN"); +// } +// else if(customer.getRole().equals("USER")){ +// customer.setRole("ROLE_USER"); +// } +// else if(customer.getRole().equals("ROLE_USER")){ +// customer.setRole("ROLE_USER"); +// } +// else if(customer.getRole().equals("ROLE_ADMIN")){ +// customer.setRole("ROLE_ADMIN"); +// } +// else{ +// customer.setRole("ROLE_USER"); +// } return cd.save(customer); } diff --git a/Frontend/HTML/user.html b/Frontend/HTML/user.html index d3af8c9..f3e22ad 100644 --- a/Frontend/HTML/user.html +++ b/Frontend/HTML/user.html @@ -115,7 +115,7 @@

Cancle payment

+ diff --git a/Frontend/JavaScript/admin.js b/Frontend/JavaScript/admin.js index 8c228d2..c942d4d 100644 --- a/Frontend/JavaScript/admin.js +++ b/Frontend/JavaScript/admin.js @@ -23,11 +23,12 @@ so.addEventListener("click", () => { localStorage.clear(); window.location.assign("/index.html"); }); - +let timeout; function notify(message) { + window.clearTimeout(timeout); nid.innerHTML = message; nid.style.opacity = 1; - setInterval(() => { + timeout = setInterval(() => { nid.style.opacity = 0; }, 2000); } @@ -57,26 +58,32 @@ function searchBusById() { document.getElementById("sb").addEventListener("click", () => { pid = document.getElementById("pid").value; // bid.removeChild(div); - if (pid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/bus/" + pid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "This bus is not exist now") { - notify(dat.message); - } else if (dat.message == "Bus not found") { - alert("Bus not found"); - notify(dat.message); - } else if (dat.busId != undefined) { - getData1(dat); - } else window.location.assign("admin.html"); + if (pid == "" || pid == " ") notify("Bus id is mandatory"); + else { + fetch("http://localhost:8080/travel/bus/" + pid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => { + console.log(data.message); + return data.json(); + }) + .then((dat) => { + if (dat.message != undefined) notify(dat.message); + // if (dat.message == "This bus is not exist now") { + // notify(dat.message); + // } else if (dat.message == "Bus not found") { + // notify(dat.message); + // } else if (dat.busId != undefined) { + // getData1(dat); + // } + else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData1(result) { @@ -169,22 +176,25 @@ function removeBus() { document.getElementById("sb").addEventListener("click", () => { busid = document.getElementById("bid").value; - fetch("http://localhost:8080/travel/bus/" + busid, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Bus not found with the given id to remove") { - notify(dat.message); - } else if (dat.message == "Bus is already removed") { - notify(dat.message); - } else if (dat.busId != undefined) getData3(dat); + if (busid == "" || busid == " ") notify("Bus id is mandatory"); + else { + fetch("http://localhost:8080/travel/bus/" + busid, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Bus not found with the given id to remove") { + notify(dat.message); + } else if (dat.message == "Bus is already removed") { + notify(dat.message); + } else if (dat.busId != undefined) getData3(dat); + }) + .catch((error) => console.log(error)); + } }); } function getData3(result) { @@ -216,25 +226,27 @@ function searchBusByTravelId() { document.getElementById("sb").addEventListener("click", () => { pid = document.getElementById("pid").value; // bid.removeChild(div); - if (pid == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/bus/travels/" + pid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "This travels is not available now") { - notify(dat.message); - } else if (dat.message == "No bus is added by this traveler yet") { - notify(dat.message); - } else if (dat.message == "Travels not found to add bus") { - notify(dat.message); - } else getData4(dat); + if (pid == "" || pid == " ") notify("Travel is is mandatory"); + else { + fetch("http://localhost:8080/travel/bus/travels/" + pid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "This travels is not available now") { + notify(dat.message); + } else if (dat.message == "No bus is added by this traveler yet") { + notify(dat.message); + } else if (dat.message == "Travels not found to add bus") { + notify(dat.message); + } else getData4(dat); + }) + .catch((error) => console.log(error)); + } }); } function getData4(result) { @@ -306,24 +318,33 @@ function addBus() { bustype = document.getElementById("bt").value; busnumber = document.getElementById("bn").value; capacity = document.getElementById("bc").value; - fetch("http://localhost:8080/travel/Bus/" + travelId, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - busType: bustype, - busNumber: busnumber, - capacity: capacity, - }), - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Travels not found to add bus") notify(dat.message); - else if (dat.busId != undefined) getData5(dat.busId); + + if (travelId == "" || travelId == " ") notify("Travel id is mandatory"); + else if (bustype == "" || bustype == " ") notify("Bus type is mandatory"); + else if (busnumber == "" || busnumber == " ") + notify("Bus number is mandatory"); + else if (capacity == "" || capacity == " ") notify("Capacity is mandatory"); + else { + fetch("http://localhost:8080/travel/Bus/" + travelId, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + busType: bustype, + busNumber: busnumber, + capacity: capacity, + }), }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Travels not found to add bus") + notify(dat.message); + else if (dat.busId != undefined) getData5(dat.busId); + }) + .catch((error) => console.log(error)); + } }); } function getData5(result) { @@ -359,32 +380,38 @@ function addDestination() { document.getElementById("sb").addEventListener("click", () => { desname = document.getElementById("desName").value; desenviroment = document.getElementById("enviroment").value; - // bid.removeChild(div); - fetch("http://localhost:8080/travel/destination", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - name: desname, - desEnvironment: desenviroment, - }), - }) - .then((data) => { - console.log(data); - return data.json(); - }) - .then((dat) => { - if (dat.message == "Travels not found to add bus") { - notify(dat.message); - } else if (dat.desId != undefined) { - getData6(dat.desId, div); - } else { - window.location.assign("admin.html"); - } + + if (desname == "" || desname == " ") + notify("Destination name is mandatory"); + else if (desenviroment == "" || desenviroment == " ") + notify("Destination enviroment is mandotry (HOT,COLD,NORMAL)"); + else { + fetch("http://localhost:8080/travel/destination", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + name: desname, + desEnvironment: desenviroment, + }), }) - .catch((error) => console.log(error)); + .then((data) => { + console.log(data); + return data.json(); + }) + .then((dat) => { + if (dat.message == "Travels not found to add bus") { + notify(dat.message); + } else if (dat.desId != undefined) { + getData6(dat.desId, div); + } else { + window.location.assign("admin.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function getData6(result) { @@ -427,31 +454,39 @@ function updateDestination() { document.getElementById("sb").addEventListener("click", () => { desname = document.getElementById("desName").value; desenviroment = document.getElementById("enviroment").value; - desId = document.getElementById("desid").value; - // bid.removeChild(div); - fetch("http://localhost:8080/travel/destination/" + deseId, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - name: desname, - desEnvironment: desenviroment, - }), - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "Destination does not exist") { - notify(dat.message); - } else if (dat.desId != undefined) { - getData7(dat.desId, div); - } else { - window.location.assign("admin.html"); - } + deseId = document.getElementById("desid").value; + + if (desname == "" || desname == " ") + notify("Destination name is mandatory"); + else if (desenviroment == "" || desenviroment == " ") + notify("Destination enviroment is mandotry"); + else if (deseId == "" || deseId == " ") + notify("Destination id is mandotry(HOT,COLD,NORMAL)"); + else { + fetch("http://localhost:8080/travel/destination/" + deseId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + name: desname, + desEnvironment: desenviroment, + }), }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "Destination does not exist") { + notify(dat.message); + } else if (dat.desId != undefined) { + getData7(dat.desId, div); + } else { + window.location.assign("admin.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function getData7(result) { @@ -485,25 +520,27 @@ function removeDestination() { document.getElementById("sb").addEventListener("click", () => { desId = document.getElementById("desid").value; // bid.removeChild(div); - if (desId == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/Destination/" + desId, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Unable to remove alerady deleted destination") { - notify(dat.message); - } else if (dat.message == "Destination not found with the given id") { - notify(dat.message); - } else if (dat.desId != undefined) { - getData8(dat.desId); - } else window.location.assign("admin.html"); + if (desId == "" || desId == " ") notify("Destination id is mandatory"); + else { + fetch("http://localhost:8080/travel/Destination/" + desId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Unable to remove alerady deleted destination") { + notify(dat.message); + } else if (dat.message == "Destination not found with the given id") { + notify(dat.message); + } else if (dat.desId != undefined) { + getData8(dat.desId); + } else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData8(result) { @@ -579,26 +616,28 @@ function searchDestination() { desId = document.getElementById("desid").value; // bid.removeChild(div); console.log(desId); - if (desId == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/Destination/" + desId, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "This destinaton is not available now") { - notify(dat.message); - } else if (dat.message == "Destination not found with the given id") { - notify(dat.message); - } else if (dat.desId != undefined) { - getData10(dat); - } else window.location.assign("admin.html"); + if (desId == "" || desId == " ") notify("Destination id is mandatory"); + else { + fetch("http://localhost:8080/travel/Destination/" + desId, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "This destinaton is not available now") { + notify(dat.message); + } else if (dat.message == "Destination not found with the given id") { + notify(dat.message); + } else if (dat.desId != undefined) { + getData10(dat); + } else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData10(element) { @@ -676,7 +715,6 @@ function addRoute() { div.setAttribute("class", "form"); bid.append(div); document.getElementById("cb").addEventListener("click", () => { - // bid.removeChild(div); window.location.assign("admin.html"); }); @@ -688,36 +726,48 @@ function addRoute() { pickUpPoint = document.getElementById("pp").value; fare = document.getElementById("f").value; busId = document.getElementById("bi").value; - // bid.removeChild(div); - fetch("http://localhost:8080/travel/route/" + busId, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - routeFrom: routeFrom, - routeTo: routeTo, - departureTime: derpaureTime, - arrivalTime: arrivalTime, - pickupPoint: pickUpPoint, - fare: fare, - }), - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Bus is not exist now") { - notify(dat.message); - window.location.assign("admin.html"); - } else if (dat.message == "Bus not found with the given id") { - notify(dat.message); - } else if (dat.routeId != undefined) { - getData11(dat.routeId); - } else { - window.location.assign("admin.html"); - } + + if (routeFrom == "" || routeFrom == " ") notify("Route is mandatory"); + else if (routeTo == "" || routeTo == " ") notify("Route is mandatory"); + else if (derpaureTime == "" || derpaureTime == " ") + notify("Departure time is mandatory"); + else if (arrivalTime == "" || arrivalTime == " ") + notify("Arrival time is mandatory"); + else if (pickUpPoint == "" || pickUpPoint == " ") + notify("Pick up point is mandatory"); + else if (fare == "" || fare == " ") notify("Fare is mandatory"); + else if (busId == "" || busId == " ") notify("Bus id is mandatory"); + else { + fetch("http://localhost:8080/travel/route/" + busId, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + routeFrom: routeFrom, + routeTo: routeTo, + departureTime: derpaureTime, + arrivalTime: arrivalTime, + pickupPoint: pickUpPoint, + fare: fare, + }), }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Bus is not exist now") { + notify(dat.message); + window.location.assign("admin.html"); + } else if (dat.message == "Bus not found with the given id") { + notify(dat.message); + } else if (dat.routeId != undefined) { + getData11(dat.routeId); + } else { + window.location.assign("admin.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function getData11(result) { @@ -775,34 +825,43 @@ function updateRoute() { derpaureTime = document.getElementById("dt").value; arrivalTime = document.getElementById("at").value; routeId = document.getElementById("ri").value; - // bid.removeChild(div); - fetch("http://localhost:8080/travel/route/update/" + routeId, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - routeFrom: routeFrom, - routeTo: routeTo, - departureTime: derpaureTime, - arrivalTime: arrivalTime, - }), - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "Route is not available to update now") { - notify(dat.message); - } else if (dat.message == "Route not found to update") { - notify(dat.message); - } else if (dat.routeId != undefined) { - getData12(dat.routeId); - } else { - window.location.assign("admin.html"); - } + + if (routeFrom == "" || routeFrom == " ") notify("Route is mandatory"); + else if (routeTo == "" || routeTo == " ") notify("Route is mandatory"); + else if (derpaureTime == "" || derpaureTime == " ") + notify("Departure time is mandatory"); + else if (arrivalTime == "" || arrivalTime == " ") + notify("Arrival time is mandatory"); + else if (routeId == "" || routeId == " ") notify("Route id is mandatory"); + else { + fetch("http://localhost:8080/travel/route/update/" + routeId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + routeFrom: routeFrom, + routeTo: routeTo, + departureTime: derpaureTime, + arrivalTime: arrivalTime, + }), }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "Route is not available to update now") { + notify(dat.message); + } else if (dat.message == "Route not found to update") { + notify(dat.message); + } else if (dat.routeId != undefined) { + getData12(dat.routeId); + } else { + window.location.assign("admin.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function getData12(result) { @@ -835,25 +894,27 @@ function removeRoute() { document.getElementById("sb").addEventListener("click", () => { routeId = document.getElementById("rid").value; // bid.removeChild(div); - if (routeId == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/route/" + routeId, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Route is not available to remove now") { - notify(dat.message); - } else if (dat.message == "Route not found to remove") { - notify(dat.message); - } else if (dat.routeId != undefined) { - getData13(dat.routeId, div); - } else window.location.assign("admin.html"); + if (routeId == "" || routeId == " ") notify("Route id is mandatory"); + else { + fetch("http://localhost:8080/travel/route/" + routeId, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Route is not available to remove now") { + notify(dat.message); + } else if (dat.message == "Route not found to remove") { + notify(dat.message); + } else if (dat.routeId != undefined) { + getData13(dat.routeId, div); + } else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData13(result) { @@ -934,26 +995,28 @@ function searchRoute() { document.getElementById("sb").addEventListener("click", () => { routeId = document.getElementById("rid").value; // bid.removeChild(div); - if (routeId == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/route/" + routeId, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "Route is not available now") { - notify(dat.message); - } else if (dat.message == "Route not found to view") { - notify(dat.message); - } else if (dat.routeId != undefined) { - getData15(dat); - } else window.location.assign("admin.html"); + if (routeId == "" || routeId == " ") notify("Route id is mandatory"); + else { + fetch("http://localhost:8080/travel/route/" + routeId, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "Route is not available now") { + notify(dat.message); + } else if (dat.message == "Route not found to view") { + notify(dat.message); + } else if (dat.routeId != undefined) { + getData15(dat); + } else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData15(element) { @@ -1349,36 +1412,49 @@ function addHotel() { rent = document.getElementById("hn").value; status = document.getElementById("hs").value; desId = document.getElementById("di").value; - // bid.removeChild(div); - if (desId == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/hotel/" + desId, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - hotelName: hotelName, - hotelType: hotelType, - hotelDescription: hotelDescription, - address: address, - rent: rent, - status: status, - }), - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Invalid destination ID") { - notify(dat.message); - } else if (dat.message == "Destination is not available") { - notify(dat.message); - } else if (dat.hotelId != undefined) { - getData20(dat.hotelId); - } else { - window.location.assign("admin.html"); - } + + if (hotelName == "" || hotelName == " ") notify("Hotel name is mandatory"); + else if (hotelType == "" || hotelType == " ") + notify( + "Hotel type is mandatory(ONE_STAR,TWO_STAR,THREE_STAR,FOUR_STAR,FIVE_STAR)" + ); + else if (hotelDescription == "" || hotelDescription == " ") + notify("Hotel description is required"); + else if (address == "" || address == " ") notify("Hotel address required"); + else if (rent == "" || rent == " ") notify("Hotel rent is mandatory"); + else if (status == "" || status == " ") + notify("Hotel status is required(OPEN,CLOSED,FILLED,VACANT)"); + else if (desId == " " || desId == "") notify("Destination id is requred"); + else { + fetch("http://localhost:8080/travel/hotel/" + desId, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + hotelName: hotelName, + hotelType: hotelType, + hotelDescription: hotelDescription, + address: address, + rent: rent, + status: status, + }), }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Invalid destination ID") { + notify(dat.message); + } else if (dat.message == "Destination is not available") { + notify(dat.message); + } else if (dat.hotelId != undefined) { + getData20(dat.hotelId); + } else { + window.location.assign("admin.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function getData20(result) { @@ -1410,26 +1486,27 @@ function removeHotel() { document.getElementById("sb").addEventListener("click", () => { hid = document.getElementById("hid").value; - // bid.removeChild(div); - if (hid == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/Hotel/" + hid, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Unable to remove already deleted hotel") { - notify(dat.message); - } else if (dat.message == "Hotel not found with given id") { - notify(dat.message); - } else if (dat.hotelId != undefined) { - getData21(dat.hotelId); - } else window.location.assign("admin.html"); + if (hid == "" || hid == " ") notify("Hotel id is mandatory"); + else { + fetch("http://localhost:8080/travel/Hotel/" + hid, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Unable to remove already deleted hotel") { + notify(dat.message); + } else if (dat.message == "Hotel not found with given id") { + notify(dat.message); + } else if (dat.hotelId != undefined) { + getData21(dat.hotelId); + } else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData21(result) { @@ -1508,31 +1585,34 @@ function showByDesId() { document.getElementById("sb").addEventListener("click", () => { did = document.getElementById("did").value; - // bid.removeChild(div); - if (did == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/Hotel/Destination/" + did, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => { - console.log(data); - return data.json(); - }) - .then((dat) => { - if (dat.message == "This destination is not available now") { - notify(dat.message); - } else if (dat.message == "Empty hotel list") { - notify(dat.message); - } else if (dat.message == "No destination is found with the given id") { - notify(dat.message); - } else { - getData23(dat); - } + if (did == "" || did == " ") notify("Destination id is required"); + else { + fetch("http://localhost:8080/travel/Hotel/Destination/" + did, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => { + console.log(data); + return data.json(); + }) + .then((dat) => { + if (dat.message == "This destination is not available now") { + notify(dat.message); + } else if (dat.message == "Empty hotel list") { + notify(dat.message); + } else if ( + dat.message == "No destination is found with the given id" + ) { + notify(dat.message); + } else { + getData23(dat); + } + }) + .catch((error) => console.log(error)); + } }); } function getData23(result) { @@ -1613,30 +1693,38 @@ function addTravel() { address = document.getElementById("td").value; contact = document.getElementById("tc").value; - // bid.removeChild(div); - // if (desId == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/travels", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - travelsName: travelName, - agentName: agentName, - address: address, - contact: contact, - }), - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.travelsId != undefined) { - getData24(dat.travelsId); - } else { - window.location.assign("admin.html"); - } + if (travelName == "" || travelName == " ") { + notify("Travel name is mandatory"); + } else if (agentName == "" || agentName == " ") { + notify("Agent name is mandatory"); + } else if (address == "" || address == " ") { + notify("Address is mandatory"); + } else if (contact == "" || contact == " ") { + notify("Contact is mandatory"); + } else { + fetch("http://localhost:8080/travel/travels", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + travelsName: travelName, + agentName: agentName, + address: address, + contact: contact, + }), }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.travelsId != undefined) { + getData24(dat.travelsId); + } else { + window.location.assign("admin.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function getData24(result) { @@ -1668,26 +1756,29 @@ function removeTravel() { document.getElementById("sb").addEventListener("click", () => { tid = document.getElementById("tid").value; + // bid.removeChild(div); - if (tid == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/travels/remove/" + tid, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Travel is not available to remove") { - notify(dat.message); - } else if (dat.message == "Travels not found to remove") { - notify(dat.message); - } else if (dat.travelsId != undefined) { - getData25(dat.travelsId); - } else window.location.assign("admin.html"); + if (tid == "" || tid == " ") notify("Travel id is mandatory"); + else { + fetch("http://localhost:8080/travel/travels/remove/" + tid, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Travel is not available to remove") { + notify(dat.message); + } else if (dat.message == "Travels not found to remove") { + notify(dat.message); + } else if (dat.travelsId != undefined) { + getData25(dat.travelsId); + } else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData25(result) { @@ -1789,6 +1880,17 @@ function updateTravel() { address = document.getElementById("ta").value; contact = document.getElementById("ac").value; + if (travelName == "" || travelName == " ") { + notify("Travel name is mandatory"); + } else if (tid == "" || tid == " ") { + notify("Travel id is mandatory"); + } else if (agentName == "" || agentName == " ") { + notify("Agent name is mandatory"); + } else if (address == "" || address == " ") { + notify("Address is mandatory"); + } else if (contact == "" || contact == " ") { + notify("Contact is mandatory"); + } // bid.removeChild(div); fetch("http://localhost:8080/travel/travels/update/" + tid, { method: "POST", @@ -1987,7 +2089,6 @@ function viewAllFeedBack() { .catch((error) => console.log(error)); } function getData29(result) { - console.log(result); bid.innerHTML = null; let div = document.createElement("div"); let arr = []; @@ -2164,44 +2265,76 @@ function addPackage() { packageDescription4 = document.getElementById("pd4").value; packageDescription5 = document.getElementById("pd5").value; packageCost = document.getElementById("pc").value; - // bid.removeChild(div); - fetch( - "http://localhost:8080/travel/Packages/" + hotelId + "/" + destinationId, - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - packageName: packageName, - hotelType: hotelType, - daysAndNight: daysAndNight, - packageSeason: packageSeason, - packageDescription1: packageDescription1, - packageDescription2: packageDescription2, - packageDescription3: packageDescription3, - packageDescription4: packageDescription4, - packageDescription5: packageDescription5, - packageCost: packageCost, - }), - } + if (hotelId == "" || hotelId == " ") notify("Hotel id is mandatory"); + else if (destinationId == "" || destinationId == " ") + notify("Destination id is mandatory"); + else if (packageName == "" || packageName == " ") + notify("Package name is mandatory"); + else if (hotelType == "" || hotelType == " ") + notify( + "Hotel type is mandatory(ONE_STAR,TWO_STAR,THREE_STAR,FOUR_STAR,FIVE_STAR)" + ); + else if (daysAndNight == "" || daysAndNight == " ") + notify("Day and night field is mandatory"); + else if (packageSeason == "" || packageSeason == " ") + notify("Package season is mandatory(WINTER,SUMMER,RAINY,SPRING)"); + else if ( + packageDescription1 == "" || + packageDescription1 == " " || + packageDescription2 == "" || + packageDescription2 == " " || + packageDescription3 == "" || + packageDescription3 == " " || + packageDescription4 == "" || + packageDescription4 == " " || + packageDescription5 == "" || + packageDescription5 == " " ) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Unable to add package in deleted hotel") { - notify(dat.message); - } else if ( - dat.message == "Unable to add package in deleted destination" - ) { - notify(dat.message); - } else if (dat.message == "Hotel not found with the given id") { - notify(dat.message); - } else if (dat.packageId != undefined) { - getData31(dat.packageId); + notify("All package description are mandatroy"); + else if (packageCost == "" || packageCost == " ") + notify("Package cost field is mandatory"); + else { + fetch( + "http://localhost:8080/travel/Packages/" + + hotelId + + "/" + + destinationId, + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + packageName: packageName, + hotelType: hotelType, + daysAndNight: daysAndNight, + packageSeason: packageSeason, + packageDescription1: packageDescription1, + packageDescription2: packageDescription2, + packageDescription3: packageDescription3, + packageDescription4: packageDescription4, + packageDescription5: packageDescription5, + packageCost: packageCost, + }), } - }) - .catch((error) => console.log(error)); + ) + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Unable to add package in deleted hotel") { + notify(dat.message); + } else if ( + dat.message == "Unable to add package in deleted destination" + ) { + notify(dat.message); + } else if (dat.message == "Hotel not found with the given id") { + notify(dat.message); + } else if (dat.packageId != undefined) { + getData31(dat.packageId); + } + }) + .catch((error) => console.log(error)); + } }); } function getData31(dat) { @@ -2232,26 +2365,27 @@ function searchPackage() { document.getElementById("sb").addEventListener("click", () => { pid = document.getElementById("pid").value; - // bid.removeChild(div); - if (pid == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/Packages/" + pid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Package is not exist now") { - notify(dat.message); - } else if (dat.message == "No package is found to view") { - notify(dat.message); - } else { - getData32(dat); - } + if (pid == "" || pid == " ") notify("Package id is mandatory"); + else { + fetch("http://localhost:8080/travel/Packages/" + pid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Package is not exist now") { + notify(dat.message); + } else if (dat.message == "No package is found to view") { + notify(dat.message); + } else { + getData32(dat); + } + }) + .catch((error) => console.log(error)); + } }); } function getData32(result) { @@ -2362,25 +2496,27 @@ function removePackage() { document.getElementById("sb").addEventListener("click", () => { pid = document.getElementById("pid").value; // bid.removeChild(div); - if (pid == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/Packages/" + pid, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Unable to remove already deleted package") { - notify(dat.message); - } else if (dat.message == "No package is found to remove") { - notify(dat.message); - } else if (dat.packageId != undefined) { - getData34(dat.packageId); - } else window.location.assign("admin.html"); + if (pid == "" || pid == " ") notify("Package id is mandatory"); + else { + fetch("http://localhost:8080/travel/Packages/" + pid, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Unable to remove already deleted package") { + notify(dat.message); + } else if (dat.message == "No package is found to remove") { + notify(dat.message); + } else if (dat.packageId != undefined) { + getData34(dat.packageId); + } else window.location.assign("admin.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData34(result) { diff --git a/Frontend/JavaScript/home.js b/Frontend/JavaScript/home.js index de54202..56b364a 100644 --- a/Frontend/JavaScript/home.js +++ b/Frontend/JavaScript/home.js @@ -8,9 +8,9 @@ function openpopup() { headers: { "Content-Type": "application/json", }, - body: { + body: JSON.stringify({ email: email, - }, + }), }) .then((data) => { if (data.ok == false) { @@ -25,11 +25,12 @@ function closepopup() { pops.classList.remove("open-pop"); } let nid = document.getElementById("notify"); - +let timeout; function notify(message) { + window.clearTimeout(timeout); nid.innerHTML = message; nid.style.opacity = 1; - setInterval(() => { + timeout = setInterval(() => { nid.style.opacity = 0; }, 2000); } @@ -69,31 +70,36 @@ function signIn() { let user = document.getElementById("userName").value; let password = document.getElementById("userPass").value; - let auth = btoa(`${user}:${password}`); - fetch("http://localhost:8080/travel/cusLogin", { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => { - console.log(data); - if (data.ok == false) { - notify("Verification failed"); - } else return data.json(); - }) - .then((res) => { - if (res != undefined) { - localStorage.setItem("User", user); - localStorage.setItem("Password", password); - if (res.role == "ROLE_ADMIN") - window.location.assign("HTML/admin.html"); - else if (res.role == "ROLE_USER") - window.location.assign("HTML/user.html"); - } + if (user == "" || user == " ") notify("Username is mandatory"); + else if (password == "" || password == " ") notify("Password is mandatory"); + else { + let auth = btoa(`${user}:${password}`); + fetch("http://localhost:8080/travel/cusLogin", { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => { + console.log(data); + if (data.ok == false) { + notify("Verification failed"); + } else return data.json(); + }) + .then((res) => { + if (res != undefined) { + bid.removeChild(div); + localStorage.setItem("User", user); + localStorage.setItem("Password", password); + if (res.role == "ROLE_ADMIN") + window.location.assign("HTML/admin.html"); + else if (res.role == "ROLE_USER") + window.location.assign("HTML/user.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function reg() { @@ -110,32 +116,47 @@ function signup() { let aadhar = document.getElementById("aadhar").value; let gender = document.getElementById("gender").value; let country = document.getElementById("country").value; - // let role = document.getElementById("role").value; + let role = document.getElementById("role").value; let moblie = document.getElementById("mobile").value; let email = document.getElementById("email").value; - - fetch("http://localhost:8080/travel/customer/signup", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - customerName: name, - customerPassword: password, - address: address, - aadharId: aadhar, - gender: gender, - country: country, - role: "USER", - mobileNo: moblie, - email: email, - }), - }) - .then((data) => { - if (data.ok == false) notify("Registration failed"); - else return data.json(); + if (name == "" || name == " ") notify("Name is mandatory"); + else if (password == "" || password == " ") notify("Password is mandatory"); + else if (address == "" || address == " ") notify("Aadress is mandatory"); + else if (aadhar == "" || aadhar == " ") notify("Aadhar is mandatory"); + else if (gender == "" || gender == " ") notify("Gender is mandatory"); + else if (country == "" || country == " ") notify("Country is mandatory"); + else if (moblie == "" || moblie == " ") notify("Mobile number is mandatory"); + else if (email == "" || email == " ") notify("Email is mandatory"); + else { + fetch("http://localhost:8080/travel/customer/signup", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + customerName: name, + customerPassword: password, + address: address, + aadharId: aadhar, + gender: gender, + country: country, + role: role, + mobileNo: moblie, + email: email, + }), }) - .then((dat) => { - if (dat.customerId != undefined) notify("Register successfully"); - }); + .then((data) => { + console.log(data); + if (data.message == "Customer already registered") + notify("Customer already registered"); + else if (data.ok == false) notify("Registration failed"); + else return data.json(); + }) + .then((dat) => { + if (dat.customerId != undefined) { + rgst.style.opacity = 0; + notify("Register successfully"); + } + }); + } } diff --git a/Frontend/JavaScript/user.js b/Frontend/JavaScript/user.js index 0f2cb03..98f046c 100644 --- a/Frontend/JavaScript/user.js +++ b/Frontend/JavaScript/user.js @@ -22,10 +22,12 @@ so.addEventListener("click", () => { localStorage.clear(); window.location.assign("/index.html"); }); +let timeout; function notify(message) { + window.clearTimeout(timeout); nid.innerHTML = message; nid.style.opacity = 1; - setInterval(() => { + timeout = setInterval(() => { nid.style.opacity = 0; }, 2000); } @@ -67,27 +69,34 @@ function addFeedback() { cid = document.getElementById("cid").value; feedback = document.getElementById("fb").value; rating = document.getElementById("cr").value; - fetch("http://localhost:8080/travel/feedback/" + cid, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - body: JSON.stringify({ - feedback: feedback, - rating: rating, - }), - }) - .then((dat) => dat.json()) - .then((data) => { - console.log(data); - if (data.message == "Customer not valid") { - notify(data.message); - } else if (data.feedbackId != undefined) { - getData1(data.message); - } + + if (cid == "" || cid == " ") notify("Customer id is mandatory"); + else if (feedback == "" || feedback == " ") + notify("Feedback description is mandatory"); + else if (rating == "" || rating == " ") notify("Rating is mandatory"); + else { + fetch("http://localhost:8080/travel/feedback/" + cid, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, + body: JSON.stringify({ + feedback: feedback, + rating: rating, + }), }) - .catch((error) => console.log(error)); + .then((dat) => dat.json()) + .then((data) => { + console.log(data); + if (data.message == "Customer not valid") { + notify(data.message); + } else if (data.feedbackId != undefined) { + getData1(data.message); + } + }) + .catch((error) => console.log(error)); + } }); } function getData1(result) { @@ -118,23 +127,25 @@ function searchFeedBackByfeedBackId() { document.getElementById("sb").addEventListener("click", () => { fid = document.getElementById("fid").value; // bid.removeChild(div); - if (fid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/feedback/" + fid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Feedback not found with the given id") { - notify(dat.message); - } else { - getData2(dat); - } + if (fid == "" || fid == " ") notify("Feedback id is mandatory"); + else { + fetch("http://localhost:8080/travel/feedback/" + fid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Feedback not found with the given id") { + notify(dat.message); + } else { + getData2(dat); + } + }) + .catch((error) => console.log(error)); + } }); } function getData2(result) { @@ -175,14 +186,12 @@ function searchFeedBackByCustomerId() { div.setAttribute("class", "form"); bid.append(div); document.getElementById("cb").addEventListener("click", () => { - // bid.removeChild(div); window.location.assign("user.html"); }); document.getElementById("sb").addEventListener("click", () => { cid = document.getElementById("cid").value; - // bid.removeChild(div); - if (cid == "") window.location.assign("user.html"); + if (cid == "" || cid == " ") notify("Customer id is mandatory"); fetch("http://localhost:8080/travel/feedback/customer/" + cid, { method: "GET", headers: { @@ -308,30 +317,33 @@ function bookPackage() { document.getElementById("sb").addEventListener("click", () => { cid = document.getElementById("cid").value; pid = document.getElementById("pid").value; - // bid.removeChild(div); - if (cid == "" || pid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/package/" + cid + "/" + pid, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Not valid customer to make booking") { - notify(dat.message); - } else if (dat.message == "Package not found") { - notify(dat.message); - } else if (dat.message == "Customer is not exist now") { - notify(dat.message); - } else if (dat.message == "Package is not exist now") { - notify(dat.message); - } else if (dat.bookingId != undefined) { - getData5(dat.bookingId); - } else window.location.assign("user.html"); + + if (cid == "" || cid == " ") notify("Customer id is mandatory"); + else if (pid == "" || pid == " ") notify("Package id is mandatory"); + else { + fetch("http://localhost:8080/travel/package/" + cid + "/" + pid, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Not valid customer to make booking") { + notify(dat.message); + } else if (dat.message == "Package not found") { + notify(dat.message); + } else if (dat.message == "Customer is not exist now") { + notify(dat.message); + } else if (dat.message == "Package is not exist now") { + notify(dat.message); + } else if (dat.bookingId != undefined) { + getData5(dat.bookingId); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData5(result) { @@ -363,28 +375,30 @@ function searchPackage() { document.getElementById("sb").addEventListener("click", () => { bookingId = document.getElementById("bid").value; // bid.removeChild(div); - if (bookingId == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/package/" + bookingId, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "Booking is not exist now") { - notify(dat.message); - } else if ( - dat.message == "No booking found with the given id to view" - ) { - notify(dat.message); - } else if (dat.bookingId != undefined) { - getData7(dat); - } + if (bookingId == "" || bookingId == " ") notify("Booking id is mandatory"); + else { + fetch("http://localhost:8080/travel/package/" + bookingId, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "Booking is not exist now") { + notify(dat.message); + } else if ( + dat.message == "No booking found with the given id to view" + ) { + notify(dat.message); + } else if (dat.bookingId != undefined) { + getData7(dat); + } + }) + .catch((error) => console.log(error)); + } }); } function getData7(result) { @@ -437,27 +451,29 @@ function removePackage() { document.getElementById("sb").addEventListener("click", () => { pid = document.getElementById("pid").value; // bid.removeChild(div); - if (pid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/package/" + pid, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Unable to cancle already canceld booking") { - notify(dat.message); - } else if ( - dat.message == "No booking found with the given id to cancle" - ) { - notify(dat.message); - } else if (dat.bookingId != undefined) { - getData8(dat.bookingId); - } else window.location.assign("user.html"); + if (pid == "" || pid == " ") notify("Package id is mandatory"); + else { + fetch("http://localhost:8080/travel/package/" + pid, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Unable to cancle already canceld booking") { + notify(dat.message); + } else if ( + dat.message == "No booking found with the given id to cancle" + ) { + notify(dat.message); + } else if (dat.bookingId != undefined) { + getData8(dat.bookingId); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData8(result) { @@ -492,25 +508,27 @@ function searchBusById() { document.getElementById("sb").addEventListener("click", () => { pid = document.getElementById("pid").value; // bid.removeChild(div); - if (pid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/bus/" + pid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "This bus is not exist now") { - notify(dat.message); - } else if (dat.message == "Bus not found") { - notify(dat.message); - } else if (dat.busId != undefined) { - getData9(dat); - } else window.location.assign("user.html"); + if (pid == "" || pid == " ") notify("Bus id is mandatory"); + else { + fetch("http://localhost:8080/travel/bus/" + pid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "This bus is not exist now") { + notify(dat.message); + } else if (dat.message == "Bus not found") { + notify(dat.message); + } else if (dat.busId != undefined) { + getData9(dat); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData9(result) { @@ -559,25 +577,27 @@ function searchBusByTravelId() { document.getElementById("sb").addEventListener("click", () => { pid = document.getElementById("pid").value; // bid.removeChild(div); - if (pid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/bus/travels/" + pid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "This travels is not available now") { - notify(dat.message); - } else if (dat.message == "No bus is added by this traveler yet") { - notify(dat.message); - } else if (dat.message == "Travels not found to add bus") { - notify(dat.message); - } else getData10(dat); + if (pid == "" || pid == " ") notify("Travel id is mandatory"); + else { + fetch("http://localhost:8080/travel/bus/travels/" + pid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "This travels is not available now") { + notify(dat.message); + } else if (dat.message == "No bus is added by this traveler yet") { + notify(dat.message); + } else if (dat.message == "Travels not found to add bus") { + notify(dat.message); + } else getData10(dat); + }) + .catch((error) => console.log(error)); + } }); } function getData10(result) { @@ -676,28 +696,30 @@ function searchCustomer() { document.getElementById("sb").addEventListener("click", () => { cid = document.getElementById("cid").value; // bid.removeChild(div); - if (cid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/customer/" + cid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "This customer is not exist now") { - notify(dat.message); - } else if ( - dat.message == "Customer not found with the given id to delete" - ) { - notify(dat.message); - } else if (dat.customerId != undefined) { - getData12(dat); - } else window.location.assign("user.html"); + if (cid == "" || cid == " ") notify("Customer id is mandatory"); + else { + fetch("http://localhost:8080/travel/customer/" + cid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "This customer is not exist now") { + notify(dat.message); + } else if ( + dat.message == "Customer not found with the given id to delete" + ) { + notify(dat.message); + } else if (dat.customerId != undefined) { + getData12(dat); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData12(element) { @@ -794,6 +816,7 @@ function viewAllDestination() { }) .then((dat) => { if (dat.message == "Destination list is empty") notify(dat.message); + else getData14(dat); }) .catch((error) => console.log(error)); } @@ -847,26 +870,28 @@ function searchDestination() { desId = document.getElementById("desid").value; // bid.removeChild(div); console.log(desId); - if (desId == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/Destination/" + desId, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "This destinaton is not available now") { - notify(dat.message); - } else if (dat.message == "Destination not found with the given id") { - notify(dat.message); - } else if (dat.desId != undefined) { - getData15(dat); - } else window.location.assign("user.html"); + if (desId == "" || desId == " ") notify("Destination id is mandatory"); + else { + fetch("http://localhost:8080/travel/Destination/" + desId, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "This destinaton is not available now") { + notify(dat.message); + } else if (dat.message == "Destination not found with the given id") { + notify(dat.message); + } else if (dat.desId != undefined) { + getData15(dat); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData15(element) { @@ -915,26 +940,28 @@ function searchDestinationByBusId() { desId = document.getElementById("desid").value; // bid.removeChild(div); console.log(desId); - if (desId == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/Destination/travels/" + desId, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "Bus is not exist now") { - notify(dat.message); - } else if (dat.message == "Given bus not go any destination yet") { - notify(dat.message); - } else if (dat.message == "Bus not found with the given id") { - notify(dat.message); - } else getData16(dat); + if (desId == "" || desId == " ") notify("Bus id is mandatory"); + else { + fetch("http://localhost:8080/travel/Destination/travels/" + desId, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "Bus is not exist now") { + notify(dat.message); + } else if (dat.message == "Given bus not go any destination yet") { + notify(dat.message); + } else if (dat.message == "Bus not found with the given id") { + notify(dat.message); + } else getData16(dat); + }) + .catch((error) => console.log(error)); + } }); } function getData16(data) { @@ -1036,30 +1063,34 @@ function showByDesId() { document.getElementById("sb").addEventListener("click", () => { did = document.getElementById("did").value; // bid.removeChild(div); - if (did == "") window.location.assign("admin.html"); - fetch("http://localhost:8080/travel/Hotel/Destination/" + did, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => { - console.log(data); - return data.json(); - }) - .then((dat) => { - if (dat.message == "This destination is not available now") { - notify(dat.message); - } else if (dat.message == "Empty hotel list") { - notify(dat.message); - } else if (dat.message == "No destination is found with the given id") { - notify(dat.message); - } else { - getData18(dat); - } + if (did == "" || did == " ") notify("Destination id is mandatory"); + else { + fetch("http://localhost:8080/travel/Hotel/Destination/" + did, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => { + console.log(data); + return data.json(); + }) + .then((dat) => { + if (dat.message == "This destination is not available now") { + notify(dat.message); + } else if (dat.message == "Empty hotel list") { + notify(dat.message); + } else if ( + dat.message == "No destination is found with the given id" + ) { + notify(dat.message); + } else { + getData18(dat); + } + }) + .catch((error) => console.log(error)); + } }); } function getData18(result) { @@ -1117,26 +1148,28 @@ function searchTravel() { document.getElementById("sb").addEventListener("click", () => { cid = document.getElementById("cid").value; // bid.removeChild(div); - if (cid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/travels/" + cid, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "Travel is not available now") { - notify(dat.message); - } else if (dat.message == "Travels not found to view") { - notify(dat.message); - } else if (dat.travelsId != undefined) { - getData19(dat); - } else window.location.assign("user.html"); + if (cid == "" || cid == " ") notify("Travel id is mandatory"); + else { + fetch("http://localhost:8080/travel/travels/" + cid, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "Travel is not available now") { + notify(dat.message); + } else if (dat.message == "Travels not found to view") { + notify(dat.message); + } else if (dat.travelsId != undefined) { + getData19(dat); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData19(element) { @@ -1287,26 +1320,28 @@ function searchRoute() { document.getElementById("sb").addEventListener("click", () => { routeId = document.getElementById("rid").value; // bid.removeChild(div); - if (routeId == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/route/" + routeId, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - console.log(dat); - if (dat.message == "Route is not available now") { - notify(dat.message); - } else if (dat.message == "Route not found to view") { - notify(dat.message); - } else if (dat.routeId != undefined) { - getData22(dat); - } else window.location.assign("user.html"); + if (routeId == "") notify("Route id is mandatory"); + else { + fetch("http://localhost:8080/travel/route/" + routeId, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + console.log(dat); + if (dat.message == "Route is not available now") { + notify(dat.message); + } else if (dat.message == "Route not found to view") { + notify(dat.message); + } else if (dat.routeId != undefined) { + getData22(dat); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData22(element) { @@ -1367,30 +1402,38 @@ function makePayment() { document.getElementById("sb").addEventListener("click", () => { bookingId = document.getElementById("bid").value; customerId = document.getElementById("cid").value; - fetch( - "http://localhost:8080/travel/Payment/" + bookingId + "/" + customerId, - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - } - ) - .then((dat) => dat.json()) - .then((data) => { - if (data.message == "Please enter valid customer id") { - notify(data.message); - } else if (data.message == "Package Booking not exist now") { - notify(data.message); - } else if (data.message == "No hotel booking found with the given id") { - notify(data.message); - } else if (data.paymentId != undefined) { - getData23(data.paymentId); - window.location.assign("user.html"); + + if (bookingId == "" || bookingId == " ") notify("Booking id is mandatory"); + else if (customerId == "" || customerId == " ") + notify("Customer id is mandatory"); + else { + fetch( + "http://localhost:8080/travel/Payment/" + bookingId + "/" + customerId, + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, } - }) - .catch((error) => console.log(error)); + ) + .then((dat) => dat.json()) + .then((data) => { + if (data.message == "Please enter valid customer id") { + notify(data.message); + } else if (data.message == "Package Booking not exist now") { + notify(data.message); + } else if ( + data.message == "No hotel booking found with the given id" + ) { + notify(data.message); + } else if (data.paymentId != undefined) { + getData23(data.paymentId); + window.location.assign("user.html"); + } + }) + .catch((error) => console.log(error)); + } }); } function getData23(result) { @@ -1429,27 +1472,30 @@ function canclePayment() { pid = document.getElementById("pid").value; cid = document.getElementById("cid").value; // bid.removeChild(div); - if (cid == "" || pid == "") window.location.assign("user.html"); - fetch("http://localhost:8080/travel/Payment/" + pid + "/" + cid, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - Authorization: `Basic ${auth}`, - }, - }) - .then((data) => data.json()) - .then((dat) => { - if (dat.message == "Unable to cancle already cancled payment") { - notify(dat.message); - } else if (dat.message == "Payment details not found") { - notify(dat.message); - } else if (dat.message == "Not valid customer") { - notify(dat.message); - } else if (dat.paymentId != undefined) { - getData24(dat.paymentId); - } else window.location.assign("user.html"); + if (cid == "" || cid == " ") notify("Customer id is mandatory"); + else if (pid == "" || pid == " ") notify("Payment id is mandatory"); + else { + fetch("http://localhost:8080/travel/Payment/" + pid + "/" + cid, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${auth}`, + }, }) - .catch((error) => console.log(error)); + .then((data) => data.json()) + .then((dat) => { + if (dat.message == "Unable to cancle already cancled payment") { + notify(dat.message); + } else if (dat.message == "Payment details not found") { + notify(dat.message); + } else if (dat.message == "Not valid customer") { + notify(dat.message); + } else if (dat.paymentId != undefined) { + getData24(dat.paymentId); + } else window.location.assign("user.html"); + }) + .catch((error) => console.log(error)); + } }); } function getData24(result) { diff --git a/Frontend/index.html b/Frontend/index.html index 42c7a09..9e2b812 100644 --- a/Frontend/index.html +++ b/Frontend/index.html @@ -9,7 +9,7 @@