def GetUser(current_user, user_type, username): if not username: return ResponseHelper.ReturnBadRequestResponse() user_dao = UserDao() if username == current_user: user = user_dao.GetUserById(current_user) if user: return ResponseHelper.ReturnOkDataResponse("User Found", { "User": DAOHelper.RemoveValueFromObject(UsersTable.PASSWORD, user) }) else: return ResponseHelper.ReturnNotFoundResponse("User Not Found!") else: user = user_dao.GetUserById(username) if user: return ResponseHelper.ReturnOkDataResponse("Request OK", { "User": DAOHelper.RemoveValueFromObject(UsersTable.PASSWORD, user) }) else: return ResponseHelper.ReturnNotFoundResponse("User Not Found!")
def GetAttendingEvents(current_user, user_type): event_dao = EventDao() events = event_dao.GetParticipatingEvents(current_user) if events: return ResponseHelper.ReturnOkDataResponse("Request OK", {"Events": events}) else: return ResponseHelper.ReturnNotFoundResponse("No Events Found!")
def GetUsers(current_user, user_type, search_type, search_value): if not search_type and search_value: return ResponseHelper.ReturnBadRequestResponse() user_dao = UserDao() users = user_dao.GetUsers(search_type, search_value) if users: return ResponseHelper.ReturnOkDataResponse("Request OK", {"Users": users}) else: return ResponseHelper.ReturnNotFoundResponse("Users Not Found!")
def GetAthletes(current_user, user_type): if user_type != RequestConstants.USER_TYPE_COA: return ResponseHelper.ReturnBadRequestResponse() user_dao = UserDao() users = user_dao.GetCoachAthletes(current_user) if users: return ResponseHelper.ReturnOkDataResponse("Request OK", {"Users": users}) else: return ResponseHelper.ReturnNotFoundResponse("Users Not Found!")
def GetEvent(current_user, user_type, event_id): if not event_id: return ResponseHelper.ReturnBadRequestResponse() event_dao = EventDao() event = event_dao.GetEvent(event_id) if event: return ResponseHelper.ReturnOkDataResponse("Request OK", {"Event": event}) else: return ResponseHelper.ReturnNotFoundResponse("No Event Found!")
def GetTemplates(current_user, user_type, user_id): if current_user != user_id: return ResponseHelper.ReturnBadRequestResponse() if user_type != RequestConstants.USER_TYPE_COA: return ResponseHelper.ReturnBadRequestResponse() training_log_template_dao = TrainingLogTemplateDao() templates = training_log_template_dao.GetTemplates(user_id) if templates: return ResponseHelper.ReturnOkDataResponse("Request OK", {"Templates": templates}) else: return ResponseHelper.ReturnNotFoundResponse("No Templates Found!")
def GetTargets(current_user, user_type, user_id, week_num, year_num): if current_user != user_id: access_dao = AccessDao() if not access_dao.CheckCoachTargetsAccess(current_user, user_id): return ResponseHelper.ReturnBadRequestResponse() if not week_num: return ResponseHelper.ReturnBadRequestResponse() target_dao = TargetDao() targets = target_dao.GetTargetsByWeek(user_id, week_num, year_num) if targets: return ResponseHelper.ReturnOkDataResponse("Request OK", {"Targets": targets}) else: return ResponseHelper.ReturnNotFoundResponse("No Targets Found!")
def GetWorkoutById(current_user, user_type, user_id, training_log_id): if current_user != user_id: access_dao = AccessDao() if not access_dao.CheckCoachTrainingLogAccess(current_user, user_id): return ResponseHelper.ReturnBadRequestResponse() if not training_log_id: return ResponseHelper.ReturnBadRequestResponse() training_log_dao = TrainingLogDao() training_log = training_log_dao.GetWorkoutById(training_log_id, user_id) if training_log: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"TrainingLog": training_log} ) else: return ResponseHelper.ReturnNotFoundResponse("Training Log Not Found!")
def GetInvites(current_user, user_type, invite_status_type): invite_type = request.args.get('type') invite_types = ["one-one", "vid-con", "coa-dat", "ath-dat"] if not invite_status_type: return ResponseHelper.ReturnBadRequestResponse() if not invite_type or invite_type not in invite_types: if invite_status_type == "sent" or invite_status_type == "received": invite_dao = InviteDao() invites = invite_dao.GetInvites(current_user, invite_status_type) if invites: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"Invites": invites}) else: return ResponseHelper.ReturnNotFoundResponse( "No Invites Found!") elif invite_status_type == "new": invite_dao = InviteDao() count = invite_dao.GetNewInvitesCount(current_user) if count: return ResponseHelper.ReturnOkDataResponse("Request OK", count) else: return ResponseHelper.ReturnOkDataResponse("Request OK", 0) else: return ResponseHelper.ReturnBadRequestResponse() else: if invite_status_type == "sent" or invite_status_type == "received": if invite_type == "ath-dat" and user_type != RequestConstants.USER_TYPE_ATH: return ResponseHelper.ReturnBadRequestResponse() if invite_type == "coa-dat" and user_type != RequestConstants.USER_TYPE_COA: return ResponseHelper.ReturnBadRequestResponse() invite_dao = InviteDao() invites = invite_dao.GetInvites( current_user, invite_status_type, (invite_types.index(invite_type) + 1)) if invites: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"Invites": invites}) else: return ResponseHelper.ReturnNotFoundResponse( "No Invites Found!") else: return ResponseHelper.ReturnBadRequestResponse()
def GetWorkouts(current_user, user_type, user_id): if current_user != user_id: access_dao = AccessDao() if not access_dao.CheckCoachTrainingLogAccess(current_user, user_id): return ResponseHelper.ReturnBadRequestResponse() day = request.args.get('day') week = request.args.get('week') month = request.args.get('month') year = request.args.get('year') log_type = request.args.get('type') if not day and not week and not month and not year: return ResponseHelper.ReturnBadRequestResponse() else: # Workouts by day if day and month and year: training_log_dao = TrainingLogDao() training_logs = training_log_dao.GetWorkoutsByDay(day, month, year, user_id) if training_logs: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"TrainingLogs": training_logs} ) else: return ResponseHelper.ReturnNotFoundResponse("No Logs Found!") # Workouts by week elif week and year and not log_type: training_log_dao = TrainingLogDao() training_logs = training_log_dao.GetWorkoutsByWeek(week, year, user_id, log_type=None) if training_logs: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"TrainingLogs": training_logs} ) else: return ResponseHelper.ReturnNotFoundResponse("No Logs Found!") # Workouts by week elif week and year and log_type: training_log_dao = TrainingLogDao() training_logs = training_log_dao.GetWorkoutsByWeek(week, year, user_id, log_type) if training_logs: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"TrainingLogs": training_logs} ) else: return ResponseHelper.ReturnNotFoundResponse("No Logs Found!") # Workouts by month elif month and year: month_end = calendar.monthrange(int(year), int(month))[1] training_log_dao = TrainingLogDao() training_logs = training_log_dao.GetWorkoutsByMonth(month, month_end, year, user_id) if training_logs: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"TrainingLogs": training_logs} ) else: return ResponseHelper.ReturnNotFoundResponse("No Logs Found!") # Bad request if no combinations are matched else: return ResponseHelper.ReturnBadRequestResponse()