def create(self, request_model: 'ExerciseInputSchema') -> Dict: exercise = ExerciseModel() exercise.id = request_model.exercise_id or str(uuid4()) exercise.name = request_model.name exercise.description = request_model.description exercise.video_url = request_model.video_url exercise.files = [] for f in request_model.files: exercise_file = ExerciseFileModel() exercise_file.id = f.exercise_id or str(uuid4()) exercise_file.exercise_id = exercise.id exercise_file.file_id = f.file_id exercise.files.append(exercise_file) with master_async_session() as session: session.add(exercise) output = ExerciseOutputSchema() output.exercise_id = exercise.id output.name = exercise.name output.description = exercise.description output.video_url = exercise.video_url output.files = [] for file in exercise.files: output_file = ExerciseFileOutputSchema() output_file.id = file.id output_file.exercise_id = file.exercise_id output_file.file_id = file.file_id output.files.append(output_file) output.validate() return output.to_primitive()
def update(self, request_model: 'EquipmentInputSchema', equipment_id=None): goal = EquipmentModel() goal.id = equipment_id goal.description = request_model.description with master_async_session() as session: session.merge(goal) output = EquipmentOutputSchema() output.equipment_id = goal.id output.description = goal.description output.validate() return output.to_primitive()
def create(self, request_model: 'EquipmentInputSchema') -> Dict: goal = EquipmentModel() goal.id = request_model.equipment_id or str(uuid4()) goal.description = request_model.description with master_async_session() as session: session.add(goal) output = EquipmentOutputSchema() output.equipment_id = goal.id output.description = goal.description output.validate() return output.to_primitive()
def create(self, request_model: 'MuscleGroupInputSchema') -> Dict: muscle_group = MuscleGroupModel() muscle_group.id = request_model.muscle_group_id or str(uuid4()) muscle_group.name = request_model.name with master_async_session() as session: session.add(muscle_group) output = MuscleGroupOutputSchema() output.muscle_group_id = muscle_group.id output.name = muscle_group.name output.validate() return output.to_primitive()
def update(self, request_model: 'MuscleGroupInputSchema', muscle_group_id=None): muscle_group = MuscleGroupModel() muscle_group.id = muscle_group_id muscle_group.name = request_model.name with master_async_session() as session: session.merge(muscle_group) output = MuscleGroupOutputSchema() output.muscle_group_id = muscle_group.id output.name = muscle_group.name output.validate() return output.to_primitive()
def update(self, request_model: 'ExerciseInputSchema', exercise_id=None): exercise = ExerciseModel() exercise.id = exercise_id exercise.name = request_model.name exercise.description = request_model.description exercise.video_url = request_model.video_url with master_async_session() as session: session.merge(exercise) output = ExerciseOutputSchema() output.exercise_id = exercise.id output.name = exercise.name output.description = exercise.description output.video_url = exercise.video_url output.files = [] for file in exercise.files: output_file = ExerciseFileOutputSchema() output_file.id = file.id output_file.exercise_id = file.exercise_id output_file.file_id = file.file_id output.files.append(output_file) output.validate() return output.to_primitive()
def destroy(self, exercise_id): with master_async_session() as session: session.query(ExerciseModel).filter_by(id=exercise_id).delete() return None
def destroy(self, equipment_id): with master_async_session() as session: session.query(EquipmentModel).filter_by(id=equipment_id).delete() return None
def destroy(self, muscle_group_id): with master_async_session() as session: session.query(MuscleGroupModel).filter_by( id=muscle_group_id).delete() return None