-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from bounswe/issue#160-create-training-program
Issue#160 create training program
- Loading branch information
Showing
17 changed files
with
449 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
backend/demo-group7/src/main/java/com/group7/demo/controllers/TrainingProgramController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.group7.demo.controllers; | ||
|
||
import com.group7.demo.dtos.TrainingProgramRequest; | ||
import com.group7.demo.dtos.TrainingProgramResponse; | ||
import com.group7.demo.services.TrainingProgramService; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/training-programs") | ||
@AllArgsConstructor | ||
public class TrainingProgramController { | ||
|
||
private final TrainingProgramService trainingProgramService; | ||
|
||
// Endpoint to create a new training program | ||
@PostMapping | ||
public ResponseEntity<TrainingProgramResponse> createTrainingProgram(@RequestBody TrainingProgramRequest request) { | ||
TrainingProgramResponse createdProgram = trainingProgramService.createTrainingProgram(request); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(createdProgram); | ||
} | ||
|
||
// Optional: Endpoint to fetch a list of training programs | ||
@GetMapping | ||
public ResponseEntity<List<TrainingProgramResponse>> getAllTrainingPrograms() { | ||
List<TrainingProgramResponse> trainingPrograms = trainingProgramService.getAllTrainingPrograms(); | ||
return ResponseEntity.ok(trainingPrograms); | ||
} | ||
|
||
// Optional: Endpoint to fetch a specific training program by ID | ||
@GetMapping("/{id}") | ||
public ResponseEntity<TrainingProgramResponse> getTrainingProgramById(@PathVariable Long id) { | ||
TrainingProgramResponse trainingProgram = trainingProgramService.getTrainingProgramById(id); | ||
return ResponseEntity.ok(trainingProgram); | ||
} | ||
|
||
// Optional: Endpoint to delete a training program by ID | ||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteTrainingProgram(@PathVariable Long id) { | ||
trainingProgramService.deleteTrainingProgram(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/demo-group7/src/main/java/com/group7/demo/dtos/ExerciseDetailRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.group7.demo.dtos; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class ExerciseDetailRequest { | ||
|
||
private Integer sets; | ||
private Integer repetitions; | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/demo-group7/src/main/java/com/group7/demo/dtos/ExerciseDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.group7.demo.dtos; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class ExerciseDetailResponse { | ||
private Integer sets; | ||
private Integer repetitions; | ||
|
||
// Getters, setters, and builder... | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/demo-group7/src/main/java/com/group7/demo/dtos/ExerciseRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.group7.demo.dtos; | ||
|
||
import com.group7.demo.models.enums.MuscleGroup; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class ExerciseRequest { | ||
|
||
private String name; // Name of the exercise | ||
private MuscleGroup muscleGroup; // Enum for muscle groups | ||
private Integer sets; // Number of sets | ||
private Integer repetitions; // Number of repetitions per set | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/demo-group7/src/main/java/com/group7/demo/dtos/ExerciseResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.group7.demo.dtos; | ||
|
||
import com.group7.demo.models.enums.MuscleGroup; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class ExerciseResponse { | ||
private String name; | ||
private MuscleGroup muscleGroup; | ||
private ExerciseDetailResponse exerciseDetail; | ||
|
||
// Getters, setters, and builder... | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/demo-group7/src/main/java/com/group7/demo/dtos/TrainingProgramRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.group7.demo.dtos; | ||
|
||
import com.group7.demo.models.enums.LocationType; | ||
import com.group7.demo.models.enums.ProgramType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class TrainingProgramRequest { | ||
|
||
private String title; | ||
private ProgramType programType; | ||
private LocationType locationType; | ||
private List<ExerciseRequest> exercises; | ||
private String description; | ||
private Long trainerId; // The ID of the trainer creating the program | ||
} |
23 changes: 23 additions & 0 deletions
23
backend/demo-group7/src/main/java/com/group7/demo/dtos/TrainingProgramResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.group7.demo.dtos; | ||
|
||
import com.group7.demo.models.enums.LocationType; | ||
import com.group7.demo.models.enums.ProgramType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class TrainingProgramResponse { | ||
private Long id; | ||
private String title; | ||
private ProgramType programType; | ||
private LocationType locationType; | ||
private List<ExerciseResponse> exercises; | ||
private String description; | ||
private String trainerUsername; | ||
} |
40 changes: 40 additions & 0 deletions
40
backend/demo-group7/src/main/java/com/group7/demo/models/Exercise.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.group7.demo.models; | ||
import com.group7.demo.models.enums.MuscleGroup; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
public class Exercise { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(unique = true) | ||
private String name; // Name of the exercise | ||
|
||
@Enumerated(EnumType.STRING) | ||
private MuscleGroup muscleGroup; // Targeted muscle group | ||
|
||
@OneToOne(mappedBy = "exercise", cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
private ExerciseDetail exerciseDetail; // Link to the sets and repetitions | ||
|
||
@ManyToMany(mappedBy = "exercises", fetch = FetchType.LAZY) | ||
private List<TrainingProgram> trainingPrograms = new ArrayList<>(); | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/demo-group7/src/main/java/com/group7/demo/models/ExerciseDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.group7.demo.models; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
public class ExerciseDetail { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private Integer sets; // Number of sets | ||
|
||
private Integer repetitions; // Number of repetitions per set | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "exercise_id", nullable = false) | ||
private Exercise exercise; // Link to the exercise | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/demo-group7/src/main/java/com/group7/demo/models/TrainingProgram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.group7.demo.models; | ||
|
||
import com.group7.demo.models.enums.LocationType; | ||
import com.group7.demo.models.enums.ProgramType; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
public class TrainingProgram { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String title; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private ProgramType programType; // GROUP or INDIVIDUAL | ||
|
||
@Enumerated(EnumType.STRING) | ||
private LocationType locationType; // HOME, GYM, OUTDOOR | ||
|
||
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) | ||
@JoinTable( | ||
name = "training_program_exercise", // Name of the join table | ||
joinColumns = @JoinColumn(name = "training_program_id"), // Foreign key to TrainingProgram | ||
inverseJoinColumns = @JoinColumn(name = "exercise_id") // Foreign key to Exercise | ||
) private List<Exercise> exercises; // Exercises linked to the training program | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User trainer; | ||
|
||
private String description; // Optional description of the program | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
backend/demo-group7/src/main/java/com/group7/demo/models/enums/LocationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.group7.demo.models.enums; | ||
|
||
public enum LocationType { | ||
HOME, | ||
GYM, | ||
OUTDOOR | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/demo-group7/src/main/java/com/group7/demo/models/enums/MuscleGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.group7.demo.models.enums; | ||
|
||
public enum MuscleGroup { | ||
CHEST, | ||
BACK, | ||
LEGS, | ||
ARMS, | ||
SHOULDERS, | ||
CORE | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/demo-group7/src/main/java/com/group7/demo/models/enums/ProgramType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.group7.demo.models.enums; | ||
|
||
public enum ProgramType { | ||
GROUP, | ||
INDIVIDUAL | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/demo-group7/src/main/java/com/group7/demo/repository/ExerciseRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.group7.demo.repository; | ||
|
||
import com.group7.demo.models.Exercise; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ExerciseRepository extends JpaRepository<Exercise, Long> { | ||
Optional<Exercise> findByName(String name); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
backend/demo-group7/src/main/java/com/group7/demo/repository/TrainingProgramRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.group7.demo.repository; | ||
|
||
import com.group7.demo.models.TrainingProgram; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TrainingProgramRepository extends JpaRepository<TrainingProgram, Long> { | ||
} |
Oops, something went wrong.