diff --git a/main.py b/main.py index 2ef4435..d81d4fa 100644 --- a/main.py +++ b/main.py @@ -413,71 +413,6 @@ def get_profile(request: ProfileRequest): finally: cursor.close() conn.close() - -@app.post("/getprofile") -def get_profile(request: ProfileRequest): - conn = get_db_connection() - cursor = conn.cursor() - try: - cursor.execute("SELECT uid, display_name, current_elo, openskill_mu, openskill_sigma FROM users WHERE token = %s;", (request.token,)) - user = cursor.fetchone() - if not user: - raise HTTPException(status_code=404, detail="User not found") - - uid, display_name, current_elo = user["uid"], user["display_name"], user["current_elo"] - - cursor.execute( - """ - SELECT - m.match_id, - u.display_name AS opponent_name, - m.match_date, - CASE - WHEN m.player1_uid = %s AND m.player1_score > m.player2_score THEN 'Win' - WHEN m.player2_uid = %s AND m.player2_score > m.player1_score THEN 'Win' - ELSE 'Loss' - END AS result, - CASE - WHEN m.player1_uid = %s THEN m.player1_elo_change - WHEN m.player2_uid = %s THEN m.player2_elo_change - END AS elo_change - FROM matches m - JOIN users u ON u.uid = CASE - WHEN m.player1_uid = %s THEN m.player2_uid - WHEN m.player2_uid = %s THEN m.player1_uid - END - WHERE %s IN (m.player1_uid, m.player2_uid) - ORDER BY m.match_date DESC - LIMIT 10; - """, - (uid, uid, uid, uid, uid, uid, uid) - ) - matches = cursor.fetchall() - - return { - "name": display_name, - "uid": uid, - "elo": current_elo, - "openskill_rate": openskill_mu, - "openskill_stdev": openskill_sigma, - "matches": [ - { - "match_id": match["match_id"], - "opponent_name": match["opponent_name"], - "result": match["result"], - "elo_change": match["elo_change"], - "match_date": match["match_date"].isoformat() - } - for match in matches - ] - } - except Exception as e: - raise HTTPException(status_code=400, detail=str(e)) - finally: - cursor.close() - conn.close() - - @app.get("/version") def get_latest_commit_hashes():