Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
b9783db
Created all api files
kanghosaeyo Aug 12, 2025
e2ac6ee
added database
kanghosaeyo Aug 12, 2025
45470a8
Merge pull request #1 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
60aee78
put stuff in the database
kanghosaeyo Aug 12, 2025
3f17845
Merge pull request #2 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
1dedfd4
Renamed folders
aga1936 Aug 12, 2025
06a60db
Renamed folders
aga1936 Aug 12, 2025
db8e240
added route for updating student profiles in /users
kanghosaeyo Aug 12, 2025
991d584
Merge pull request #3 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
d68d89e
query for finding status of application for student
aga1936 Aug 12, 2025
c00ede5
updated application status viewing api calls
kanghosaeyo Aug 12, 2025
7313d0f
Merge pull request #5 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
b37286d
Added company viewin
kanghosaeyo Aug 12, 2025
1a5507c
Merge pull request #6 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
a4f369c
added api for viewing avgPay per industry
kanghosaeyo Aug 12, 2025
9b459be
Merge pull request #7 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
a0a6962
Added and edited api routes for avg pay, placement data, company ratings
kanghosaeyo Aug 12, 2025
6342449
Merge pull request #8 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
55a02df
added api routes for identifying students with few apps
kanghosaeyo Aug 12, 2025
8b1d36e
Merge pull request #9 from kanghosaeyo/oscar
kanghosaeyo Aug 12, 2025
f225d16
added query for persona 1 to view num apps
aga1936 Aug 13, 2025
dc916b3
change position preference
aga1936 Aug 13, 2025
84a5d40
fixed error with applications route for students
aga1936 Aug 13, 2025
58842a9
fixed typo in function name in applications
aga1936 Aug 13, 2025
0fa835a
created main page
kanghosaeyo Aug 13, 2025
d64638f
Merge pull request #10 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
6c506fa
Added all the home pages for each persona
kanghosaeyo Aug 13, 2025
249a926
Merge pull request #11 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
6dd6c1c
api route for deadlines
aga1936 Aug 13, 2025
f44659d
Added mock data
kanghosaeyo Aug 13, 2025
000b6f7
Merge pull request #12 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
43ef2ab
deleted question mark
kanghosaeyo Aug 13, 2025
232e045
Merge pull request #13 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
a2412f9
api route for desired skills
aga1936 Aug 13, 2025
9819d26
Merge branch 'ana_antic'
aga1936 Aug 13, 2025
0c3939d
api for required skills
aga1936 Aug 13, 2025
427ccc8
Merge branch 'ana_antic'
aga1936 Aug 13, 2025
f53899a
Fixed database and updated student page
kanghosaeyo Aug 13, 2025
8d0cb8f
Merge branch 'main' of https://github.com/kanghosaeyo/Coopalytics int…
kanghosaeyo Aug 13, 2025
d7e8ae5
Merge pull request #14 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
91f360d
employer view profile
allymayo Aug 13, 2025
81f9905
ignor
kanghosaeyo Aug 13, 2025
d72a552
Merge pull request #15 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
379eaf4
reverted back to no api connection in student home, can someone help me
kanghosaeyo Aug 13, 2025
2c70f68
Merge pull request #16 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
23cded6
filter applicants
allymayo Aug 13, 2025
db3e8e5
added all pages + fixed side bar navigation
kanghosaeyo Aug 13, 2025
6b46845
Merge pull request #17 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
fca9d30
allow admins to review job postings before approval, shows unflagged …
suripeddis Aug 13, 2025
29ac429
exmployer post position
allymayo Aug 13, 2025
9749767
admine can review positions before they go live
suripeddis Aug 13, 2025
f209950
admin can review positions (redo)
suripeddis Aug 13, 2025
b3a8466
Merge pull request #18 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
eb31949
added api calls in student homepage and fixed mock data
kanghosaeyo Aug 13, 2025
55ae2a4
Merge pull request #19 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
5b45eeb
Add a simple admin list of jobs to review that shows unflagged co-op …
suripeddis Aug 13, 2025
07e5cb8
employer view applications
allymayo Aug 13, 2025
7df67d6
Merge pull request #20 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
9fb9899
Admin can approve a co-op positions by setting the flag to false
suripeddis Aug 13, 2025
c947e47
sets the flagged to false
suripeddis Aug 13, 2025
a409065
Merge pull request #21 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
df09a4e
Allow admins to delete unapproved or invalid co-op postings that are …
suripeddis Aug 13, 2025
82f22e9
setting flagged to true will delete a posting
suripeddis Aug 13, 2025
464b0a7
Merge pull request #22 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
7fe0601
Admins can now create employer student and advisor profiles by sendin…
suripeddis Aug 13, 2025
c387787
student creates aplication
allymayo Aug 13, 2025
b6f6a62
Merge pull request #23 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
e00791c
Allow admins to delete a user by sending a DELETE request with a user…
suripeddis Aug 13, 2025
8f2bfc1
Merge pull request #24 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
20b2ab9
Admin views preference metrics of different postings
suripeddis Aug 13, 2025
b0e50d5
Merge pull request #25 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
e83cb46
admin has the ability to flag a position with issues now
suripeddis Aug 13, 2025
e8bb57f
admin can flag positions that have issues
suripeddis Aug 13, 2025
03c061e
Merge pull request #26 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
89e5f34
admin can remove the flag on the coop position if it was fixed or cha…
suripeddis Aug 13, 2025
3b16b2a
Merge pull request #27 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
2bed251
Connected api with student home page + fixed database & mock data
kanghosaeyo Aug 13, 2025
10ca501
Merge pull request #28 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
8dee103
For each company this tells us how many applications came from each g…
suripeddis Aug 13, 2025
b4f0046
Merge pull request #29 from kanghosaeyo/saumya
suripeddis Aug 13, 2025
ca400e7
Merge branch 'main' into Ally
allymayo Aug 13, 2025
a003398
Merge pull request #31 from kanghosaeyo/Ally
kanghosaeyo Aug 13, 2025
812178c
remove employer view route
allymayo Aug 13, 2025
4dde230
Merge pull request #32 from kanghosaeyo/Ally
allymayo Aug 13, 2025
00f86d8
typo
kanghosaeyo Aug 13, 2025
0943393
Merge pull request #33 from kanghosaeyo/oscar
kanghosaeyo Aug 13, 2025
607cab7
fix routes
allymayo Aug 14, 2025
4798387
Merge pull request #34 from kanghosaeyo/Ally
allymayo Aug 14, 2025
60d96f6
updated routes for persona 1
aga1936 Aug 14, 2025
1e05e58
trouble shooting issues with student profile
aga1936 Aug 14, 2025
65733cc
fixed issues with api and routes to connect to db
aga1936 Aug 14, 2025
3850524
api routing edits
engamy Aug 14, 2025
ef41b03
updated Student_Home to fix errors with skills section
aga1936 Aug 14, 2025
c132baa
adding company profile user story routes
engamy Aug 14, 2025
4fd803a
resolving merge conflicts
engamy Aug 14, 2025
b953bce
figuring out the missing blueprint imports
suripeddis Aug 14, 2025
266bb70
Merge pull request #35 from kanghosaeyo/saumya
suripeddis Aug 14, 2025
bc7868f
merge main with branch Amy
engamy Aug 14, 2025
c4c9e37
Connect Admin Home Streamlit page to API for pending co-op positions …
suripeddis Aug 14, 2025
667a115
Merge pull request #37 from kanghosaeyo/saumya
suripeddis Aug 14, 2025
15dd448
trying to merge :(
suripeddis Aug 14, 2025
ca9c099
attempting to merge
suripeddis Aug 14, 2025
5b1704b
redoing the admin home again
suripeddis Aug 14, 2025
5f096d7
Created the calendar for Student to view deadlines for coops that the…
aga1936 Aug 14, 2025
8cec21e
Merge branch 'ana_antic'
aga1936 Aug 14, 2025
b4169f9
show the first 5 pending positions
suripeddis Aug 14, 2025
e1b56d9
show the first 5 pending positions
suripeddis Aug 14, 2025
6d5af26
Merge pull request #38 from kanghosaeyo/saumya
suripeddis Aug 14, 2025
47ba929
Added route to pull all co-op positions
aga1936 Aug 14, 2025
08ef7a2
Merge branch 'ana_antic'
aga1936 Aug 14, 2025
2fc3033
move admin to app instead of backend
suripeddis Aug 14, 2025
02b3a17
merge conflicts
suripeddis Aug 14, 2025
88b3e1d
added advisor home page
kanghosaeyo Aug 14, 2025
854a62c
changed API_BASE
suripeddis Aug 14, 2025
e624e0a
Merge pull request #40 from kanghosaeyo/oscar
kanghosaeyo Aug 14, 2025
37ac13f
see the pending coop positions
suripeddis Aug 14, 2025
31d9b4c
format
allymayo Aug 14, 2025
cd82a8e
Merge branch 'saumya'
suripeddis Aug 14, 2025
822b6d7
employer homepage
allymayo Aug 14, 2025
de35ead
employer pages
allymayo Aug 14, 2025
3223760
postings page title
allymayo Aug 14, 2025
6367ce3
redoing admin_home because nothing is loading/working
suripeddis Aug 14, 2025
2fd1b3b
remerging to see if this works
suripeddis Aug 14, 2025
5d27ccb
employer home page
allymayo Aug 14, 2025
b1d6830
started from scratch for admin home
suripeddis Aug 14, 2025
e4c7e42
Merge pull request #41 from kanghosaeyo/Ally
allymayo Aug 14, 2025
b948fe9
Resolved merge conflict in Admin Home page
suripeddis Aug 14, 2025
c4ad21d
implemented flagging in advisor
kanghosaeyo Aug 14, 2025
5238983
deleted unnecessary advisor route
kanghosaeyo Aug 14, 2025
25ba97b
Added the admin employer information
suripeddis Aug 14, 2025
b446bdb
Merge main←saumya: keep saumya version of Admin_Home
suripeddis Aug 14, 2025
0749cc1
co-op position view for students, has 404 error for retrieving positions
aga1936 Aug 14, 2025
d25446d
attempt at displaying all coop positions
engamy Aug 14, 2025
12c7479
attempting to display coop positions
engamy Aug 14, 2025
417aa54
Admin can now see the pending posts still approve button still not wo…
suripeddis Aug 14, 2025
07066e8
Created Advisor Analytics page
kanghosaeyo Aug 14, 2025
b02eaf3
checking merge properly
suripeddis Aug 14, 2025
e39b2ec
advisor-company ratings page
engamy Aug 14, 2025
7052cb0
advisor companies
engamy Aug 14, 2025
c5bf6d1
reverted changes
kanghosaeyo Aug 14, 2025
aa18f22
advisor company rating info
engamy Aug 14, 2025
9db1dd3
fixed api routes for admin employers
kanghosaeyo Aug 14, 2025
c3402db
adding admin postings now
suripeddis Aug 14, 2025
3a2a1b8
advisor company ratings
engamy Aug 14, 2025
52b8ce7
removing old comments
engamy Aug 14, 2025
8d3e29c
recommitting the admin postings because its not showing in the main
suripeddis Aug 15, 2025
91357e2
a
suripeddis Aug 15, 2025
1547cd4
Merge branch 'main' into saumya
suripeddis Aug 15, 2025
e30aa2e
Merge pull request #51 from kanghosaeyo/saumya
kanghosaeyo Aug 15, 2025
a05d0ae
fixed routing
kanghosaeyo Aug 15, 2025
c91f2fd
Merge pull request #52 from kanghosaeyo/oscar
kanghosaeyo Aug 15, 2025
9b4069b
fixed routes AGAIN
kanghosaeyo Aug 15, 2025
bb839cb
Merge pull request #53 from kanghosaeyo/oscar
kanghosaeyo Aug 15, 2025
03dad5a
Merge branch 'Amy'
engamy Aug 15, 2025
9a769d0
reset to working version for everyone, added in browse positions again
aga1936 Aug 15, 2025
8ddcda4
deleted prefixes and fixed api routes in student home and advisor home
kanghosaeyo Aug 15, 2025
f2292ba
Merge pull request #54 from kanghosaeyo/oscar
kanghosaeyo Aug 15, 2025
c5b9d5a
Merge branch 'ana_antic'
aga1936 Aug 15, 2025
71d582f
updated student browser positions again...
aga1936 Aug 15, 2025
85e1d37
added remove preference button on browse coop postings
aga1936 Aug 15, 2025
23c792a
more detail to coop postings for students
aga1936 Aug 15, 2025
5858f36
updated the student calendar
aga1936 Aug 15, 2025
044a530
updated calendar
aga1936 Aug 15, 2025
8510be8
added applications, fixed db issue
aga1936 Aug 15, 2025
3110853
finished setting up application submissions
aga1936 Aug 15, 2025
6fdbbb2
fixed application status
aga1936 Aug 15, 2025
c8053e9
cleaned up comments in code for students
aga1936 Aug 15, 2025
5e14fa4
deleted folders/files from class example
aga1936 Aug 15, 2025
55b3168
deleted duplicate of workedatpos inserts
aga1936 Aug 15, 2025
1334b2a
updated comments
aga1936 Aug 15, 2025
3946869
deleted conflict markers
aga1936 Aug 15, 2025
8d3b6ab
deleted duplicate in inserts again...
aga1936 Aug 15, 2025
1bfa421
needed to fix inserts again
aga1936 Aug 15, 2025
4a81d4c
updated to have 125 skilldetails table entry
aga1936 Aug 15, 2025
871716c
added more employers
aga1936 Aug 15, 2025
528ef1f
added more co-op positions in sample data
aga1936 Aug 15, 2025
51df6b4
added more to createspos table
aga1936 Aug 15, 2025
74ee489
added more applications and appleistopos data
aga1936 Aug 15, 2025
2b5d124
added more students and advisors to make more advisor advisee data
aga1936 Aug 15, 2025
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
File renamed without changes.
4 changes: 2 additions & 2 deletions api/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ SECRET_KEY=someCrazyS3cR3T!Key.!
DB_USER=root
DB_HOST=db
DB_PORT=3306
DB_NAME=northwind
MYSQL_ROOT_PASSWORD=<put a good password here>
DB_NAME=coopalytics
MYSQL_ROOT_PASSWORD=" "
56 changes: 56 additions & 0 deletions api/backend/advisoradvisee/advisoradvisee_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from flask import Blueprint
from flask import request
from flask import jsonify
from flask import make_response
from flask import current_app
from backend.db_connection import db

advisoradvisee = Blueprint('advisoradvisee', __name__)

# Advisor identifies students with too few applications
@advisoradvisee.route('/advisor/<advisorID>/students/low-applications', methods=['GET'])
def get_students_with_low_applications(advisorID):
current_app.logger.info('GET /advisor/<advisorID>/students/low-applications route')

query = '''
SELECT u.userId,
u.firstName,
u.lastName,
COUNT(apps.applicationId) AS totalApps
FROM advisor_advisee aa
JOIN users u ON u.userId = aa.studentId
LEFT JOIN appliesToApp ata ON ata.studentId = u.userId
LEFT JOIN applications apps ON ata.applicationId = apps.applicationId
WHERE aa.advisorId = {0}
GROUP BY u.userId, u.firstName, u.lastName
HAVING COUNT(apps.applicationId) < 5
ORDER BY totalApps ASC, u.lastName;
'''.format(advisorID)

cursor = db.get_db().cursor()
cursor.execute(query)
theData = cursor.fetchall()

the_response = make_response(jsonify(theData))
the_response.status_code = 200
return the_response

# Admin reassigns students to different advisors as needed
@advisoradvisee.route('/admin/<studentId>/<advisorId>',
methods = ['PUT'])
def reassignAdvisor():
current_app.logger.info('PUT /admin/<studentId>/<advisorId> route')
advisorId = request.json
studentId = request.json

query = '''
UPDATE advisor_advisee
SET advisorId = %s
WHERE studentId = %s;
'''
data=(advisorId, studentId)
cursor = db.get_db().cursor()
r = cursor.execute(query, data)
db.get_db().commit()
return 'advisor reassigned successfully'

165 changes: 165 additions & 0 deletions api/backend/applications/applications_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
from flask import Blueprint
from flask import request
from flask import jsonify
from flask import make_response
from flask import current_app
from backend.db_connection import db
import pymysql

# New Blueprint for applications
applications = Blueprint('applications', __name__)


# Student viewing their own application statuses
@applications.route('/student/<studentID>/applications', methods=['GET'])
def get_student_applications(studentID):
current_app.logger.info(f'GET /student/{studentID}/applications route')

query = '''
SELECT u.userId,
u.firstName,
u.lastName,
a.applicationId,
a.status AS applicationStatus,
a.resume,
a.coverLetter,
a.gpa,
cp.title AS positionTitle,
cp.deadline AS applicationDeadline,
a.dateTimeApplied,
cp.description AS positionDescription
FROM users u
JOIN appliesToApp ata ON u.userId = ata.studentId
JOIN applications a ON ata.applicationId = a.applicationId
JOIN coopPositions cp ON a.coopPositionId = cp.coopPositionId
WHERE u.userId = %s
ORDER BY a.dateTimeApplied DESC, cp.deadline ASC
'''

connection = db.get_db()

cursor = connection.cursor(pymysql.cursors.DictCursor)
cursor.execute(query, (studentID,))
theData = cursor.fetchall()

return make_response(jsonify(theData), 200)

# student sees how many positions they have applied to
@applications.route('/student/<studentID>/applications/summary', methods=['GET'])
def get_numb_apps(studentID):
current_app.logger.info('GET /student/<studentID>/applications route')

query = '''
SELECT a.status,
COUNT(*) AS ApplicationCount
FROM applications a
JOIN appliesToApp ata ON a.applicationId = ata.applicationId
WHERE ata.studentId = %s
GROUP BY a.status

'''

cursor = db.get_db().cursor()
cursor.execute(query, (studentID,))
theData = cursor.fetchall()

the_response = make_response(jsonify(theData))
the_response.status_code = 200
return the_response



# Advisor viewing all their advisees' application statuses
@applications.route('/advisor/<advisorID>/students/applications', methods=['GET'])
def get_advisor_student_applications(advisorID):
current_app.logger.info('GET /advisor/<advisorID>/students/applications route')

query = '''
SELECT aa.advisorId,
u.userId,
u.firstName,
u.lastName,
a.applicationId,
a.status AS applicationStatus,
cp.title AS positionTitle,
cp.deadline AS applicationDeadline,
com.name AS companyName,
a.dateApplied
FROM advisor_advisee aa
JOIN users u ON aa.studentId = u.userId
JOIN appliesToApp ata ON u.userId = ata.studentId
JOIN applications a ON ata.applicationId = a.applicationId
JOIN coopPositions cp ON a.coopPositionId = cp.coopPositionId
JOIN companyProfiles com ON cp.companyProfileId = com.companyProfileId
LEFT JOIN workedAtPos wp ON u.userId = wp.studentId AND wp.coopPositionId = cp.coopPositionId
WHERE aa.advisorId = {0}
ORDER BY u.lastName, u.firstName, a.dateApplied DESC
'''.format(advisorID)

cursor = db.get_db().cursor()
cursor.execute(query)
theData = cursor.fetchall()

the_response = make_response(jsonify(theData))
the_response.status_code = 200
return the_response

# Employer views all applications of a posting
@applications.route('/applications/<int:coopPositionId>', methods=['GET'])
def get_applications(coopPositionId):
current_app.logger.info('GET /applications/%s', coopPositionId)

query = '''
SELECT a.dateTimeApplied, a.status, a.resume, a.gpa, a.coverLetter,
a.coopPositionId, a.applicationId
FROM applications a
JOIN coopPositions cp ON a.coopPositionId = cp.coopPositionId
WHERE a.coopPositionId = %s
ORDER BY a.dateTimeApplied DESC;
'''
cursor = db.get_db().cursor(dictionary=True)
cursor.execute(query, (coopPositionId,))
theData = cursor.fetchall()

return make_response(jsonify(theData), 200)

# Student applies to a position
@applications.route('/applications/new', methods=['POST'])
def create_application():
current_app.logger.info('POST /applications/new')

data = request.json
required_fields = ['coopPositionId', 'studentId']

if not all(field in data for field in required_fields):
current_app.logger.warning('POST /applications/new missing required fields')
return make_response(jsonify({"error": "coopPositionId and studentId are required"}), 400)

try:
cursor = db.get_db().cursor()

# Insert application
cursor.execute('''
INSERT INTO applications (resume, gpa, coverLetter, coopPositionId)
VALUES (%s, %s, %s, %s)
''', (
data.get('resume', ''),
data.get('gpa'),
data.get('coverLetter', ''),
data['coopPositionId']
))

application_id = cursor.lastrowid

# Link student to application
cursor.execute('''
INSERT INTO appliesToApp (applicationId, studentId)
VALUES (%s, %s)
''', (application_id, data['studentId']))

db.get_db().commit()
return jsonify({"message": "Application submitted", "applicationId": application_id}), 201

except Exception as e:
current_app.logger.error(f"❌ Error creating application: {e}")
return jsonify({"error": str(e)}), 500 # Temporarily return full error for debugging
134 changes: 134 additions & 0 deletions api/backend/companyProfiles/companyProfiles_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from flask import Blueprint
from flask import request
from flask import jsonify
from flask import make_response
from flask import current_app
from backend.db_connection import db

companyProfiles = Blueprint('companyProfiles', __name__)

# Student/Advisor views a company profile
@companyProfiles.route('/companyProfiles/<companyProfileId>', methods=['GET'])
def get_company_profile(companyProfileId):
query = '''
SELECT *
FROM companyProfiles
WHERE companyProfileId = %s
'''.format(companyProfileId)

cursor = db.get_db().cursor()
cursor.execute(query)
columns = [col[0] for col in cursor.description]
theData = [dict(zip(columns, row)) for row in cursor.fetchall()]

the_response = make_response(jsonify(theData))
the_response.status_code = 200
return the_response

# Advisor views all company profiles
@companyProfiles.route('/companyProfiles', methods=['GET'])
def get_all_company_profiles():
query = '''
SELECT companyProfileId, name, bio, industry, websiteLink
FROM companyProfiles
ORDER BY name
'''

cursor = db.get_db().cursor()
cursor.execute(query)
columns = [col[0] for col in cursor.description]
theData = [dict(zip(columns, row)) for row in cursor.fetchall()]

the_response = make_response(jsonify(theData))
the_response.status_code = 200
return the_response

# Advisor views all company profiles sorted by their rating
@companyProfiles.route('/companyProfiles/rating', methods=['GET'])
def get_company_profiles_by_rating():
query = '''
SELECT com.name AS companyName,
com.industry AS companyIndustry,
com.websiteLink AS companyWebsite,
AVG(wp.companyRating) AS avgCompanyRating,
COUNT(wp.companyRating) AS ratingCount
FROM workedAtPos wp
JOIN coopPositions cp ON wp.coopPositionId = cp.coopPositionId
JOIN createsPos cr ON cp.coopPositionId = cr.coopPositionId
JOIN users u ON cr.employerId = u.userId
JOIN companyProfiles com ON u.companyProfileId = com.companyProfileId
WHERE wp.companyRating IS NOT NULL
GROUP BY com.name, com.industry, com.websiteLink
HAVING COUNT(wp.companyRating) > 0
ORDER BY avgCompanyRating DESC;
'''

# SELECT com.name AS companyName,
# AVG(wp.companyRating) AS avgCompanyRating
# FROM workedAtPos wp
# JOIN coopPositions cp ON wp.coopPositionId = cp.coopPositionId
# JOIN createsPos cr ON cp.coopPositionId = cr.coopPositionId
# JOIN users u ON cr.employerId = u.userId
# JOIN companyProfiles com ON u.companyProfileId = com.companyProfileId
# GROUP BY com.name
# ORDER BY avgCompanyRating DESC;

cursor = db.get_db().cursor()
cursor.execute(query)
columns = [col[0] for col in cursor.description]
theData = [dict(zip(columns, row)) for row in cursor.fetchall()]
the_response = make_response(jsonify(theData))
the_response.status_code = 200
return the_response

# Employer creates a company profile
@companyProfiles.route('/companyProfiles/create/<companyProfileId>', methods=['POST'])
def createCompanyProfile(companyProfileId):

the_data = request.json
current_app.logger.info(the_data)

name = the_data['company_name']
bio = the_data['company_bio']
industry = the_data['company_industry']
websiteLink = the_data['website_link']

query = f'''
INSERT INTO companyProfiles (name, bio, industry, websiteLink)
VALUE( '{name}', '{bio}', '{industry}', '{websiteLink}')
'''

current_app.logger.info(query)
cursor = db.get_db().cursor()
cursor.execute(query)
db.get_db().commit()

response = make_response("Created company profile")
response.status_code = 200
return response

# Employer updates/edits company information
@companyProfiles.route('/companyProfiles/update/<companyProfileId>', methods=['PUT'])
def updateCompanyProfile(companyProfileId):
current_app.logger.info('PUT /companyProfiles/update/<companyProfileId> route')

company_info = request.json
companyId = company_info['id']
companyName = company_info['name']
companyBio = company_info['bio']
companyIndustry = company_info['industry']
companyWebsite = company_info['website_link']

query = '''
UPDATE companyProfiles
SET name = %s,
bio = %s,
industry = %s,
websiteLink = %s
WHERE companyProfileId = %s
'''
data = (companyName, companyBio, companyIndustry, companyWebsite, companyId)
cursor = db.get_db().cursor()
r = cursor.execute(query, data)
db.get_db().commit()
return 'Updated company profile!'
Loading