removed ip from the get data

This commit is contained in:
2024-02-02 23:40:05 +01:00
parent 62f0e2933e
commit e92821f361
3 changed files with 21 additions and 3 deletions

13
main.py
View File

@@ -1,6 +1,7 @@
from typing import Any
from flask import Flask, json, request
from dataclasses import dataclass
from flask_cors import CORS, cross_origin
@dataclass
class Score:
@@ -8,7 +9,13 @@ class Score:
username: str
ip: str | None = None
@dataclass()
class ScoreDTO:
score: int
username: str
app = Flask(__name__)
cors = CORS(app)
scores: list[Score] = []
@app.route('/')
@@ -16,11 +23,13 @@ def root():
return 'This is the snakes backend for the leaderboard and should only be requested by the snakes webapp'
@app.route('/score', methods = ['GET'])
@cross_origin()
def get_score() -> str:
return json.dumps(scores)
scoreDTOs = map(lambda score: ScoreDTO(score.score, score.username), scores)
return json.dumps(list(scoreDTOs))
@app.route('/score', methods = ['POST'])
@cross_origin()
def add_score() -> str:
body: Any | None = request.json