def CreateTarget(current_user, user_type, user_id): if current_user != user_id: access_dao = AccessDao() if not access_dao.CheckCoachTargetsAccess(current_user, user_id): return ResponseHelper.ReturnBadRequestResponse() if not request.data: return ResponseHelper.ReturnBadRequestResponse() else: request_data = json.loads(request.data) target = Target( None, # For Id that is auto generated by a trigger user_id, # Ensure log is created for the current user, request_data[str(TargetsTable.CONTENT)], request_data[str(TargetsTable.STATUS)], request_data[str(TargetsTable.WEEK)], request_data[str(TargetsTable.YEAR)]) target_dao = TargetDao() if target_dao.CreateTarget(target): return ResponseHelper.ReturnCreatedResponse("Target Created") else: return ResponseHelper.ReturnConflictResponse( "Unable to Create Target!")
def CreateMultipleInvites(current_user, user_type): if not request.data: return ResponseHelper.ReturnBadRequestResponse() else: request_data = json.loads(request.data) invite = Invite( None, # For Id that is auto generated by a trigger request_data[str(InvitesTable.INVITE_TYPE)], current_user, # Ensure log is created for the current user, None, request_data[str(InvitesTable.STATUS)], request_data[str(InvitesTable.SEND_DATE)], request_data[str(InvitesTable.EVENT_ID)]) recipients = request_data["Recipients"] invite_dao = InviteDao() if invite_dao.CreateMultipleInvites(invite, recipients): return ResponseHelper.ReturnCreatedResponse("Invites Created") else: return ResponseHelper.ReturnConflictResponse( "Unable to Create Invites!")
def CreateTemplate(current_user, user_type, user_id): if current_user != user_id: return ResponseHelper.ReturnBadRequestResponse() if user_type != RequestConstants.USER_TYPE_COA: return ResponseHelper.ReturnBadRequestResponse() if not request.data: return ResponseHelper.ReturnBadRequestResponse() else: training_log_data = json.loads(request.data) template = TrainingLogTemplate( None, # For Id that is auto generated by a trigger user_id, # Ensure log is created for the current user, training_log_data[str(TrainingLogTemplateTable.NAME)], training_log_data[str(TrainingLogTemplateTable.DURATION_PLANNED)], training_log_data[str(TrainingLogTemplateTable.DURATION_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.DISTANCE_PLANNED)], training_log_data[str(TrainingLogTemplateTable.DISTANCE_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.DISTANCE_UNIT)], training_log_data[str( TrainingLogTemplateTable.HR_RESTING_PLANNED)], training_log_data[str(TrainingLogTemplateTable.HR_AVG_PLANNED)], training_log_data[str(TrainingLogTemplateTable.HR_MAX_PLANNED)], training_log_data[str(TrainingLogTemplateTable.HR_RESTING_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.HR_AVG_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.HR_MAX_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.WATTS_AVG_PLANNED)], training_log_data[str(TrainingLogTemplateTable.WATTS_MAX_PLANNED)], training_log_data[str(TrainingLogTemplateTable.WATTS_AVG_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.WATTS_MAX_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.RPE_PLANNED)], training_log_data[str(TrainingLogTemplateTable.RPE_ACTUAL)], training_log_data[str(TrainingLogTemplateTable.HR_ZONE1_TIME)], training_log_data[str(TrainingLogTemplateTable.HR_ZONE2_TIME)], training_log_data[str(TrainingLogTemplateTable.HR_ZONE3_TIME)], training_log_data[str(TrainingLogTemplateTable.HR_ZONE4_TIME)], training_log_data[str(TrainingLogTemplateTable.HR_ZONE5_TIME)], training_log_data[str(TrainingLogTemplateTable.HR_ZONE6_TIME)]) training_log_template_dao = TrainingLogTemplateDao() if training_log_template_dao.CreateTrainingLogTemplate(template): return ResponseHelper.ReturnCreatedResponse("Template Created") else: return ResponseHelper.ReturnConflictResponse( "Unable to Create Template!")
def CreateUser(): if not request.data: return ResponseHelper.ReturnBadRequestResponse() else: user_data = json.loads(request.data) password = PasswordHashingHelper.GetEncryptedHash(user_data[str( UsersTable.PASSWORD)]) user = User(user_data[str(UsersTable.ID)], password, user_data[str( UsersTable.F_NAME)], user_data[str(UsersTable.L_NAME)], user_data[str(UsersTable.E_MAIL)], user_data[str(UsersTable.DOB)], user_data[str(UsersTable.TYPE)], user_data[str(UsersTable.LOCATION)], user_data[str(UsersTable.BIO)]) user_dao = UserDao() if user_dao.GetUserById(user.Id): return ResponseHelper.ReturnConflictResponse( "User Already Exists!") else: user_dao = UserDao() if user_dao.CreateUser(user): return ResponseHelper.ReturnCreatedResponse("User Created") else: return ResponseHelper.ReturnCreatedResponse( "Unable to Create User!")
def CreateTrainingLog(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() if not request.data: return ResponseHelper.ReturnBadRequestResponse() else: training_log_data = json.loads(request.data) training_log = TrainingLog( None, # For Id that is auto generated by a trigger user_id, # Ensure log is created for the current user, training_log_data[str(TrainingLogTable.TYPE_ID)], training_log_data[str(TrainingLogTable.LOG_DATE)], training_log_data[str(TrainingLogTable.LOG_TIME)], training_log_data[str(TrainingLogTable.LOG_NAME)], training_log_data[str(TrainingLogTable.LOG_DESC)], training_log_data[str(TrainingLogTable.ATHLETES_COMMENTS)], training_log_data[str(TrainingLogTable.COACHES_COMMENTS)], training_log_data[str(TrainingLogTable.WORKOUT_COMMENTS)], training_log_data[str(TrainingLogTable.DURATION_PLANNED)], training_log_data[str(TrainingLogTable.DURATION_ACTUAL)], training_log_data[str(TrainingLogTable.DISTANCE_PLANNED)], training_log_data[str(TrainingLogTable.DISTANCE_ACTUAL)], training_log_data[str(TrainingLogTable.DISTANCE_UNIT)], training_log_data[str(TrainingLogTable.HR_RESTING_PLANNED)], training_log_data[str(TrainingLogTable.HR_AVG_PLANNED)], training_log_data[str(TrainingLogTable.HR_MAX_PLANNED)], training_log_data[str(TrainingLogTable.HR_RESTING_ACTUAL)], training_log_data[str(TrainingLogTable.HR_AVG_ACTUAL)], training_log_data[str(TrainingLogTable.HR_MAX_ACTUAL)], training_log_data[str(TrainingLogTable.WATTS_AVG_PLANNED)], training_log_data[str(TrainingLogTable.WATTS_MAX_PLANNED)], training_log_data[str(TrainingLogTable.WATTS_AVG_ACTUAL)], training_log_data[str(TrainingLogTable.WATTS_MAX_ACTUAL)], training_log_data[str(TrainingLogTable.RPE_PLANNED)], training_log_data[str(TrainingLogTable.RPE_ACTUAL)], training_log_data[str(TrainingLogTable.HR_ZONE1_TIME)], training_log_data[str(TrainingLogTable.HR_ZONE2_TIME)], training_log_data[str(TrainingLogTable.HR_ZONE3_TIME)], training_log_data[str(TrainingLogTable.HR_ZONE4_TIME)], training_log_data[str(TrainingLogTable.HR_ZONE5_TIME)], training_log_data[str(TrainingLogTable.HR_ZONE6_TIME)], training_log_data[str(TrainingLogTable.CALORIES_BURNED)], training_log_data[str(TrainingLogTable.SLEEP_QUALITY)] ) training_log_dao = TrainingLogDao() if training_log_dao.CreateWorkout(training_log): return ResponseHelper.ReturnCreatedResponse("Training Log Created") else: return ResponseHelper.ReturnConflictResponse("Unable to Create Training Log!")