From ce89ff66c4a0ba029543da8adc61b13ae16f7513 Mon Sep 17 00:00:00 2001 From: SarahWohlford <157171746+SarahWohlford@users.noreply.github.com> Date: Fri, 11 Apr 2025 13:14:05 -0400 Subject: [PATCH 1/4] Update opportunity_routes.py Start of opportunity routes --- labconnect/main/opportunity_routes.py | 98 ++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/labconnect/main/opportunity_routes.py b/labconnect/main/opportunity_routes.py index 1dbfe145..4161a1cc 100644 --- a/labconnect/main/opportunity_routes.py +++ b/labconnect/main/opportunity_routes.py @@ -16,6 +16,7 @@ Leads, Opportunities, RecommendsClassYears, + RecommendsCourses, User, Courses, Participates, @@ -584,6 +585,18 @@ def editOpportunity_get(opportunity_id): # RecommendsCourses.opportunity_id == opportunity_id # ) # ).all() + + courses_data = db.session.execute( + db.select(RecommendsCourses.course_code).where( + RecommendsCourses.opportunity_id == opportunity_id + ) + ).all() + + majors_data = db.session.execute( + db.select(RecommendsMajors.major_code).where( + RecommendsMajors.opportunity_id == opportunity_id + ) + ).all() # Query related majors # majors_data = db.session.execute( @@ -803,12 +816,91 @@ def deleteOpportunity(opportunity_id): return {"data": "Opportunity Deleted"} +#Return opportunity data +@main_blueprint.get("/OpportunityRoute/") +@jwt_required() +def saveUserOpportunity(a_opportunity_id): + data = request.get_json() + if not data: + abort(400, "Missing JSON data") + + opportunity_id = db.session.get(Opportunities, opportunity_id) + if not opportunity_id: + return {"error": "Opportunity not found"}, 404 + + user_id = get_jwt_identity() + #opp_id --> opp --> name + + data = db.session.execute( + db.select(Opportunities) + .where(Opportunities.opportunity_id == a_opportunity_id) + ).scalars() + name = data.name + + opportunity = db.session.execute( + db.select(Opportunities).where(Opportunities.id == opportunity_id) + ).scalar_one_or_none() + + if opportunity is None: + abort(400) + + author = db.session.execute( + db.select(User).where(User.email == user_id[0]) + ).scalar_one_or_none() + + leads = db.session.execute( + db.select(Leads) + .where(Leads.opportunity_id == opportunity_id) + .where(Leads.lab_manager_id == author.lab_manager_id) + ).scalar_one_or_none() + try: + pay = int(data["hourlyPay"]) + except ValueError: + pay = None + + one = True if "1" in data["credits"] else False + two = True if "2" in data["credits"] else False + three = True if "3" in data["credits"] else False + four = True if "4" in data["credits"] else False + + lenum = convert_to_enum(data["location"]) + + if lenum is None: + lenum = LocationEnum.TBD + + #hold = [a_opportunity_id, opportunity, description, recomeded_experience, pay, one, two, three, four, + #semester, year, aplication_due, active, location, last_updated, author, leads] + hold = [a_opportunity_id, opportunity, pay, one, two, three, four, author, leads] + return hold + + + #for opps in db.session.execute( + #db.select(opportunity_id).where( + #Opportunities.opportunity_id == opportunity_id + #) + #).scalars() + + + ''' + opportunity.name = request_data["title"] + opportunity.description = request_data["description"] + opportunity.recommended_experience = request_data["recommended_experience"] + opportunity.pay = pay + opportunity.one_credit = one + opportunity.two_credits = two + opportunity.three_credits = three + opportunity.four_credits = four + opportunity.application_due = datetime.strptime( + request_data["application_due"], "%Y-%m-%d" + ) + # opportunity.active = data["active"] + opportunity.location = lenum + opportunity.last_updated = datetime.now()' + ''' -# //////////////////////////////////////////////// # Store opportunities saved by a user # ***Specificaly storing a individual users saved opportunities*** - # Save User Opportunity @main_blueprint.post("/saveUserOpportunity/") @jwt_required() @@ -872,4 +964,4 @@ def deleteUserOpportunity(opportunity_id): db.session.delete(get_saved_opp_info) db.session.commit() - return {"message": "Opportunity deleted"}, 200 + return {"message": "Opportunity deleted"}, 200 \ No newline at end of file From 4c81ec6e49f1cdaac949443aef75de55949fc2cb Mon Sep 17 00:00:00 2001 From: SarahWohlford <157171746+SarahWohlford@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:27:50 -0400 Subject: [PATCH 2/4] Fix way data is returned --- labconnect/main/opportunity_routes.py | 79 ++++++++++++++++++- .../components/Navigation/PageNavigation.js | 1 + 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 react-app/src/shared/components/Navigation/PageNavigation.js diff --git a/labconnect/main/opportunity_routes.py b/labconnect/main/opportunity_routes.py index 4161a1cc..69cb8bd5 100644 --- a/labconnect/main/opportunity_routes.py +++ b/labconnect/main/opportunity_routes.py @@ -867,7 +867,7 @@ def saveUserOpportunity(a_opportunity_id): if lenum is None: lenum = LocationEnum.TBD - + #reformatted #hold = [a_opportunity_id, opportunity, description, recomeded_experience, pay, one, two, three, four, #semester, year, aplication_due, active, location, last_updated, author, leads] hold = [a_opportunity_id, opportunity, pay, one, two, three, four, author, leads] @@ -882,6 +882,7 @@ def saveUserOpportunity(a_opportunity_id): ''' + Data in opportunity opportunity.name = request_data["title"] opportunity.description = request_data["description"] opportunity.recommended_experience = request_data["recommended_experience"] @@ -898,6 +899,82 @@ def saveUserOpportunity(a_opportunity_id): opportunity.last_updated = datetime.now()' ''' +# Return opportunity data +@main_blueprint.get("/OpportunityRoute/") +@jwt_required() +def get_opportunity(opportunity_id): + # Get current user ID from JWT + user_id = get_jwt_identity() + + # Fetch the opportunity + opportunity = db.session.execute( + db.select(Opportunities).where(Opportunities.id == opportunity_id) + ).scalar_one_or_none() + + if opportunity is None: + return {"error": "Opportunity not found"}, 404 + + # Get the user + user = db.session.execute( + db.select(User).where(User.id == user_id) + ).scalar_one_or_none() + + if user is None: + return {"error": "User not found"}, 404 + + # Get the lab manager + leads = db.session.execute( + db.select(Leads) + .where(Leads.opportunity_id == opportunity_id) + .where(Leads.lab_manager_id == user.lab_manager_id) + ).scalar_one_or_none() + + # Might need + author = db.session.execute( + db.select(User).where(User.email == user_id[0]) + ).scalar_one_or_none() + + rec_major = db.session.execute( + db.select(RecommendsMajors).where(RecommendsMajors.opportunity_id == opportunity_id) + ).scalar_one_or_none() + + rec_course = db.session.execute( + db.select(RecommendsCourses).where(RecommendsCourses.opportunity_id == opportunity_id) + ).scalar_one_or_none() + + rec_class_years = db.session.execute( + db.select(RecommendsClassYears).where(RecommendsClassYears.opportunity_id == opportunity_id) + ).scalar_one_or_none() + + # Structure the opportunity data to return + information = { + "id": opportunity.id, + "name": opportunity.name, + "description": opportunity.description, + "recommended_experience": opportunity.recommended_experience, + "pay": opportunity.pay, + "credits": { + "one_credit": opportunity.one_credit, + "two_credits": opportunity.two_credits, + "three_credits": opportunity.three_credits, + "four_credits": opportunity.four_credits, + }, + "semester": opportunity.semester, + "year": opportunity.year, + "application_due": opportunity.application_due.isoformat() if opportunity.application_due else None, + "active": opportunity.active, + "location": opportunity.location.name if opportunity.location else None, + "last_updated": opportunity.last_updated.isoformat() if opportunity.last_updated else None, + "leads_by_user_lab": leads is not None, + "author": author.id, + "rec_major": rec_major.major_code, + "rec_course": rec_course.course_code, + "rec_class_years": rec_class_years.class_years + } + + #return jsonify(information), 200 + return information, 200 + # Store opportunities saved by a user # ***Specificaly storing a individual users saved opportunities*** diff --git a/react-app/src/shared/components/Navigation/PageNavigation.js b/react-app/src/shared/components/Navigation/PageNavigation.js new file mode 100644 index 00000000..33662f55 --- /dev/null +++ b/react-app/src/shared/components/Navigation/PageNavigation.js @@ -0,0 +1 @@ +/* From e3d4136d8cf73dcf9a82fa6a041bd236cd8874b1 Mon Sep 17 00:00:00 2001 From: SarahWohlford <157171746+SarahWohlford@users.noreply.github.com> Date: Sat, 19 Apr 2025 19:47:37 -0400 Subject: [PATCH 3/4] Final clean up --- labconnect/main/opportunity_routes.py | 109 ++------------------------ 1 file changed, 7 insertions(+), 102 deletions(-) diff --git a/labconnect/main/opportunity_routes.py b/labconnect/main/opportunity_routes.py index 69cb8bd5..72a8e79a 100644 --- a/labconnect/main/opportunity_routes.py +++ b/labconnect/main/opportunity_routes.py @@ -87,6 +87,7 @@ def packageIndividualOpportunity(opportunityInfo): "recommended_experience": opportunityInfo.recommended_experience, "authors": "", "department": "", + "authorProfile": "", "pay": opportunityInfo.pay, "credits": None, "semester": f"{opportunityInfo.semester} {opportunityInfo.year}", @@ -585,18 +586,6 @@ def editOpportunity_get(opportunity_id): # RecommendsCourses.opportunity_id == opportunity_id # ) # ).all() - - courses_data = db.session.execute( - db.select(RecommendsCourses.course_code).where( - RecommendsCourses.opportunity_id == opportunity_id - ) - ).all() - - majors_data = db.session.execute( - db.select(RecommendsMajors.major_code).where( - RecommendsMajors.opportunity_id == opportunity_id - ) - ).all() # Query related majors # majors_data = db.session.execute( @@ -816,89 +805,6 @@ def deleteOpportunity(opportunity_id): return {"data": "Opportunity Deleted"} -#Return opportunity data -@main_blueprint.get("/OpportunityRoute/") -@jwt_required() -def saveUserOpportunity(a_opportunity_id): - data = request.get_json() - if not data: - abort(400, "Missing JSON data") - - opportunity_id = db.session.get(Opportunities, opportunity_id) - if not opportunity_id: - return {"error": "Opportunity not found"}, 404 - - user_id = get_jwt_identity() - #opp_id --> opp --> name - - data = db.session.execute( - db.select(Opportunities) - .where(Opportunities.opportunity_id == a_opportunity_id) - ).scalars() - name = data.name - - opportunity = db.session.execute( - db.select(Opportunities).where(Opportunities.id == opportunity_id) - ).scalar_one_or_none() - - if opportunity is None: - abort(400) - - author = db.session.execute( - db.select(User).where(User.email == user_id[0]) - ).scalar_one_or_none() - - leads = db.session.execute( - db.select(Leads) - .where(Leads.opportunity_id == opportunity_id) - .where(Leads.lab_manager_id == author.lab_manager_id) - ).scalar_one_or_none() - try: - pay = int(data["hourlyPay"]) - except ValueError: - pay = None - - one = True if "1" in data["credits"] else False - two = True if "2" in data["credits"] else False - three = True if "3" in data["credits"] else False - four = True if "4" in data["credits"] else False - - lenum = convert_to_enum(data["location"]) - - if lenum is None: - lenum = LocationEnum.TBD - #reformatted - #hold = [a_opportunity_id, opportunity, description, recomeded_experience, pay, one, two, three, four, - #semester, year, aplication_due, active, location, last_updated, author, leads] - hold = [a_opportunity_id, opportunity, pay, one, two, three, four, author, leads] - return hold - - - #for opps in db.session.execute( - #db.select(opportunity_id).where( - #Opportunities.opportunity_id == opportunity_id - #) - #).scalars() - - - ''' - Data in opportunity - opportunity.name = request_data["title"] - opportunity.description = request_data["description"] - opportunity.recommended_experience = request_data["recommended_experience"] - opportunity.pay = pay - opportunity.one_credit = one - opportunity.two_credits = two - opportunity.three_credits = three - opportunity.four_credits = four - opportunity.application_due = datetime.strptime( - request_data["application_due"], "%Y-%m-%d" - ) - # opportunity.active = data["active"] - opportunity.location = lenum - opportunity.last_updated = datetime.now()' - ''' - # Return opportunity data @main_blueprint.get("/OpportunityRoute/") @jwt_required() @@ -906,7 +812,7 @@ def get_opportunity(opportunity_id): # Get current user ID from JWT user_id = get_jwt_identity() - # Fetch the opportunity + #Get the opportunity opportunity = db.session.execute( db.select(Opportunities).where(Opportunities.id == opportunity_id) ).scalar_one_or_none() @@ -923,7 +829,7 @@ def get_opportunity(opportunity_id): return {"error": "User not found"}, 404 # Get the lab manager - leads = db.session.execute( + labManager = db.session.execute( db.select(Leads) .where(Leads.opportunity_id == opportunity_id) .where(Leads.lab_manager_id == user.lab_manager_id) @@ -947,7 +853,7 @@ def get_opportunity(opportunity_id): ).scalar_one_or_none() # Structure the opportunity data to return - information = { + allData = { "id": opportunity.id, "name": opportunity.name, "description": opportunity.description, @@ -965,15 +871,14 @@ def get_opportunity(opportunity_id): "active": opportunity.active, "location": opportunity.location.name if opportunity.location else None, "last_updated": opportunity.last_updated.isoformat() if opportunity.last_updated else None, - "leads_by_user_lab": leads is not None, + "lab_managers": labManager is not None, "author": author.id, "rec_major": rec_major.major_code, "rec_course": rec_course.course_code, "rec_class_years": rec_class_years.class_years } - - #return jsonify(information), 200 - return information, 200 + + return allData, 200 # Store opportunities saved by a user # ***Specificaly storing a individual users saved opportunities*** From c1244bb963db23261453907ba0a922be69815e65 Mon Sep 17 00:00:00 2001 From: SarahWohlford <157171746+SarahWohlford@users.noreply.github.com> Date: Tue, 3 Jun 2025 14:48:25 -0400 Subject: [PATCH 4/4] Last changes --- labconnect/main/opportunity_routes.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/labconnect/main/opportunity_routes.py b/labconnect/main/opportunity_routes.py index 72a8e79a..ff9f938a 100644 --- a/labconnect/main/opportunity_routes.py +++ b/labconnect/main/opportunity_routes.py @@ -805,8 +805,8 @@ def deleteOpportunity(opportunity_id): return {"data": "Opportunity Deleted"} -# Return opportunity data -@main_blueprint.get("/OpportunityRoute/") +# Return all opportunity data +@main_blueprint.get("/OpportunityRoute/") @jwt_required() def get_opportunity(opportunity_id): # Get current user ID from JWT @@ -835,11 +835,7 @@ def get_opportunity(opportunity_id): .where(Leads.lab_manager_id == user.lab_manager_id) ).scalar_one_or_none() - # Might need - author = db.session.execute( - db.select(User).where(User.email == user_id[0]) - ).scalar_one_or_none() - + #red_major, rec_courses, rec_class_years rec_major = db.session.execute( db.select(RecommendsMajors).where(RecommendsMajors.opportunity_id == opportunity_id) ).scalar_one_or_none() @@ -867,12 +863,15 @@ def get_opportunity(opportunity_id): }, "semester": opportunity.semester, "year": opportunity.year, - "application_due": opportunity.application_due.isoformat() if opportunity.application_due else None, + "application_due" : + (opportunity.application_due.isoformat() if opportunity.application_due else None), "active": opportunity.active, - "location": opportunity.location.name if opportunity.location else None, - "last_updated": opportunity.last_updated.isoformat() if opportunity.last_updated else None, - "lab_managers": labManager is not None, - "author": author.id, + "location": + (opportunity.location.name if opportunity.location else None), + "last_updated": + (opportunity.last_updated.isoformat() if opportunity.last_updated else None), + "is_there_lab_managers": labManager is not None, + "lab_managers_id" : labManager.id, "rec_major": rec_major.major_code, "rec_course": rec_course.course_code, "rec_class_years": rec_class_years.class_years