Skip to content

Commit 707584d

Browse files
committed
added mentor_mentee_map function to crud.py
1 parent e0976b2 commit 707584d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

app/db/crud.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
SCOPE = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
1313
CREDS_FILE = "credentials.json"
1414

15+
def mentor_mentee_map(db:Session):
16+
mentors=(
17+
db.query(models.User).filter(models.User.role == "mentor").all()
18+
)
19+
mentees=(
20+
db.query(models.User).filter(models.User.role == "mentee").all()
21+
)
22+
23+
for mentor in mentors:
24+
for mentee in mentees:
25+
if not db.query(models.MentorMenteeMap).filter_by(mentor_id=mentor.id, mentee_id=mentee.id).first():
26+
map_entry = models.MentorMenteeMap(mentor_id=mentor.id, mentee_id=mentee.id)
27+
db.add(map_entry)
28+
db.commit()
29+
db.refresh(map_entry)
30+
return "Mentor Mentee Mapping completed successfully"
31+
1532
def get_user_by_email(db: Session, email: str):
1633
return db.query(models.User).filter(models.User.email == email).first()
1734

0 commit comments

Comments
 (0)