Skip to content

Commit

Permalink
Export workout collections (#1013)
Browse files Browse the repository at this point in the history
* feat(models): change export structure of workouts

* feat(exporter): correct structure for workouts
  • Loading branch information
IgnisDa committed Sep 7, 2024
1 parent cd44a98 commit fba6764
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/models/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_graphql::{Enum, InputObject, SimpleObject};
use enum_meta::{meta, Meta};
use enums::EntityLot;
use schematic::Schematic;
use schematic::{ConfigEnum, Schematic};
use sea_orm::{prelude::DateTimeUtc, FromJsonQueryResult};
use serde::{Deserialize, Serialize};
use strum::{Display, EnumIter};
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Default for StoredUrl {
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Enum)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Enum, ConfigEnum)]
pub enum CollectionExtraInformationLot {
String,
Number,
Expand All @@ -65,6 +65,7 @@ pub enum CollectionExtraInformationLot {
SimpleObject,
FromJsonQueryResult,
InputObject,
Schematic,
)]
#[graphql(input_name = "CollectionExtraInformationInput")]
pub struct CollectionExtraInformation {
Expand Down
5 changes: 4 additions & 1 deletion crates/models/database/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use async_graphql::SimpleObject;
use async_trait::async_trait;
use common_models::CollectionExtraInformation;
use nanoid::nanoid;
use schematic::Schematic;
use sea_orm::entity::prelude::*;
use sea_orm::ActiveValue;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, SimpleObject)]
#[derive(
Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, SimpleObject, Schematic,
)]
#[sea_orm(table_name = "collection")]
#[graphql(name = "Collection")]
pub struct Model {
Expand Down
13 changes: 12 additions & 1 deletion crates/models/dependent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ pub struct SearchResults<T: OutputType> {
pub items: Vec<T>,
}

/// Details about a specific exercise item that needs to be exported.
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Schematic)]
#[serde(rename_all = "snake_case")]
pub struct ImportOrExportWorkoutItem {
/// The details of the workout.
pub details: workout::Model,
/// The collections this entity was added to.
pub collections: Vec<String>,
}

/// Complete export of the user.
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Schematic)]
Expand All @@ -54,7 +65,7 @@ pub struct CompleteExport {
/// Data about user's measurements.
pub measurements: Option<Vec<user_measurement::Model>>,
/// Data about user's workouts.
pub workouts: Option<Vec<workout::Model>>,
pub workouts: Option<Vec<ImportOrExportWorkoutItem>>,
/// Data about user's media groups.
pub media_group: Option<Vec<media_models::ImportOrExportMediaGroupItem>>,
/// Data about user's exercises.
Expand Down
1 change: 1 addition & 0 deletions crates/services/exporter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ common-models = { path = "../../models/common" }
common-utils = { path = "../../utils/common" }
database-models = { path = "../../models/database" }
database-utils = { path = "../../utils/database" }
dependent-models = { path = "../../models/dependent" }
enums = { path = "../../enums" }
file-storage-service = { path = "../file-storage" }
fitness-models = { path = "../../models/fitness" }
Expand Down
7 changes: 6 additions & 1 deletion crates/services/exporter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use database_models::{
use database_utils::{
entity_in_collections, item_reviews, user_measurements_list, workout_details,
};
use dependent_models::ImportOrExportWorkoutItem;
use enums::EntityLot;
use file_storage_service::FileStorageService;
use fitness_models::UserMeasurementsListInput;
Expand Down Expand Up @@ -348,7 +349,11 @@ impl ExporterService {
for workout_id in workout_ids {
let details =
workout_details(&self.db, &self.file_storage_service, user_id, workout_id).await?;
writer.serialize_value(&details).unwrap();
let exp = ImportOrExportWorkoutItem {
details: details.details,
collections: details.collections.into_iter().map(|c| c.name).collect(),
};
writer.serialize_value(&exp).unwrap();
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/services/importer/src/generic_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn import(
.workouts
.unwrap_or_default()
.into_iter()
.map(|w| exercises_service.db_workout_to_workout_input(w))
.map(|w| exercises_service.db_workout_to_workout_input(w.details))
.collect_vec();

Ok(ImportResult {
Expand Down
10 changes: 9 additions & 1 deletion docs/includes/export-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ export interface Workout {
summary: WorkoutSummary;
}

/** Details about a specific exercise item that needs to be exported. */
export interface ImportOrExportWorkoutItem {
/** The collections this entity was added to. */
collections: string[];
/** The details of the workout. */
details: Workout;
}

/** Complete export of the user. */
export interface CompleteExport {
/** Data about user's exercises. */
Expand All @@ -329,5 +337,5 @@ export interface CompleteExport {
/** Data about user's people. */
people: ImportOrExportPersonItem[] | null;
/** Data about user's workouts. */
workouts: Workout[] | null;
workouts: ImportOrExportWorkoutItem[] | null;
}

0 comments on commit fba6764

Please sign in to comment.