diff --git a/game_collection/user_management.py b/game_collection/user_management.py index 18b58e3..b6ea088 100644 --- a/game_collection/user_management.py +++ b/game_collection/user_management.py @@ -1,5 +1,5 @@ from flask import Blueprint, request, jsonify, g -from models import db, User +from models import db, User, Game from datetime import datetime, timedelta import jwt from werkzeug.security import generate_password_hash, check_password_hash @@ -99,3 +99,17 @@ def delete_user(user_id): db.session.delete(user) db.session.commit() return jsonify({'message': 'User deleted!'}), 200 + +@user_bp.route('/games/', methods=['PUT']) +def edit_game(game_id): + if not authenticate(): + return jsonify({'message': 'Unauthorized access!'}), 401 + data = request.json + game = Game.query.get(game_id) + if not game: + return jsonify({'message': 'Game not found!'}), 404 + game.title = data.get('title', game.title) + game.image = data.get('image', game.image) + + db.session.commit() + return jsonify({'message': 'Game updated!'}), 200