-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterview.py
50 lines (40 loc) · 2 KB
/
interview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Contains functionalities to track interview questions
"""
from datetime import datetime
from utils import db
from tables import Application, InterviewQuestion
integer_id_error = {"status": "The application ID must be an integer."}
invalid_id_error = {"status": "You need to provide a valid application ID! No application found for your ID."}
missing_question_error = {"status": "You need to provide a question!"}
missing_question_id_error = {"status": "You need to provide a question ID!"}
question_not_found_error = {"status": "No question found"}
def add_interview_question(application_id, question, title, user_id):
if type(application_id) != int:
return integer_id_error
application = Application.query.filter_by(id=application_id, user_id=user_id).first()
if not application_id or not application:
return invalid_id_error
if not question or type(question) != str:
return missing_question_error
question = InterviewQuestion(application_id=application_id, question=question, title=title)
db.session.add(question)
db.session.commit()
questions = InterviewQuestion.query.filter_by(application_id=application_id).all()
return [question.to_dict() for question in questions]
def get_interview_questions(application_id, user_id):
if type(application_id) != int:
return integer_id_error
application = Application.query.filter_by(id=application_id, user_id=user_id).first()
if not application_id or not application:
return invalid_id_error
questions = InterviewQuestion.query.filter_by(application_id=application_id).all()
return [question.to_dict() for question in questions]
def update_interview_question(question_id, new_question):
if not question_id:
return missing_question_id_error
interview_question = InterviewQuestion.query.filter_by(id=question_id).first()
if not interview_question:
return question_not_found_error
interview_question.question = new_question
return interview_question.to_dict()