Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Most code is based on and adapted from the CS 340 starter code including:
1. app routes and app.py
adapted to fit our needs
2. tempates
2. templates
adapted to improve UX
3. style.css
copied
Expand Down Expand Up @@ -55,6 +55,18 @@ Links to an external site.
7 # I Source URL: https://www.google.com/search?sourceid=chrome&udm=50&aep=42&source=chrome.crn.rb
Links to an external site.

# Date: 3/11/26
# Prompts used to debug logic for to delete skierslifts button error handling
# Provided gemini my roll back error handling results and asked it to show exist handler options.
4 # I Source URL: https://www.google.com/search?sourceid=chrome&udm=50&aep=42&source=chrome.crn.rb
Links to an external site.

# Date: 3/12/26
4 # Prompts used to consult on the usage of cursor.nextset() in Trails
# Requested scenarios where the cursor moves the next result set.
# I Source URL: https://www.google.com/search?sourceid=chrome&udm=50&aep=42&source=chrome.crn.rb
Links to an external site.

# Date: 3/13/26
# Prompts used to add logic for to update rentals button
4 # I provided my route and asked for an update form that only appears after the button is pressed and is automatically filled with the row ID
Expand All @@ -69,3 +81,4 @@ Links to an external site.
Links to an external site.



41 changes: 41 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,47 @@ def delete_rentalinventory():
dbConnection.close()


# create trail

@app.route("/trails/create", methods=["POST"])
def create_trails():
try:
dbConnection = db.connectDB() # this opens skiers db connection
cursor = dbConnection.cursor()

# Get form data. will do data cleansing try/catch blocks later since we don't have int input for the following attributes:
Name = request.form["create_trail_name"]
Difficulty = request.form["create_trail_difficulty"]
TrailLength = request.form["create_trail_trailLength"]
Status = request.form["create_trail_status"]


# call create trails sp method
query1 = "CALL sp_CreateTrail(%s, %s, %s, %s, @t_new_id);"
cursor.execute(query1, (Name, Difficulty, TrailLength, Status))
cursor.nextset()
# store the generated trail id for the last inserted row.
cursor.execute("SELECT @new_id;")
new_id = cursor.fetchone()[0] # id is index 0 of the row
# cursor.nextset() # Move the the next result. Assuming this to move to the next row?
dbConnection.commit() #commit transaction
print(f"""Create skiers.
ID: {new_id}
Name: {Name}
Difficulty {Difficulty}
TrailLength {TrailLength}
Status {Status}
""")
# Redirect to the updated webpage by add the path /skiers
return redirect("/trails")
except Exception as e:
print(f"Error executing quereis: {e}")
return ("An error occurred while executing trails/create this database queries. ", 500,) # ProgError, OpsError, DBError? can be more specific
finally:
# Close the DB Conneciton, if it exists:
if "dbConnection" in locals() and dbConnection:
dbConnection.close()


# --------------------------------------------------------------------------------------------------
# SkiersRentals CRUD
Expand Down
129 changes: 88 additions & 41 deletions database/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,36 @@
-- create Skiers input
INSERT INTO `Skiers` (`Name`, `Address`, `Phone`, `Email`, `Ability`)
VALUES ( @Name, @Address, @Phone, @Email, @Ability);

-- Read all Skiers
SELECT * FROM `Skiers`;

-- Read a specific Skier by ID
-- SET @SkierID = 3;
SELECT * FROM `Skiers` WHERE `SkierID` = @SkierID

-- Update a Skier's information
UPDATE `Skiers`
SET `Name` = @Name, `Address` = @Address, `Phone` = @Phone, `Email` = @Email, `Ability` = @Ability
WHERE `SkierID` = @SkierID;

-- Delete a Skier
-- SET @SkierID = 5;
DELETE FROM `Skiers` WHERE `SkierID` = @SkierID;
-- Update a Skier
SET @SkierID = 1;
SET @Name = "John Smith";
SET @Address = "123 1ST St";
SET @Phone = "1234567891";
SET @Email = "js@example.com";
SET @Ability = "Expert";

------------------------------------------------------
-- Trails CRUD Operations
-- -----------------------------------------------------
-- create Trails input
INSERT INTO `Trails` (`Name`, `Difficulty`, `Length`, `Status`)
VALUES ( @Name, @Difficulty, @Length, @Status);
UPDATE Skiers
SET Name = @Name,
Address = @Address,
Phone = @Phone,
Email = @Email,
Ability = @Ability
WHERE SkierID = @SkierID;

