from flask import Blueprint, request
from flask import json

import calendar

from api_app.dao.access_dao import AccessDao
from api_app.dao.training_log_dao import TrainingLogDao
from api_app.models.training_log import TrainingLog
from api_app.decorators.decorators import Decorators
from api_app.helpers.response_helper import ResponseHelper
from api_app.models.update_data import UpdateData
from api_app.constants.request import RequestConstants
from api_app.constants.database.training_log_table import TrainingLogTable

mod_training_log = Blueprint('training_log', __name__, url_prefix='/training-log')


@mod_training_log.route("/<user_id>", methods=['POST'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workout/<training_log_id>", methods=['PUT'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workout/<training_log_id>", methods=['DELETE'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workout/<training_log_id>", methods=['GET'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workouts", methods=['GET'])
@Decorators.TokenRequired
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()



7106e893cff70d65413b87a471c1a00579e26baf
<mask token>


@mod_training_log.route('/<user_id>', methods=['POST'])
@Decorators.TokenRequired
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, user_id, 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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=['PUT']
    )
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=[
    'DELETE'])
@Decorators.TokenRequired
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!')


<mask token>


@mod_training_log.route('/<user_id>/workouts', methods=['GET'])
@Decorators.TokenRequired
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()
    elif 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!')
    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!')
    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!')
    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!')
    else:
        return ResponseHelper.ReturnBadRequestResponse()

<mask token>


@mod_training_log.route('/<user_id>', methods=['POST'])
@Decorators.TokenRequired
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, user_id, 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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=['PUT']
    )
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=[
    'DELETE'])
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=['GET']
    )
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workouts', methods=['GET'])
@Decorators.TokenRequired
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()
    elif 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!')
    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!')
    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!')
    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!')
    else:
        return ResponseHelper.ReturnBadRequestResponse()

<mask token>
mod_training_log = Blueprint('training_log', __name__, url_prefix=
    '/training-log')


@mod_training_log.route('/<user_id>', methods=['POST'])
@Decorators.TokenRequired
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, user_id, 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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=['PUT']
    )
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=[
    'DELETE'])
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=['GET']
    )
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workouts', methods=['GET'])
@Decorators.TokenRequired
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()
    elif 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!')
    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!')
    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!')
    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!')
    else:
        return ResponseHelper.ReturnBadRequestResponse()

from flask import Blueprint, request
from flask import json
import calendar
from api_app.dao.access_dao import AccessDao
from api_app.dao.training_log_dao import TrainingLogDao
from api_app.models.training_log import TrainingLog
from api_app.decorators.decorators import Decorators
from api_app.helpers.response_helper import ResponseHelper
from api_app.models.update_data import UpdateData
from api_app.constants.request import RequestConstants
from api_app.constants.database.training_log_table import TrainingLogTable
mod_training_log = Blueprint('training_log', __name__, url_prefix=
    '/training-log')


@mod_training_log.route('/<user_id>', methods=['POST'])
@Decorators.TokenRequired
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, user_id, 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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=['PUT']
    )
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=[
    'DELETE'])
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workout/<training_log_id>', methods=['GET']
    )
@Decorators.TokenRequired
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!')


@mod_training_log.route('/<user_id>/workouts', methods=['GET'])
@Decorators.TokenRequired
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()
    elif 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!')
    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!')
    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!')
    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!')
    else:
        return ResponseHelper.ReturnBadRequestResponse()

from flask import Blueprint, request
from flask import json

import calendar

from api_app.dao.access_dao import AccessDao
from api_app.dao.training_log_dao import TrainingLogDao
from api_app.models.training_log import TrainingLog
from api_app.decorators.decorators import Decorators
from api_app.helpers.response_helper import ResponseHelper
from api_app.models.update_data import UpdateData
from api_app.constants.request import RequestConstants
from api_app.constants.database.training_log_table import TrainingLogTable

mod_training_log = Blueprint('training_log', __name__, url_prefix='/training-log')


@mod_training_log.route("/<user_id>", methods=['POST'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workout/<training_log_id>", methods=['PUT'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workout/<training_log_id>", methods=['DELETE'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workout/<training_log_id>", methods=['GET'])
@Decorators.TokenRequired
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!")


@mod_training_log.route("/<user_id>/workouts", methods=['GET'])
@Decorators.TokenRequired
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()


