Beispiel #1
0
    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)
Beispiel #2
0
 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)
Beispiel #3
0
	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)
Beispiel #4
0
def get_current_user(user_id: int):
    user = User.query.get_or_404(
        int(user_id), description=f"User with id {user_id} not found"
    )

    return jsonify({"success": True, "data": user_schema.dump(user)})