Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export workout collections #1013

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}