From bdb693c3612c6b921b826709faa6c5850cfd617d Mon Sep 17 00:00:00 2001 From: "Manuel Weiser (aider)" Date: Mon, 2 Sep 2024 11:42:20 +0200 Subject: [PATCH] feat: add edit_game endpoint to allow users to update game title and image --- game_collection/user_management.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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