Upload files to ''

master
Manish 2 years ago
parent 8c000375d9
commit e203994212

@ -0,0 +1,69 @@
#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=salon --no-align --tuples-only -c"
echo -e "\n~~~~~ MY SALON ~~~~~\n"
echo -e "Welcome to My Salon, how can I help you?\n"
MAIN_MENU() {
if [[ $1 ]]
then
echo -e "$1"
fi
SERVICES="$($PSQL "SELECT service_id, name FROM services")"
echo "$SERVICES" | while IFS="|" read SERVICE_ID SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
read SERVICE_ID_SELECTED
if [[ $SERVICE_ID_SELECTED =~ [0-9]+ ]]
then
SERVICE_ID_CHECK=$($PSQL "SELECT service_id FROM services WHERE service_id=$SERVICE_ID_SELECTED")
if [[ -z $SERVICE_ID_CHECK ]]
then
MAIN_MENU "\nI could not find that service. What would you like today?"
else
BOOK_SERVICE $SERVICE_ID_SELECTED;
fi
else
MAIN_MENU "\nI could not find that service. What would you like today?"
fi
}
BOOK_SERVICE() {
if [[ $1 ]]
then
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$1")
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
if [[ $CUSTOMER_PHONE =~ ^[0-9]+(-[0-9]+)+$ ]]
then
# check number in db
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
# if not found than ask for name
if [[ -z $CUSTOMER_ID ]]
then
echo -e "\nI don't have a record for that phone number, what's your name?"
IFS=$'\n\t\r' read CUSTOMER_NAME
ADD_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$CUSTOMER_PHONE')")
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
else
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone='$CUSTOMER_PHONE'")
fi
# ask for time
echo -e "\nWhat time would you like your cut, $CUSTOMER_NAME?"
read SERVICE_TIME
# book appointment
BOOKING_RESULT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $1, '$SERVICE_TIME')")
echo -e "\nI have put you down for a $SERVICE_NAME at $SERVICE_TIME, $CUSTOMER_NAME."
else
echo -e "That is not a valid number.\n"
BOOK_SERVICE $1
fi
fi
}
MAIN_MENU

@ -0,0 +1,286 @@
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
DROP DATABASE salon;
--
-- Name: salon; Type: DATABASE; Schema: -; Owner: freecodecamp
--
CREATE DATABASE salon WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';
ALTER DATABASE salon OWNER TO freecodecamp;
\connect salon
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: appointments; Type: TABLE; Schema: public; Owner: freecodecamp
--
CREATE TABLE public.appointments (
appointment_id integer NOT NULL,
customer_id integer NOT NULL,
service_id integer NOT NULL,
"time" character varying(20) NOT NULL
);
ALTER TABLE public.appointments OWNER TO freecodecamp;
--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--
CREATE SEQUENCE public.appointments_appointment_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.appointments_appointment_id_seq OWNER TO freecodecamp;
--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--
ALTER SEQUENCE public.appointments_appointment_id_seq OWNED BY public.appointments.appointment_id;
--
-- Name: customers; Type: TABLE; Schema: public; Owner: freecodecamp
--
CREATE TABLE public.customers (
customer_id integer NOT NULL,
name character varying(100) NOT NULL,
phone character varying(20) NOT NULL
);
ALTER TABLE public.customers OWNER TO freecodecamp;
--
-- Name: customers_customer_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--
CREATE SEQUENCE public.customers_customer_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.customers_customer_id_seq OWNER TO freecodecamp;
--
-- Name: customers_customer_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--
ALTER SEQUENCE public.customers_customer_id_seq OWNED BY public.customers.customer_id;
--
-- Name: services; Type: TABLE; Schema: public; Owner: freecodecamp
--
CREATE TABLE public.services (
service_id integer NOT NULL,
name character varying(100) NOT NULL
);
ALTER TABLE public.services OWNER TO freecodecamp;
--
-- Name: services_service_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--
CREATE SEQUENCE public.services_service_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.services_service_id_seq OWNER TO freecodecamp;
--
-- Name: services_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--
ALTER SEQUENCE public.services_service_id_seq OWNED BY public.services.service_id;
--
-- Name: appointments appointment_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.appointments ALTER COLUMN appointment_id SET DEFAULT nextval('public.appointments_appointment_id_seq'::regclass);
--
-- Name: customers customer_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.customers ALTER COLUMN customer_id SET DEFAULT nextval('public.customers_customer_id_seq'::regclass);
--
-- Name: services service_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.services ALTER COLUMN service_id SET DEFAULT nextval('public.services_service_id_seq'::regclass);
--
-- Data for Name: appointments; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--
INSERT INTO public.appointments VALUES (1, 6, 1, '10:30');
INSERT INTO public.appointments VALUES (2, 6, 2, '11am');
INSERT INTO public.appointments VALUES (3, 6, 1, '10:30');
INSERT INTO public.appointments VALUES (4, 6, 1, '10:30');
INSERT INTO public.appointments VALUES (17, 32, 1, '9am');
INSERT INTO public.appointments VALUES (18, 33, 1, 'Test');
INSERT INTO public.appointments VALUES (19, 34, 1, '10am');
--
-- Data for Name: customers; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--
INSERT INTO public.customers VALUES (6, 'Fabio', '555-555-5555');
INSERT INTO public.customers VALUES (32, 'Tes', '111-111-1111');
INSERT INTO public.customers VALUES (33, 'Tes', '222-222-2222');
INSERT INTO public.customers VALUES (34, 'Test', '333-333-3333');
--
-- Data for Name: services; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--
INSERT INTO public.services VALUES (1, 'cut');
INSERT INTO public.services VALUES (2, 'color');
INSERT INTO public.services VALUES (3, 'perm');
INSERT INTO public.services VALUES (4, 'style');
INSERT INTO public.services VALUES (5, 'trim');
--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--
SELECT pg_catalog.setval('public.appointments_appointment_id_seq', 25, true);
--
-- Name: customers_customer_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--
SELECT pg_catalog.setval('public.customers_customer_id_seq', 39, true);
--
-- Name: services_service_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--
SELECT pg_catalog.setval('public.services_service_id_seq', 5, true);
--
-- Name: appointments appointments_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.appointments
ADD CONSTRAINT appointments_pkey PRIMARY KEY (appointment_id);
--
-- Name: customers customers_phone_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.customers
ADD CONSTRAINT customers_phone_key UNIQUE (phone);
--
-- Name: customers customers_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.customers
ADD CONSTRAINT customers_pkey PRIMARY KEY (customer_id);
--
-- Name: services services_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.services
ADD CONSTRAINT services_name_key UNIQUE (name);
--
-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.services
ADD CONSTRAINT services_pkey PRIMARY KEY (service_id);
--
-- Name: appointments appointments_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.appointments
ADD CONSTRAINT appointments_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(customer_id);
--
-- Name: appointments appointments_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.appointments
ADD CONSTRAINT appointments_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(service_id);
--
-- PostgreSQL database dump complete
--
Loading…
Cancel
Save