Added ExerciseController
This commit is contained in:
parent
93d212f7e5
commit
50a6ece0d8
|
@ -1,3 +1,6 @@
|
|||
us,United States
|
||||
nl,Netherlands
|
||||
de,Germany
|
||||
uk,United Kingdom
|
||||
dk,Denmark
|
||||
mx,Mexico
|
|
|
@ -0,0 +1,22 @@
|
|||
package nl.andrewlalis.gymboard_api.controller;
|
||||
|
||||
import nl.andrewlalis.gymboard_api.controller.dto.ExerciseResponse;
|
||||
import nl.andrewlalis.gymboard_api.service.ExerciseService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class ExerciseController {
|
||||
private final ExerciseService exerciseService;
|
||||
|
||||
public ExerciseController(ExerciseService exerciseService) {
|
||||
this.exerciseService = exerciseService;
|
||||
}
|
||||
|
||||
@GetMapping(path = "/exercises")
|
||||
public List<ExerciseResponse> getExercises() {
|
||||
return exerciseService.getExercises();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package nl.andrewlalis.gymboard_api.service;
|
||||
|
||||
import nl.andrewlalis.gymboard_api.controller.dto.ExerciseResponse;
|
||||
import nl.andrewlalis.gymboard_api.dao.exercise.ExerciseRepository;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ExerciseService {
|
||||
private final ExerciseRepository exerciseRepository;
|
||||
|
||||
public ExerciseService(ExerciseRepository exerciseRepository) {
|
||||
this.exerciseRepository = exerciseRepository;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<ExerciseResponse> getExercises() {
|
||||
return exerciseRepository.findAll(Sort.by("shortName"))
|
||||
.stream().map(ExerciseResponse::new).toList();
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
<SlimForm>
|
||||
<div class="row">
|
||||
<q-select
|
||||
:options="exercises"
|
||||
:options="exercisesF"
|
||||
v-model="submissionModel.exercise"
|
||||
:label="$t('gymPage.submitPage.exercise')"
|
||||
class="col-12"
|
||||
|
@ -54,7 +54,7 @@
|
|||
|
||||
<script setup lang="ts">
|
||||
import {onMounted, ref, Ref} from 'vue';
|
||||
import {Gym} from 'src/api/gymboard-api';
|
||||
import {Exercise, getExercises, Gym} from 'src/api/gymboard-api';
|
||||
import {getGymFromRoute} from 'src/router/gym-routing';
|
||||
import SlimForm from 'components/SlimForm.vue';
|
||||
|
||||
|
@ -64,6 +64,7 @@ import SlimForm from 'components/SlimForm.vue';
|
|||
// const props = defineProps<Props>();
|
||||
|
||||
const gym: Ref<Gym | undefined> = ref<Gym>();
|
||||
const exercises: Ref<Array<Exercise> | undefined> = ref<Array<Exercise>>();
|
||||
let submissionModel = ref({
|
||||
exercise: null,
|
||||
weight: null,
|
||||
|
@ -72,7 +73,7 @@ let submissionModel = ref({
|
|||
date: new Date().toLocaleDateString('en-CA')
|
||||
});
|
||||
const weightUnits = ['Kg', 'Lbs'];
|
||||
const exercises = ['Bench Press', 'Squat', 'Deadlift'];
|
||||
const exercisesF = ['Bench Press', 'Squat', 'Deadlift'];
|
||||
|
||||
// TODO: Make it possible to pass the gym to this via props instead.
|
||||
onMounted(async () => {
|
||||
|
@ -81,6 +82,11 @@ onMounted(async () => {
|
|||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
try {
|
||||
exercises.value = await getExercises();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
|
||||
function onSubmitted() {
|
||||
|
|
Loading…
Reference in New Issue