This commit is contained in:
Mael G. 2024-03-27 11:18:57 +01:00
commit b56019c694
25 changed files with 456 additions and 0 deletions

0
.gitignore vendored Normal file
View file

10
.idea/TP1_R410.iml Normal file
View file

@ -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>

View file

@ -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>

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View file

@ -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>

8
.idea/modules.xml Normal file
View file

@ -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>

6
.idea/vcs.xml Normal file
View file

@ -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>

49
.idea/workspace.xml Normal file
View file

@ -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>

0
PROJET.md Normal file
View file

11
athlete/Dockerfile Normal file
View file

@ -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"]

25
athlete/app.py Normal file
View file

@ -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()

15
athlete/athlete.py Normal file
View file

@ -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

24
athlete/conftest.py Normal file
View file

@ -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()

0
athlete/genData.py Normal file
View file

161
athlete/static/swagger.yaml Normal file
View file

@ -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'

View file

@ -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": []
}
]

View file

@ -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()

View file

View file

@ -0,0 +1,5 @@
import pytest
def test_ping(client):
response = client.get("/ping")
assert b"{\"message\":\"pong\"}\n" in response.data

38
data/athletes.json Normal file
View file

@ -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": []
}
]

0
discipline/swagger.yaml Normal file
View file

0
docker-compose.yaml Normal file
View file

0
medaille/swagger.yaml Normal file
View file

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
flask==3.0.2
pydantic==2.6.4
pytest
flask_swagger_ui

38
sample/athletes.json Normal file
View file

@ -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": []
}
]