[RDB] Clarify Salon Appointment Scheduler "Subtask 1.1:16" user story
See original GitHub issueAffected page
Relational Database Alpha Salon Appointment Scheduler
Your code
#! /bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
# display title
echo -e "\n~~~~~ MY SALON ~~~~~\n"
echo -e "Welcome to My Salon, how can I help you?\n"
# get services
SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id;")
MAIN_MENU(){
# display argument if exist
if [[ $1 ]]
then
echo -e "\n$1"
fi
# show service menu
echo "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
read SERVICE_ID_SELECTED
#if input is not INT
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
then
# return to main menu
MAIN_MENU "I could not find that service. What would you like today?"
fi
SERVICE_ID=$($PSQL "SELECT service_id FROM services WHERE service_id =$SERVICE_ID_SELECTED;")
#if the number input not found
if [[ -z $SERVICE_ID ]]
then
# return to main menu
MAIN_MENU "I could not find that service. What would you like today?"
fi
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$SERVICE_ID")
# if a valid option
# ask for phone number
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone='$CUSTOMER_PHONE';")
# if customer not found
if [[ -z $CUSTOMER_NAME ]]
then
# ask for customer name
echo -e "\nI don't have a record for that phone number, what's your name?"
read CUSTOMER_NAME
# insert customer data
UPDATE_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE','$CUSTOMER_NAME');")
fi
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE';")
# add appointment time
echo -e "\nWhat time would you like your $(echo $SERVICE_NAME | sed -r 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')?"
read SERVICE_TIME
# if no time input
if [[ -z $SERVICE_TIME ]]
then
MAIN_MENU "You have to input the time, please try again"
fi
#insert appointment
APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID, '$SERVICE_TIME')")
if [[ $APPOINTMENT_RESULT=='INSERT 0 1' ]]
then
echo -e "\nI have put you down for a $(echo $SERVICE_NAME | sed -r 's/^ *| *$//g') at $(echo $SERVICE_TIME | sed -r 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')."
else
MAIN_MENU "Unexpected error occur, please try again."
fi
}
MAIN_MENU
Expected behavior
I expect it should pass subtask 1.1:16 “If you pick a service that doesn’t exist, you should be shown the same list of services again”
Screenshots
System
- Device: [e.g. iPhone6, Laptop]
- OS: [e.g. iOS 14, Windows 10, Ubuntu 20.4]
- Browser: [e.g. chrome, safari]
- Version: [e.g. 22]
Additional context
I tried many times, and the code seems fulfill all requirements (especially subtask 1.1:16) (passed all other subtask already) It’s great if anyone can point out the problem
After the user input SERVICE_ID_SELECTED, the code check whether input is a number. If it is a number, the code will check whether the service_id exist in services table. User will be sent back to MAIN_MENU if either condition do not pass
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ppdb-1.0-xxxl-lexical.extended.synonyms.uniquepairs
31,25 31.25 7,08 7.08 4,42 4.42 bosphorus bosporus mahmoud mahmud preinstall preinstalling al-helwa el-helwa on-line online co-production coproduction ...
Read more >[RDB] Clarify Salon Appointment Scheduler "Subtask 1.1:16 ...
[RDB] Clarify Salon Appointment Scheduler "Subtask 1.1:16" user story ... I can look into rewording that user story so it's more clear on ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks so mush again!! I try to keep my code more readable and avoid nested code Didn’t realize that I have to set exit procedure for the function As a self-learner who not in the industry yet, really learn a lot from freeCodeCamp, thank you
Reopening, because I think that user story could use some clarification.