-- Read all Trails
SELECT * FROM `Trails`;
-- Read a specific Trail by ID
SELECT * FROM `Trails` WHERE `TrailID` = @TrailID;
-- Update a Trail's information
UPDATE `Trails`
SET `Name` = @Name, `Difficulty` = @Difficulty, `Length` = @Length, `Status` = @Status
WHERE `TrailID` = @TrailID;
-- Delete a Trail
DELETE FROM `Trails` WHERE `TrailID` = @TrailID;
-- ---------------------------------------------------
--SkiersTrails CRUD Operations
-- -----------------------------------------------------
-- create SkiersTrails input
INSERT INTO `SkiersTrails` (`Skiers_SkierID`, `Trails_TrailID`) VALUES ( @Skiers_SkierID, @Trails_TrailID);
-- Read all SkiersTrails
SELECT * FROM `SkiersTrails`;
-- Read a specific SkiersTrails item by ID
SELECT * FROM `SkiersTrails` WHERE `SkiersTrailsID` = @SkiersTrailsID;
-- Update a SkiersTrails item's information
UPDATE `SkiersTrails`
SET `Skiers_SkierID` = @Skiers_SkierID, `Trails_TrailID` = @Trails_TrailID
WHERE `SkiersTrailsID` = @SkiersTrailsID;
-- Delete a SkiersTrails item
DELETE FROM `SkiersTrails` WHERE `SkiersTrailsID` = @SkiersTrailsID;
------------------------------------------------------
-- Lifts CRUD Operations
-- -----------------------------------------------------
-- create Lifts input
INSERT INTO `Lifts` (`LiftNum`, `LiftName`, `TravelTime`, `ChairCapacity`, `Status`, `Altitude`)
VALUES ( @LiftNum, @LiftName, @TravelTime, @ChairCapacity, @Status, @Altitude);

-- Read all Lifts
SELECT * FROM `Lifts`;
-- Read a specific Lift by ID
Expand Down Expand Up @@ -88,8 +64,68 @@ WHERE `SkiersLiftsID` = @SkiersLiftsID;
-- Delete a SkiersLifts item
DELETE FROM `SkiersLifts` WHERE `SkiersLiftsID` = @SkiersLiftsID;

SELECT s.SkierID, s.Name, p.Type, t.TrailName, t.Difficulty
FROM Passes AS p
JOIN Skiers AS s
ON p.PassID = s.SkierID
JOIN SkiersTrails AS st
ON s.SkierID = st.Skiers_SkierID
JOIN Trails AS t
ON st.Trails_TrailID = t.TrailID
WHERE p.Type = "Full Season"
GROUP By s.SkierID, s.Name
HAVING AVG (t.TrailLength) > 1200;
------------------------------------------------------
--Passes CRUD Operations
-- Trails CRUD Operations
-- -----------------------------------------------------
-- create Trails input
INSERT INTO `Trails` (`TrailName`, `Difficulty`, `TrailLength`, `Status`)
VALUES ( @TrailName, @Difficulty, @TrailLength, @Status);
-- Read all Trails
SELECT * FROM `Trails`;
-- Read a specific Trail by ID
-- SET @TrailID = 4;
SELECT * FROM `Trails` WHERE `TrailID` = @TrailID;
-- Update a Trail's information
-- SET @TrailID = 3;
UPDATE `Trails`
SET `Name` = @Name, `Difficulty` = @Difficulty, `TrailLength` = @TrailLength, `Status` = @Status
WHERE `TrailID` = @TrailID;
-- Delete a Trail
-- SET @TrailID = 2;
DELETE FROM `Trails` WHERE `TrailID` = @TrailID;

-- ---------------------------------------------------
--SkiersTrails CRUD Operations
-- -----------------------------------------------------
-- create SkiersTrails input
INSERT INTO `SkiersTrails` (`Skiers_SkierID`, `Trails_TrailID`) VALUES ( @Skiers_SkierID, @Trails_TrailID);
-- Read all SkiersTrails
SELECT * FROM `SkiersTrails`;
-- Read a specific SkiersTrails item by ID
SELECT * FROM `SkiersTrails` WHERE `SkiersTrailsID` = @SkiersTrailsID;
-- Update a SkiersTrails item's information
UPDATE `SkiersTrails`
SET `Skiers_SkierID` = @Skiers_SkierID, `Trails_TrailID` = @Trails_TrailID
WHERE `SkiersTrailsID` = @SkiersTrailsID;
-- Delete a SkiersTrails item
DELETE FROM `SkiersTrails` WHERE `SkiersTrailsID` = @SkiersTrailsID;

