From b56019c694b6bf24d73754ca8cd8e7df3d4f7440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gramain?= Date: Wed, 27 Mar 2024 11:18:57 +0100 Subject: [PATCH] init --- .gitignore | 0 .idea/TP1_R410.iml | 10 ++ .idea/inspectionProfiles/Project_Default.xml | 6 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 49 ++++++ PROJET.md | 0 athlete/Dockerfile | 11 ++ athlete/app.py | 25 +++ athlete/athlete.py | 15 ++ athlete/conftest.py | 24 +++ athlete/genData.py | 0 athlete/static/swagger.yaml | 161 ++++++++++++++++++ athlete/tests/athletes.json | 38 +++++ athlete/tests/test_getAthlete.py | 8 + athlete/tests/test_listeAthlete.py | 0 athlete/tests/test_ping.py | 5 + data/athletes.json | 38 +++++ discipline/swagger.yaml | 0 docker-compose.yaml | 0 medaille/swagger.yaml | 0 requirements.txt | 4 + sample/athletes.json | 38 +++++ 25 files changed, 456 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/TP1_R410.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 PROJET.md create mode 100644 athlete/Dockerfile create mode 100644 athlete/app.py create mode 100644 athlete/athlete.py create mode 100644 athlete/conftest.py create mode 100644 athlete/genData.py create mode 100644 athlete/static/swagger.yaml create mode 100644 athlete/tests/athletes.json create mode 100644 athlete/tests/test_getAthlete.py create mode 100644 athlete/tests/test_listeAthlete.py create mode 100644 athlete/tests/test_ping.py create mode 100644 data/athletes.json create mode 100644 discipline/swagger.yaml create mode 100644 docker-compose.yaml create mode 100644 medaille/swagger.yaml create mode 100644 requirements.txt create mode 100644 sample/athletes.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.idea/TP1_R410.iml b/.idea/TP1_R410.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/TP1_R410.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..03d9549 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..58b0e4d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ebb0930 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..5b1f0fd --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + 1710919740613 + + + + \ No newline at end of file diff --git a/PROJET.md b/PROJET.md new file mode 100644 index 0000000..e69de29 diff --git a/athlete/Dockerfile b/athlete/Dockerfile new file mode 100644 index 0000000..bafe792 --- /dev/null +++ b/athlete/Dockerfile @@ -0,0 +1,11 @@ +FROM python:alpine3.19 + +WORKDIR /app + +COPY /requirements.txt requirements.txt + +RUN pip install -r requirements.txt + +COPY . . + +CMD ["python", "app.py"] \ No newline at end of file diff --git a/athlete/app.py b/athlete/app.py new file mode 100644 index 0000000..11e292a --- /dev/null +++ b/athlete/app.py @@ -0,0 +1,25 @@ +from flask import Flask, jsonify +import athlete + +app = Flask(__name__) + +@app.route('/ping', methods=["GET"]) +def ping(): + return jsonify({"message": "pong"}), 200 +@app.route('/', methods=["GET"]) +def hello_world(): + return jsonify(athlete.Athlete( + id=1, + prenom="john", + nom="doe", + pays="France", + sexe="Homme", + image="localhost", + disciplines=[123], + ).model_dump()) + +def create_app(): + return app + +if __name__ == '__main__': + app.run() diff --git a/athlete/athlete.py b/athlete/athlete.py new file mode 100644 index 0000000..d826389 --- /dev/null +++ b/athlete/athlete.py @@ -0,0 +1,15 @@ +from pydantic import BaseModel +from typing import Optional + +class Athlete(BaseModel): + """ + Modèle Athlète + """ + id: Optional[int] + prenom: str + nom: str + pays: str + sexe: str = "N/A" + image: str = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_640.png" + disciplines: Optional[list[int]] = None + records: Optional[list[int]] = None diff --git a/athlete/conftest.py b/athlete/conftest.py new file mode 100644 index 0000000..882eddb --- /dev/null +++ b/athlete/conftest.py @@ -0,0 +1,24 @@ +import pytest +from ..app.app import create_app + +@pytest.fixture() +def app(): + app = create_app() + app.config.update({ + "TESTING": True, + }) + + # other setup can go here + + yield app + + # clean up / reset resources here + +@pytest.fixture() +def client(app): + return app.test_client() + + +@pytest.fixture() +def runner(app): + return app.test_cli_runner() \ No newline at end of file diff --git a/athlete/genData.py b/athlete/genData.py new file mode 100644 index 0000000..e69de29 diff --git a/athlete/static/swagger.yaml b/athlete/static/swagger.yaml new file mode 100644 index 0000000..540ddfe --- /dev/null +++ b/athlete/static/swagger.yaml @@ -0,0 +1,161 @@ +openapi: 3.0.1 +info: + title: API Joueurs des J.O. 2024 + description: |- + Cette API uService sert à afficher les informations sur les joueurs des JO 2024. + version: 0.0.1 +servers: + - url: /joueurs/ +tags: + - name: athlete + description: Joueur des J.O. +paths: + /: + get: + tags: + - athlete + parameters: + - in: query + name: offset + schema: + type: integer + description: Le nombre d'éléments à ignorer avant de commencer à collecter l'ensemble de résultats + - in: query + name: limit + schema: + type: integer + description: Le nombre d'éléments à ignorer + summary: Liste l'ensemble des athlètes + description: Affiche la liste des athlètes enregistrés sur les J.O. 2024. + operationId: listeAthletes + responses: + '200': + description: Athlète + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Athlete' + post: + tags: + - athlete + summary: Créer un athlète + operationId: createAthelte + requestBody: + description: Objet athlète a créer + content: + application/json: + schema: + $ref: '#/components/schemas/Athlete' + responses: + default: + description: Opération avec succès + content: + application/json: + schema: + $ref: '#/components/schemas/Athlete' + /{id}: + parameters: + - name: id + in: path + description: ID de l'Athlète à récupérer + required: true + schema: + type: integer + get: + tags: + - athlete + summary: Récupération d'un athlète selon son id + operationId: getAthlete + responses: + '200': + description: Opération avec succès + content: + application/json: + schema: + $ref: '#/components/schemas/Athlete' + '400': + description: ID donné invalide + '404': + description: Athlète introuvable + patch: + tags: + - athlete + summary: Mettre à jour un athlète + operationId: updateAthlete + requestBody: + description: Mettre à jour un athlète existant + content: + application/json: + schema: + $ref: '#/components/schemas/Athlete' + responses: + default: + description: Opération avec succès + delete: + tags: + - athlete + summary: Supprimer un athlète + operationId: deleteAthlete + responses: + '400': + description: ID donné invalide + '404': + description: Athlète introuvable + /ping: + get: + summary: Vérifier la disponibilité du service + operationId: ping + responses: + '200': + description: Service disponible + content: + application/json: + schema: + type: object + properties: + message: + type: string + example: pong +components: + schemas: + Athlete: + type: object + properties: + id: + type: integer + format: uuid + example: 123456789 + prenom: + type: string + example: Teddy + nom: + type: string + example: Rinner + pays: + type: string + example: France + sexe: + type: string + example: Homme + image: + type: string + example: http://www.humanite.fr/wp-content/uploads/2023/05/311202.hr_.jpg?w=1024 + disciplines: + type: array + items: + type: integer + example: 1235 + records: + type: array + items: + type: integer + example: 1235 + requestBodies: + User: + description: Objet athlète à ajouter + content: + application/json: + schema: + $ref: '#/components/schemas/Athlete' \ No newline at end of file diff --git a/athlete/tests/athletes.json b/athlete/tests/athletes.json new file mode 100644 index 0000000..bd72eda --- /dev/null +++ b/athlete/tests/athletes.json @@ -0,0 +1,38 @@ +[ + { + "id": 1, + "prenom": "Riner", + "nom": "Teddy", + "pays": "France", + "sexe": "H", + "image": "https://upload.wikimedia.org/wikipedia/commons/4/4e/Teddy_Riner_2012.jpg", + "disciplines": [ + 1 + ], + "records": [] + }, + { + "id": 2, + "prenom": "Flessel", + "nom": "Laura", + "pays": "France", + "sexe": "H", + "image": "https://plusquedusport.files.wordpress.com/2012/04/124936207sl015_laura_flesse.jpg", + "disciplines": [ + 2 + ], + "records": [] + }, + { + "id": 3, + "prenom": "Monfils", + "nom": "Ga\u00ebl", + "pays": "France", + "sexe": "H", + "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Monfils_RG19_%2813%29_%2848199149362%29.jpg/1200px-Monfils_RG19_%2813%29_%2848199149362%29.jpg", + "disciplines": [ + 3 + ], + "records": [] + } +] \ No newline at end of file diff --git a/athlete/tests/test_getAthlete.py b/athlete/tests/test_getAthlete.py new file mode 100644 index 0000000..052b47e --- /dev/null +++ b/athlete/tests/test_getAthlete.py @@ -0,0 +1,8 @@ +import unittest + +class MyTestCase(unittest.TestCase): + def test_something(self): + self.assertEqual(True, False) # add assertion here + +if __name__ == '__main__': + unittest.main() diff --git a/athlete/tests/test_listeAthlete.py b/athlete/tests/test_listeAthlete.py new file mode 100644 index 0000000..e69de29 diff --git a/athlete/tests/test_ping.py b/athlete/tests/test_ping.py new file mode 100644 index 0000000..29b234a --- /dev/null +++ b/athlete/tests/test_ping.py @@ -0,0 +1,5 @@ +import pytest + +def test_ping(client): + response = client.get("/ping") + assert b"{\"message\":\"pong\"}\n" in response.data \ No newline at end of file diff --git a/data/athletes.json b/data/athletes.json new file mode 100644 index 0000000..bd72eda --- /dev/null +++ b/data/athletes.json @@ -0,0 +1,38 @@ +[ + { + "id": 1, + "prenom": "Riner", + "nom": "Teddy", + "pays": "France", + "sexe": "H", + "image": "https://upload.wikimedia.org/wikipedia/commons/4/4e/Teddy_Riner_2012.jpg", + "disciplines": [ + 1 + ], + "records": [] + }, + { + "id": 2, + "prenom": "Flessel", + "nom": "Laura", + "pays": "France", + "sexe": "H", + "image": "https://plusquedusport.files.wordpress.com/2012/04/124936207sl015_laura_flesse.jpg", + "disciplines": [ + 2 + ], + "records": [] + }, + { + "id": 3, + "prenom": "Monfils", + "nom": "Ga\u00ebl", + "pays": "France", + "sexe": "H", + "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Monfils_RG19_%2813%29_%2848199149362%29.jpg/1200px-Monfils_RG19_%2813%29_%2848199149362%29.jpg", + "disciplines": [ + 3 + ], + "records": [] + } +] \ No newline at end of file diff --git a/discipline/swagger.yaml b/discipline/swagger.yaml new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..e69de29 diff --git a/medaille/swagger.yaml b/medaille/swagger.yaml new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b5661fc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +flask==3.0.2 +pydantic==2.6.4 +pytest +flask_swagger_ui \ No newline at end of file diff --git a/sample/athletes.json b/sample/athletes.json new file mode 100644 index 0000000..bd72eda --- /dev/null +++ b/sample/athletes.json @@ -0,0 +1,38 @@ +[ + { + "id": 1, + "prenom": "Riner", + "nom": "Teddy", + "pays": "France", + "sexe": "H", + "image": "https://upload.wikimedia.org/wikipedia/commons/4/4e/Teddy_Riner_2012.jpg", + "disciplines": [ + 1 + ], + "records": [] + }, + { + "id": 2, + "prenom": "Flessel", + "nom": "Laura", + "pays": "France", + "sexe": "H", + "image": "https://plusquedusport.files.wordpress.com/2012/04/124936207sl015_laura_flesse.jpg", + "disciplines": [ + 2 + ], + "records": [] + }, + { + "id": 3, + "prenom": "Monfils", + "nom": "Ga\u00ebl", + "pays": "France", + "sexe": "H", + "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Monfils_RG19_%2813%29_%2848199149362%29.jpg/1200px-Monfils_RG19_%2813%29_%2848199149362%29.jpg", + "disciplines": [ + 3 + ], + "records": [] + } +] \ No newline at end of file