Exemple #1
0
def CheckCoachTrainingLogAccess(current_user, user_type, athlete_id):
    if not athlete_id:
        return ResponseHelper.ReturnBadRequestResponse()

    if user_type != RequestConstants.USER_TYPE_COA:
        return ResponseHelper.ReturnBadRequestResponse()

    access_dao = AccessDao()

    if access_dao.CheckCoachTrainingLogAccess(current_user, athlete_id):
        return ResponseHelper.ReturnOkResponse("Ok")

    else:
        return ResponseHelper.ReturnUnauthorizedResponse(
            "Needs to request access!")
Exemple #2
0
def DeleteTrainingLog(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()

    training_log_dao = TrainingLogDao()

    if training_log_dao.DeleteWorkout(user_id, training_log_id):
        return ResponseHelper.ReturnOkResponse("Training Log Deleted")

    else:
        return ResponseHelper.ReturnConflictResponse("Unable to Delete Training Log!")
Exemple #3
0
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!")
Exemple #4
0
def UpdateTrainingLog(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 request.data:
        return ResponseHelper.ReturnBadRequestResponse()

    else:
        request_data = json.loads(request.data)

        update_data = UpdateData(
            request_data[RequestConstants.UPDATE_REQUEST_MEMBER_KEYS],
            request_data[RequestConstants.UPDATE_REQUEST_MEMBER_VALUES],
            [TrainingLogTable.ID, TrainingLogTable.ATHLETE_ID],
            [training_log_id, user_id]
        )

        if TrainingLogTable.ID in update_data.memberKeys:

            return ResponseHelper.ReturnBadRequestResponse()

        if TrainingLogTable.ATHLETE_ID in update_data.memberKeys:

            return ResponseHelper.ReturnBadRequestResponse()

        training_log_dao = TrainingLogDao()

        if training_log_dao.UpdateWorkout(update_data):
            return ResponseHelper.ReturnOkResponse("Training Log Updated")

        else:
            return ResponseHelper.ReturnConflictResponse("Unable to Update Training Log!")
Exemple #5
0
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!")
Exemple #6
0
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()