diff --git a/src/character/templates/character/view.html b/src/character/templates/character/view.html
index f651523..7b4f1d2 100644
--- a/src/character/templates/character/view.html
+++ b/src/character/templates/character/view.html
@@ -98,8 +98,36 @@
{{ character.health_max }} |
- PV restants |
- {{ character.health_remaining }} |
+
+ PV restants
+
+
+
+
+
+
+ |
+ {{ character.health_remaining }} |
PM max |
diff --git a/src/character/urls.py b/src/character/urls.py
index 6e66e8a..d01c856 100644
--- a/src/character/urls.py
+++ b/src/character/urls.py
@@ -3,4 +3,7 @@ from django.urls import path
from character import views
app_name = "character"
-urlpatterns = [path("/", views.character_view, name="view")]
+urlpatterns = [
+ path("/", views.character_view, name="view"),
+ path("/health_change", views.character_health_change, name="health_change"),
+]
diff --git a/src/character/views.py b/src/character/views.py
index 9b6e641..b00c430 100644
--- a/src/character/views.py
+++ b/src/character/views.py
@@ -11,3 +11,22 @@ def character_view(request: WSGIRequest, pk: int) -> HttpResponse:
character = get_object_or_404(Character.objects.select_related("player"), pk=pk)
context = {"character": character}
return render(request, "character/view.html", context)
+
+
+@login_required
+def character_health_change(request: WSGIRequest, pk: int) -> HttpResponse:
+ character = get_object_or_404(Character, pk=pk)
+ value = request.GET.get("value")
+ if value == "ko":
+ character.health_remaining = 0
+ elif value == "max":
+ character.health_remaining = character.health_max
+ else:
+ value = int(value)
+ character.health_remaining += value
+ character.health_remaining = min(
+ [character.health_max, character.health_remaining]
+ )
+ character.health_remaining = max([0, character.health_remaining])
+ character.save(update_fields=["health_remaining"])
+ return HttpResponse(character.health_remaining)