-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsalon.sh
52 lines (43 loc) · 1.51 KB
/
salon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=salon --tuples-only --no-align -c"
MENU() {
echo -e "\n~~~~~ MY SALON ~~~~~"
echo "Select service ID:"
services=$($PSQL "SELECT service_id, name FROM services")
echo "$services" | while IFS="|" read service_id name; do
echo "$service_id) $name"
done
}
GET_SERVICE_ID() {
read SERVICE_ID_SELECTED
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]; then
echo "I could not find that service. What would you like today?"
MENU
GET_SERVICE_ID
return
fi
id=$($PSQL "SELECT service_id FROM services WHERE service_id=$SERVICE_ID_SELECTED")
if [[ -z $id ]]; then
echo "I could not find that service. What would you like today?"
MENU
GET_SERVICE_ID
else
echo "Selected Service ID: $id"
fi
}
MENU
GET_SERVICE_ID
echo "CUSTOMER Phone: "
read CUSTOMER_PHONE
customer=$($PSQL "SELECT name FROM customers where phone='$CUSTOMER_PHONE';")
if [[ -z $customer ]]; then
echo "CUSTOMER_NAME"
read CUSTOMER_NAME
$($PSQL "INSERT INTO customers(name,phone) VALUES('$CUSTOMER_NAME','$CUSTOMER_PHONE')")
fi;
echo "SERVICE_TIME"
read SERVICE_TIME
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE';")
$PSQL "INSERT INTO appointments (customer_id, service_id, time) VALUES ($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')"
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$SERVICE_ID_SELECTED;")
echo "I have put you down for a $SERVICE_NAME at $SERVICE_TIME, $CUSTOMER_NAME."