コード例 #1
0
ファイル: workout.py プロジェクト: nicknav98/Gym-Planner
    def patch(self, workout_id):

        json_data = request.get_json()

        data, errors = workout_schema.load(data=json_data, partial=('name', ))

        if errors:
            return {
                'message': 'Validation errors',
                'errors': errors
            }, HTTPStatus.BAD_REQUEST

        workout = Workout.get_by_id(workout_id=workout_id)

        if workout is None:
            return {'message': 'Workout not found'}, HTTPStatus.NOT_FOUND

        current_user = get_jwt_identity()

        if current_user != workout.user_id:
            return {'message': 'Access is not allowed'}, HTTPStatus.FORBIDDEN

        workout.name = data.get('name') or workout.name
        workout.length = data.get('length') or workout.length
        workout.directions = data.get('directions') or workout.directions
        workout.body_part = data.get('body_part') or workout.body_part

        workout.save()

        return workout_schema.dump(workout), HTTPStatus.OK
コード例 #2
0
ファイル: workout.py プロジェクト: nicknav98/Gym-Planner
    def get(self, workout_id):
        workout = Workout.get_by_id(workout_id=workout_id)

        if workout is None:
            return {'message': 'workout not found'}, HTTPStatus.NOT_FOUND

        current_user = get_jwt_identity()

        if workout.is_publish == False and workout_id != current_user:
            return {'message': 'Access is not allowed'}, HTTPStatus.FORBIDDEN

        return workout_schema.dump(workout).data, HTTPStatus.OK
コード例 #3
0
ファイル: workout.py プロジェクト: nicknav98/Gym-Planner
    def delete(self, workout_id):
        workout = Workout.get_by_id(workout_id=workout_id)

        if workout is None:
            return {'message': 'Workout not found'}, HTTPStatus.NOT_FOUND

        current_user = get_jwt_identity()

        if current_user != workout.user_id:
            return {'message': 'Access is not allowed'}, HTTPStatus.FORBIDDEN

        workout.delete()

        return {}, HTTPStatus.NO_CONTENT