def get(self): queryAppointments = Appointment.query.filter_by( status=Status['Pending']).all() if not queryAppointments: return res.getSuccess("No appointments found.") appointments = appointments_schema.dump(queryAppointments).data if not appointments: return res.internalServiceError( "Failed to create appointment schema.") return res.getSuccess(data=appointments)
def get(self, login): # Validate User exists user, error = User.queryByLogin(login) if error: return res.resourceMissing(error) # Retrieving user projects records = Mentor.query.filter_by(id_user42=user['id_user42']).all() if not records: res.resourceMissing("No projects found for user {}".format(login)) # Retrieving online users onlineUsers = Api42.onlineUsers() returnList = [] for rec in records: data = mentor_schema.dump(rec).data # Retrieve registered mentors for project in 'rec' query = Mentor.query.filter_by(id_project42=data['id_project42'], active=True).all() # Ensure each mentor doesn't have a pending appointment goodMentors = [] for q in query: appointment = Appointment.query.filter(Appointment.id_mentor==q.id, Appointment.status==Status['Pending']).first() if not appointment: goodMentors.append(q) queryData = mentors_schema.dump(goodMentors).data # Matching only online users and excluding self (user with login = login) tmpList = [q for q in queryData for o in onlineUsers if q['id_user42'] == o['id'] and o['login'] != login] data['project'] = {'name': rec.project.name, 'id': rec.project.id, 'onlineMentors': len(tmpList)} returnList.append(data) return res.getSuccess(data=returnList)
def get(self): queryUsers, error = User.queryByAll() if error: return res.internalServiceError(error) onlineStudents = Api42.onlineUsers() onlineSenseiUsers = [u for u in queryUsers for o in onlineStudents if u['id_user42'] == o['id']] return res.getSuccess(data=onlineSenseiUsers)
def get(self, projectId): # Validating project exists queryProject = Project.query.filter_by(id_project42=projectId).first() if not queryProject: return res.resourceMissing("Project {} not found.".format(projectId)) standingsList = [] # * Querying by order DESCENDING to retrieve top mentors for the specified project in each category * # Top 5 ordering by rating topByRating = MentorStat.query \ .join(Mentor) \ .filter(Mentor.id_project42==projectId, Mentor.abletomentor==True) \ .order_by(MentorStat.rating.desc(), MentorStat.totalappointments.desc()) \ .limit(5) standingsList.append(str('topByRating')) standingsList.append(topByRating) # Top 5 ordering by totalappointments topByAppointments = MentorStat.query \ .join(Mentor) \ .filter(Mentor.id_project42==projectId, Mentor.abletomentor==True) \ .order_by(MentorStat.totalappointments.desc()) \ .limit(5) standingsList.append(str('topByAppointments')) standingsList.append(topByAppointments) # Top 5 ordering by cancelled appointments topByCancelledAppointments = MentorStat.query \ .join(Mentor) \ .filter(Mentor.id_project42==projectId, Mentor.abletomentor==True) \ .order_by(MentorStat.cancelledappointments.desc()) \ .limit(5) standingsList.append(str('topByCancelledAppointments')) standingsList.append(topByCancelledAppointments) standings = {} for st in standingsList: if type(st) is str: name = st else: objList = [] for m in st: mentor = mentor_schema.dump(getattr(m, 'mentor')).data user = user_schema.dump(getattr(getattr(m, 'mentor'), 'user')).data stats = mentorstatschema.dump(m).data obj = { 'mentor': mentor, 'user': user, 'stats': stats } objList.append(obj) standings[name] = objList return res.getSuccess('Top 5 standings for project {}'.format(queryProject.name), standings)
def get(self, projectId): # get mentors that exist for that project query = Mentor.query \ .filter_by(id_project42=projectId, active=True) \ .all() if not query: return res.badRequestError( 'No Projects with id {} exist'.format(projectId)) mentors = mentors_schema.dump(query).data return res.getSuccess( 'mentors available for project {}'.format(projectId), result)
def get(self, mentorId): query = Mentor.query.filter_by(id=mentorId).first() if not query: return res.badRequestError( 'no mentor record with id {} exists'.format(mentorId)) data = mentor_schema.dump(query).data if not data: return res.internalServiceError('failed to build mentor data') return res.getSuccess( 'mentor data retrieved for user {} on project {}'.format( query.user.login, query.project.name), data)
def get(self, login): user, error = User.queryByLogin(login) if error: return res.resourceMissing(error) # get the mentor records for that user on which projects they can mentor query = Mentor.query.filter_by(id_user42=user['id_user42'], active=True) if not query: return res.internalServiceError( 'no mentor records for user {}'.format(login)) # return the mentor data mentors = mentors_schema.dump(query).data return res.getSuccess(data=mentors)
def get(self, id_user42): queryUser = User.query.filter_by(id_user42=id_user42).first() if not queryUser: return res.resourceMissing('User {} not found.'.format(id_user42)) userStats = {} userStats['globalStats'] = user_schema.dump(queryUser).data mentorStats = [] mentors = getattr(queryUser, 'mentor') for m in mentors: mentorObj = {} mentorObj['mentorstat'] = mentorstatschema.dump(getattr(m, 'mentorstat')).data mentorObj['project'] = project_schema.dump(getattr(m, 'project')).data mentorStats.append(mentorObj) userStats['mentorStats'] = mentorStats return res.getSuccess("Stats for user {}".format(queryUser.login), userStats)
def get(self, userId): # Appointments Table query for the specified user as mentee queryAppointments = Appointment.query \ .join(User) \ .filter(Appointment.status==Status['Pending']) \ .filter(User.id_user42==userId) \ .all() if not queryAppointments: return res.resourceMissing("No appointments found") pendingAppointments = [] for a in queryAppointments: obj = { 'appointment': appointment_schema.dump(a).data, 'mentor': user_schema.dump(getattr(getattr(a, 'mentor'), 'user')).data, 'project': project_schema.dump(getattr(getattr(a, 'mentor'), 'project')).data } pendingAppointments.append(obj) return res.getSuccess("Appointmensts for user", pendingAppointments)
def get(self): data, error = Project.queryAll() if error: return res.internalServiceError(error) return res.getSuccess('found projects', data)
def get(self, appointmentId): appointment, err = Appointment.queryById(appointmentId) if err: return res.badRequestError(err) return res.getSuccess(appointment)
def get(self, currentuser): query = User.query.all() data = users_schema.dump(query).data return res.getSuccess('all users', data)
def get(self, login): user, err = User.queryByLogin(login) if err: return res.resourceMissing(err) return res.getSuccess('user exists in database', user)
def get(self): query = Mentor.query.all() if not query: return res.badRequestError("No mentors") data = mentors_schema.dump(query).data return res.getSuccess('all mentors', data)