commit b56019c694b6bf24d73754ca8cd8e7df3d4f7440 Author: Maël Gramain <mael@enpls.org> Date: Wed Mar 27 11:18:57 2024 +0100 init 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="PYTHON_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/.venv" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ 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 @@ +<component name="InspectionProjectProfileManager"> + <profile version="1.0"> + <option name="myName" value="Project Default" /> + <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" /> + </profile> +</component> \ 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 @@ +<component name="InspectionProjectProfileManager"> + <settings> + <option name="USE_PROJECT_PROFILE" value="false" /> + <version value="1.0" /> + </settings> +</component> \ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (TP1_R410)" project-jdk-type="Python SDK" /> +</project> \ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/TP1_R410.iml" filepath="$PROJECT_DIR$/.idea/TP1_R410.iml" /> + </modules> + </component> +</project> \ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ChangeListManager"> + <list default="true" id="1cc00508-2e42-4ce9-abae-08155c1c5500" name="Changes" comment="" /> + <option name="SHOW_DIALOG" value="false" /> + <option name="HIGHLIGHT_CONFLICTS" value="true" /> + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> + <option name="LAST_RESOLUTION" value="IGNORE" /> + </component> + <component name="Git.Settings"> + <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> + </component> + <component name="ProjectColorInfo"><![CDATA[{ + "associatedIndex": 3 +}]]></component> + <component name="ProjectId" id="2dwWhX1OxNoO33O0CVQTMaL4hje" /> + <component name="ProjectLevelVcsManager" settingsEditedManually="true" /> + <component name="ProjectViewState"> + <option name="hideEmptyMiddlePackages" value="true" /> + <option name="showLibraryContents" value="true" /> + </component> + <component name="PropertiesComponent"><![CDATA[{ + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "main", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + } +}]]></component> + <component name="SharedIndexes"> + <attachedChunks> + <set> + <option value="bundled-python-sdk-5a2391486177-2887949eec09-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-233.13763.11" /> + </set> + </attachedChunks> + </component> + <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> + <component name="TaskManager"> + <task active="true" id="Default" summary="Default task"> + <changelist id="1cc00508-2e42-4ce9-abae-08155c1c5500" name="Changes" comment="" /> + <created>1710919740613</created> + <option name="number" value="Default" /> + <option name="presentableId" value="Default" /> + <updated>1710919740613</updated> + </task> + <servers /> + </component> +</project> \ 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