-- View to return Expert Skiers whose average Lift Altitude above 8000
CREATE VIEW ExpertSkiersWithHighAlt AS
SELECT Skiers.SkierID, Skiers.Name, Lifts.LiftName, Lifts.Altitude
FROM Skiers
JOIN SkiersLifts
ON Skiers.SkierID = SkiersLifts.Skiers_SkierID
JOIN Lifts
ON SkiersLifts.Lifts_LiftID = Lifts.LiftID
WHERE Skiers.Ability = "Expert"
GROUP By Skiers.SkierID, Skiers.Name
HAVING AVG(Lifts.Altitude) > 8000;

SELECT * FROM ExpertSkiersWithHighAlt;
------------------------------------------------------
-- Passes CRUD Operations
-- -----------------------------------------------------
-- create Passes input
INSERT INTO `Passes` (`Type`, `PurchaseDate`, `ExpirationDate`, `Skiers_SkierID`)
Expand All @@ -104,6 +140,7 @@ SET `Type` = @Type, `PurchaseDate` = @PurchaseDate, `ExpirationDate` = @Expirati
WHERE `PassID` = @PassID;
-- Delete a Pass
DELETE FROM `Passes` WHERE `PassID` = @PassID;

------------------------------------------------------
-- Rentals CRUD Operations
-- -----------------------------------------------------
Expand All @@ -119,6 +156,7 @@ SET `Type` = @Type
WHERE `RentalID` = @RentalID;
-- Delete a RentalInventory item
DELETE FROM `RentalInventory` WHERE `RentalID` = @RentalID;

------------------------------------------------------
-- SkiersRentals CRUD Operations
-- -----------------------------------------------------
Expand All @@ -135,3 +173,12 @@ WHERE `SkiersRentalsID` = @SkiersRentalsID;
-- Delete a SkiersRentals item
DELETE FROM `SkiersRentals` WHERE `SkiersRentalsID` = @SkiersRentalsID;

-- Return all expert skiers and the equipment type they rented:
SELECT DISTINCT Skiers.Name, Skiers.Ability, RentalInventory.Type
FROM Skiers
JOIN SkiersRentals
ON Skiers.SkierID = SkiersRentals.Skiers_SkierID
JOIN RentalInventory
ON SkiersRentals.RentalInventory_RentalID = RentalInventory.RentalID
WHERE Skiers.Ability = "Expert";

23 changes: 23 additions & 0 deletions database/PL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,26 @@ BEGIN

END //
DELIMITER ;


-- Create Trails SP:
DROP PROCEDURE IF EXISTS sp_CreateTrail;

DELIMITER //
create procedure sp_CreateTrail(
in t_name varchar(45),
in t_difficulty varchar(255),
in t_trailLength varchar(11),
in t_status varchar(255),
out t_id int)
BEGIN
insert INTO Trails(TrailName, Difficulty, TrailLength, Status)
VALUES (t_name, t_difficulty, t_trailLength, t_status);

-- store the skier id of the last inserted row:
select last_insert_id() into t_id;
-- then display id of the last inserted row
select last_insert_id() AS 't_new_id';

END //
DELIMITER ;
25 changes: 25 additions & 0 deletions templates/trails.j2
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,30 @@
</tbody>
</table>

<h2>Create a Trail</h2>
<form class="cuForm" id="create_trail_form" method="POST" action="/trails/create">

<label for="create_trail_name"> Name: </label>
<input type="text" name="create_trail_name" id="create_trail_name" required>

<label for="create_trail_difficulty"> Difficulty: </label>
<select name="create_trail_difficulty" id="create_trail_difficulty" required>
<option value="" disabled selected>Select ability level</option>
<option value="Blue">Blue</option>
<option value="Green">Green</option>
<option value="Black">Black</option>
</select>

<label for="create_trail_trailLength"> TrailLength: </label>
<input type="text" name="create_trail_trailLength" id="create_trail_trailLength" required>

<label for="create_trail_status"> Status: </label>
<input type="text" name="create_trail_status" id="create_trail_status" required>

</select>

<input type="submit">
</form>


{% endblock %}