diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/GymController.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/GymController.java index a827ceb..4522018 100644 --- a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/GymController.java +++ b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/GymController.java @@ -8,12 +8,11 @@ import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; - /** * Controller for accessing a particular gym. */ @RestController +@RequestMapping(path = "/gyms/{compoundId}") public class GymController { private final GymService gymService; private final UploadService uploadService; @@ -25,35 +24,32 @@ public class GymController { this.submissionService = submissionService; } - @GetMapping(path = "/gyms/{countryCode}/{cityCode}/{gymName}") - public GymResponse getGym( - @PathVariable String countryCode, - @PathVariable String cityCode, - @PathVariable String gymName - ) { - return gymService.getGym(new RawGymId(countryCode, cityCode, gymName)); + @GetMapping + public GymResponse getGym(@PathVariable String compoundId) { + return gymService.getGym(CompoundGymId.parse(compoundId)); } - @PostMapping(path = "/gyms/{countryCode}/{cityCode}/{gymName}/submissions") + @PostMapping(path = "/submissions") public ExerciseSubmissionResponse createSubmission( - @PathVariable String countryCode, - @PathVariable String cityCode, - @PathVariable String gymName, + @PathVariable String compoundId, @RequestBody ExerciseSubmissionPayload payload ) { - return submissionService.createSubmission(new RawGymId(countryCode, cityCode, gymName), payload); + return submissionService.createSubmission(CompoundGymId.parse(compoundId), payload); } - @PostMapping( - path = "/gyms/{countryCode}/{cityCode}/{gymName}/submissions/upload", - consumes = MediaType.MULTIPART_FORM_DATA_VALUE - ) + @GetMapping(path = "/submissions/{submissionId}") + public ExerciseSubmissionResponse getSubmission( + @PathVariable String compoundId, + @PathVariable long submissionId + ) { + return submissionService.getSubmission(CompoundGymId.parse(compoundId), submissionId); + } + + @PostMapping(path = "/submissions/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public UploadedFileResponse uploadVideo( - @PathVariable String countryCode, - @PathVariable String cityCode, - @PathVariable String gymName, + @PathVariable String compoundId, @RequestParam MultipartFile file ) { - return uploadService.handleSubmissionUpload(new RawGymId(countryCode, cityCode, gymName), file); + return uploadService.handleSubmissionUpload(CompoundGymId.parse(compoundId), file); } } diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/CompoundGymId.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/CompoundGymId.java new file mode 100644 index 0000000..6fe8ee8 --- /dev/null +++ b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/CompoundGymId.java @@ -0,0 +1,28 @@ +package nl.andrewlalis.gymboard_api.controller.dto; + +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +public record CompoundGymId(String country, String city, String gym) { + /** + * Parses a compound gym id from a string expression. + *
+ * For example, `nl_groningen_trainmore-munnekeholm`. + *
+ * @param idStr The id string. + * @return The compound gym id. + * @throws ResponseStatusException A not found exception is thrown if the id + * string is invalid. + */ + public static CompoundGymId parse(String idStr) throws ResponseStatusException { + if (idStr == null || idStr.isBlank()) throw new ResponseStatusException(HttpStatus.NOT_FOUND); + String[] parts = idStr.strip().toLowerCase().split("_"); + if (parts.length != 3) throw new ResponseStatusException(HttpStatus.NOT_FOUND); + + return new CompoundGymId( + parts[0], + parts[1], + parts[2] + ); + } +} diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionPayload.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionPayload.java index 9760f29..2d8ae27 100644 --- a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionPayload.java +++ b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionPayload.java @@ -4,6 +4,7 @@ public record ExerciseSubmissionPayload( String name, String exerciseShortName, float weight, + String weightUnit, int reps, long videoId ) {} diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionResponse.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionResponse.java index e1c7452..2abe6ac 100644 --- a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionResponse.java +++ b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/ExerciseSubmissionResponse.java @@ -11,7 +11,9 @@ public record ExerciseSubmissionResponse( ExerciseResponse exercise, String status, String submitterName, - double weight, + double rawWeight, + String weightUnit, + double metricWeight, int reps ) { public ExerciseSubmissionResponse(ExerciseSubmission submission) { @@ -22,7 +24,9 @@ public record ExerciseSubmissionResponse( new ExerciseResponse(submission.getExercise()), submission.getStatus().name(), submission.getSubmitterName(), - submission.getWeight().doubleValue(), + submission.getRawWeight().doubleValue(), + submission.getWeightUnit().name(), + submission.getMetricWeight().doubleValue(), submission.getReps() ); } diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/RawGymId.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/RawGymId.java deleted file mode 100644 index 0b22f07..0000000 --- a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/controller/dto/RawGymId.java +++ /dev/null @@ -1,3 +0,0 @@ -package nl.andrewlalis.gymboard_api.controller.dto; - -public record RawGymId(String countryCode, String cityCode, String gymName) {} diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/dao/GymRepository.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/dao/GymRepository.java index 961f9ce..ae164c1 100644 --- a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/dao/GymRepository.java +++ b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/dao/GymRepository.java @@ -1,5 +1,6 @@ package nl.andrewlalis.gymboard_api.dao; +import nl.andrewlalis.gymboard_api.controller.dto.CompoundGymId; import nl.andrewlalis.gymboard_api.model.Gym; import nl.andrewlalis.gymboard_api.model.GymId; import org.springframework.data.jpa.repository.JpaRepository; @@ -12,8 +13,14 @@ import java.util.Optional; @Repository public interface GymRepository extends JpaRepository{{ title }}
-Count: {{ todoCount }} / {{ meta.totalCount }}
-Active: {{ active ? 'yes' : 'no' }}
-Clicks on todos: {{ clickCount }}
-Recent top lifts go here.
- -All the rest of the gym leaderboards should show up here.
- -- Some text here. -
+Some text here.