From a711426a7597dc4b1244e3b0349937dc186175c8 Mon Sep 17 00:00:00 2001 From: hollum <hollum@hotmail.com> Date: Mon, 7 Mar 2022 17:17:33 +0100 Subject: [PATCH] added possibility to add goals to backend --- backend/secfit/workouts/models.py | 10 +++------- backend/secfit/workouts/serializers.py | 9 ++------- backend/secfit/workouts/views.py | 6 +++--- frontend/www/goals.html | 8 +++++--- frontend/www/scripts/goals.js | 20 +++++++++++++------- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/backend/secfit/workouts/models.py b/backend/secfit/workouts/models.py index f8c0c3d..3148639 100644 --- a/backend/secfit/workouts/models.py +++ b/backend/secfit/workouts/models.py @@ -93,17 +93,13 @@ class Exercise(models.Model): return self.name class Goal(models.Model): - """Django model for an exercise type that users can create. - - Each exercise instance must have an exercise type, e.g., Pushups, Crunches, or Lunges. + """Django model for an goal type that users can create. Attributes: name: Name of the exercise type description: Description of the exercise type - duration: Duration of one unit of the exercise - calories: Calories spent per minute - muscleGroup: What major muscle group is used in the exercise - unit: Name of the unit for the exercise type (e.g., reps, seconds) + date: Date of whenever a goal should end + exercise: What exercise is connected to a specific goal """ name = models.CharField(max_length=100) diff --git a/backend/secfit/workouts/serializers.py b/backend/secfit/workouts/serializers.py index b21342d..98036ee 100644 --- a/backend/secfit/workouts/serializers.py +++ b/backend/secfit/workouts/serializers.py @@ -216,16 +216,11 @@ class ExerciseSerializer(serializers.HyperlinkedModelSerializer): fields = ["url", "id", "name", "description", "duration", "calories", "muscleGroup", "unit", "instances"] class GoalSerializer(serializers.HyperlinkedModelSerializer): - """Serializer for an Exercise. Hyperlinks are used for relationships by default. - - Serialized fields: url, id, name, description, duration, calories, muscle group, unit, instances + """Serializer for an Goal. Hyperlinks are used for relationships by default. - Attributes: - instances: Associated exercise instances with this Exercise type. Hyperlinks. + Serialized fields: id, name, description, date, exercise """ - - class Meta: model = Goal fields = ["id", "name", "description", "date", "exercise"] diff --git a/backend/secfit/workouts/views.py b/backend/secfit/workouts/views.py index db217e0..9b64e09 100644 --- a/backend/secfit/workouts/views.py +++ b/backend/secfit/workouts/views.py @@ -225,8 +225,8 @@ class ExerciseDetail( class GoalList( mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView ): - """Class defining the web response for the creation of an Exercise, or - a list of Exercises. + """Class defining the web response for the creation of an Goal, or + a list of Goals. HTTP methods: GET, POST """ @@ -248,7 +248,7 @@ class GoalDetail( mixins.DestroyModelMixin, generics.GenericAPIView, ): - """Class defining the web response for the details of an individual Exercise. + """Class defining the web response for the details of an individual Goal. HTTP methods: GET, PUT, PATCH, DELETE """ diff --git a/frontend/www/goals.html b/frontend/www/goals.html index ede323d..5acb9e3 100644 --- a/frontend/www/goals.html +++ b/frontend/www/goals.html @@ -28,9 +28,11 @@ <template id="template-exercise"> <div class="card ml-1" style="width: 24rem;"> <div class="card-body"> - <h5 class="card-title"></h5> - <p class="card-text"></p> - <a href="#" class="card-link">Edit goal</a> + <h2 class="card-title" ></h2> + <h6 class="card-title" ></h6> + <h5 class="card-title" >Exercise: </h5> + <p class="card-text" ></p> + <a href="#" class="card-link" >Edit goal</a> </div> </div> </template> diff --git a/frontend/www/scripts/goals.js b/frontend/www/scripts/goals.js index b7304e6..a4b86cc 100644 --- a/frontend/www/scripts/goals.js +++ b/frontend/www/scripts/goals.js @@ -1,24 +1,30 @@ async function fetchExerciseTypes(request) { - let response = await sendRequest("GET", `${HOST}/api/exercises/`); + let response = await sendRequest("GET", `${HOST}/api/goal/`); if (response.ok) { let data = await response.json(); - let exercises = data.results; + let goals = data.results; let container = document.getElementById('div-content'); let exerciseTemplate = document.querySelector("#template-exercise"); - exercises.forEach(exercise => { + goals.forEach(goal => { const exerciseAnchor = exerciseTemplate.content.firstElementChild.cloneNode(true); - exerciseAnchor.href = `exercise.html?id=${exercise.id}`; + exerciseAnchor.href = `goal.html?id=${goal.id}`; + + const h2 = exerciseAnchor.querySelector("h2"); + h2.textContent = goal.name; + + const h6 = exerciseAnchor.querySelector("h6"); + h6.textContent = goal.date; const h5 = exerciseAnchor.querySelector("h5"); - h5.textContent = exercise.name; + h5.textContent += goal.exercise; const p = exerciseAnchor.querySelector("p"); - p.textContent = exercise.description; + p.textContent = goal.description; const a = exerciseAnchor.querySelector("a"); - a.href = `exercise.html?id=${exercise.id}`; + a.href = `goal.html?id=${goal.id}`; container.appendChild(exerciseAnchor); }); -- GitLab