refactor module to topics
This commit is contained in:
parent
a62d9f8643
commit
5f12be32a0
8 changed files with 73 additions and 66 deletions
|
|
@ -9,8 +9,8 @@ import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_p
|
|||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_activity.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_activity_media.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_media.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_module.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_module_location.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_topic.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_topic_location.dart';
|
||||
|
||||
/// Represents a topic in the course planner response.
|
||||
class Topic {
|
||||
|
|
@ -150,8 +150,8 @@ class CoursePlanModel {
|
|||
factory CoursePlanModel.fromCmsDocs(
|
||||
CmsCoursePlan cmsCoursePlan,
|
||||
List<CmsCoursePlanMedia>? cmsCoursePlanMedias,
|
||||
List<CmsCoursePlanModule>? cmsCoursePlanModules,
|
||||
List<CmsCoursePlanModuleLocation>? cmsCoursePlanModuleLocations,
|
||||
List<CmsCoursePlanTopic>? cmsCoursePlanModules,
|
||||
List<CmsCoursePlanTopicLocation>? cmsCoursePlanModuleLocations,
|
||||
List<CmsCoursePlanActivity>? cmsCoursePlanActivities,
|
||||
List<CmsCoursePlanActivityMedia>? cmsCoursePlanActivityMedias,
|
||||
) {
|
||||
|
|
@ -160,10 +160,10 @@ class CoursePlanModel {
|
|||
if (cmsCoursePlanModules != null) {
|
||||
for (final module in cmsCoursePlanModules) {
|
||||
// select locations of current module
|
||||
List<CmsCoursePlanModuleLocation>? moduleLocations;
|
||||
List<CmsCoursePlanTopicLocation>? moduleLocations;
|
||||
if (cmsCoursePlanModuleLocations != null) {
|
||||
for (final location in cmsCoursePlanModuleLocations) {
|
||||
if (location.coursePlanModules.contains(module.id)) {
|
||||
if (location.coursePlanTopics.contains(module.id)) {
|
||||
moduleLocations ??= [];
|
||||
moduleLocations.add(location);
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ class CoursePlanModel {
|
|||
List<CmsCoursePlanActivity>? moduleActivities;
|
||||
if (cmsCoursePlanActivities != null) {
|
||||
for (final activity in cmsCoursePlanActivities) {
|
||||
if (activity.coursePlanModules.contains(module.id)) {
|
||||
if (activity.coursePlanTopics.contains(module.id)) {
|
||||
moduleActivities ??= [];
|
||||
moduleActivities.add(activity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/common/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/course_plans/course_plan_model.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/enums/language_level_type_enum.dart';
|
||||
|
|
@ -8,10 +6,11 @@ import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_p
|
|||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_activity.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_activity_media.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_media.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_module.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_module_location.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_topic.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/models/course_plan/cms_course_plan_topic_location.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/payload_client.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
class CourseFilter {
|
||||
final LanguageModel? targetLanguage;
|
||||
|
|
@ -170,7 +169,7 @@ class CoursePlansRepo {
|
|||
}
|
||||
|
||||
final result = await payload.find(
|
||||
"course-plans",
|
||||
CmsCoursePlan.slug,
|
||||
CmsCoursePlan.fromJson,
|
||||
page: 1,
|
||||
limit: 10,
|
||||
|
|
@ -197,14 +196,14 @@ class CoursePlansRepo {
|
|||
CmsCoursePlan cmsCoursePlan,
|
||||
) async {
|
||||
final medias = await _getMedia(cmsCoursePlan);
|
||||
final modules = await _getModules(cmsCoursePlan);
|
||||
final locations = await _getModuleLocations(modules ?? []);
|
||||
final activities = await _getModuleActivities(modules ?? []);
|
||||
final topics = await _getTopics(cmsCoursePlan);
|
||||
final locations = await _getTopicLocations(topics ?? []);
|
||||
final activities = await _getTopicActivities(topics ?? []);
|
||||
final activityMedias = await _getActivityMedia(activities ?? []);
|
||||
return CoursePlanModel.fromCmsDocs(
|
||||
cmsCoursePlan,
|
||||
medias,
|
||||
modules,
|
||||
topics,
|
||||
locations,
|
||||
activities,
|
||||
activityMedias,
|
||||
|
|
@ -222,7 +221,7 @@ class CoursePlansRepo {
|
|||
};
|
||||
final limit = docs.length;
|
||||
final cmsCoursePlanMediaResult = await payload.find(
|
||||
"course-plan-media",
|
||||
CmsCoursePlanMedia.slug,
|
||||
CmsCoursePlanMedia.fromJson,
|
||||
where: where,
|
||||
limit: limit,
|
||||
|
|
@ -232,34 +231,34 @@ class CoursePlansRepo {
|
|||
return cmsCoursePlanMediaResult.docs;
|
||||
}
|
||||
|
||||
static Future<List<CmsCoursePlanModule>?> _getModules(
|
||||
static Future<List<CmsCoursePlanTopic>?> _getTopics(
|
||||
CmsCoursePlan cmsCoursePlan,
|
||||
) async {
|
||||
final docs = cmsCoursePlan.coursePlanModules?.docs;
|
||||
final docs = cmsCoursePlan.coursePlanTopics?.docs;
|
||||
if (docs == null || docs.isEmpty) return null;
|
||||
|
||||
final where = {
|
||||
"id": {"in": docs.join(",")},
|
||||
};
|
||||
final limit = docs.length;
|
||||
final cmsCourseModulesResult = await payload.find(
|
||||
"course-plan-modules",
|
||||
CmsCoursePlanModule.fromJson,
|
||||
final cmsCourseTopicsResult = await payload.find(
|
||||
CmsCoursePlanTopic.slug,
|
||||
CmsCoursePlanTopic.fromJson,
|
||||
where: where,
|
||||
limit: limit,
|
||||
page: 1,
|
||||
sort: "createdAt",
|
||||
);
|
||||
return cmsCourseModulesResult.docs;
|
||||
return cmsCourseTopicsResult.docs;
|
||||
}
|
||||
|
||||
static Future<List<CmsCoursePlanModuleLocation>?> _getModuleLocations(
|
||||
List<CmsCoursePlanModule> modules,
|
||||
static Future<List<CmsCoursePlanTopicLocation>?> _getTopicLocations(
|
||||
List<CmsCoursePlanTopic> topics,
|
||||
) async {
|
||||
final List<String> locations = [];
|
||||
for (final module in modules) {
|
||||
if (module.coursePlanModuleLocations?.docs != null) {
|
||||
locations.addAll(module.coursePlanModuleLocations!.docs!);
|
||||
for (final top in topics) {
|
||||
if (top.coursePlanTopicLocations?.docs != null) {
|
||||
locations.addAll(top.coursePlanTopicLocations!.docs!);
|
||||
}
|
||||
}
|
||||
if (locations.isEmpty) return null;
|
||||
|
|
@ -268,24 +267,24 @@ class CoursePlansRepo {
|
|||
"id": {"in": locations.join(",")},
|
||||
};
|
||||
final limit = locations.length;
|
||||
final cmsCoursePlanModuleLocationsResult = await payload.find(
|
||||
"course-plan-module-locations",
|
||||
CmsCoursePlanModuleLocation.fromJson,
|
||||
final cmsCoursePlanTopicLocationsResult = await payload.find(
|
||||
CmsCoursePlanTopicLocation.slug,
|
||||
CmsCoursePlanTopicLocation.fromJson,
|
||||
where: where,
|
||||
limit: limit,
|
||||
page: 1,
|
||||
sort: "createdAt",
|
||||
);
|
||||
return cmsCoursePlanModuleLocationsResult.docs;
|
||||
return cmsCoursePlanTopicLocationsResult.docs;
|
||||
}
|
||||
|
||||
static Future<List<CmsCoursePlanActivity>?> _getModuleActivities(
|
||||
List<CmsCoursePlanModule> module,
|
||||
static Future<List<CmsCoursePlanActivity>?> _getTopicActivities(
|
||||
List<CmsCoursePlanTopic> topics,
|
||||
) async {
|
||||
final List<String> activities = [];
|
||||
for (final mod in module) {
|
||||
if (mod.coursePlanActivities?.docs != null) {
|
||||
activities.addAll(mod.coursePlanActivities!.docs!);
|
||||
for (final top in topics) {
|
||||
if (top.coursePlanActivities?.docs != null) {
|
||||
activities.addAll(top.coursePlanActivities!.docs!);
|
||||
}
|
||||
}
|
||||
if (activities.isEmpty) return null;
|
||||
|
|
@ -295,7 +294,7 @@ class CoursePlansRepo {
|
|||
};
|
||||
final limit = activities.length;
|
||||
final cmsCoursePlanActivitiesResult = await payload.find(
|
||||
"course-plan-activities",
|
||||
CmsCoursePlanActivity.slug,
|
||||
CmsCoursePlanActivity.fromJson,
|
||||
where: where,
|
||||
limit: limit,
|
||||
|
|
@ -321,7 +320,7 @@ class CoursePlansRepo {
|
|||
};
|
||||
final limit = mediaIds.length;
|
||||
final cmsCoursePlanActivityMediasResult = await payload.find(
|
||||
"course-plan-activity-medias",
|
||||
CmsCoursePlanActivityMedia.slug,
|
||||
CmsCoursePlanActivityMedia.fromJson,
|
||||
where: where,
|
||||
limit: limit,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'package:fluffychat/pangea/payload_client/polymorphic_relationship.dart';
|
|||
|
||||
/// Represents a course plan from the CMS API
|
||||
class CmsCoursePlan {
|
||||
static const String slug = "course-plans";
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
|
|
@ -10,7 +11,7 @@ class CmsCoursePlan {
|
|||
final String l1; // Language of instruction
|
||||
final String l2; // Target language
|
||||
final JoinField? coursePlanMedia;
|
||||
final JoinField? coursePlanModules;
|
||||
final JoinField? coursePlanTopics;
|
||||
final PolymorphicRelationship? createdBy;
|
||||
final PolymorphicRelationship? updatedBy;
|
||||
final String updatedAt;
|
||||
|
|
@ -24,7 +25,7 @@ class CmsCoursePlan {
|
|||
required this.l1,
|
||||
required this.l2,
|
||||
this.coursePlanMedia,
|
||||
this.coursePlanModules,
|
||||
this.coursePlanTopics,
|
||||
this.createdBy,
|
||||
this.updatedBy,
|
||||
required this.updatedAt,
|
||||
|
|
@ -40,7 +41,7 @@ class CmsCoursePlan {
|
|||
l1: json['l1'],
|
||||
l2: json['l2'],
|
||||
coursePlanMedia: JoinField.fromJson(json['coursePlanMedia']),
|
||||
coursePlanModules: JoinField.fromJson(json['coursePlanModules']),
|
||||
coursePlanTopics: JoinField.fromJson(json['coursePlanTopics']),
|
||||
createdBy: PolymorphicRelationship.fromJson(json['createdBy']),
|
||||
updatedBy: PolymorphicRelationship.fromJson(json['updatedBy']),
|
||||
updatedAt: json['updatedAt'],
|
||||
|
|
@ -57,7 +58,7 @@ class CmsCoursePlan {
|
|||
'l1': l1,
|
||||
'l2': l2,
|
||||
'coursePlanMedia': coursePlanMedia?.toJson(),
|
||||
'coursePlanModules': coursePlanModules?.toJson(),
|
||||
'coursePlanTopics': coursePlanTopics?.toJson(),
|
||||
'createdBy': createdBy?.toJson(),
|
||||
'updatedBy': updatedBy?.toJson(),
|
||||
'updatedAt': updatedAt,
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ class CmsCoursePlanVocab {
|
|||
|
||||
/// Represents a course plan activity from the CMS API
|
||||
class CmsCoursePlanActivity {
|
||||
static const String slug = "course-plan-activities";
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
|
|
@ -77,7 +79,7 @@ class CmsCoursePlanActivity {
|
|||
final List<CmsCoursePlanActivityRole> roles;
|
||||
final List<CmsCoursePlanVocab> vocabs;
|
||||
final JoinField? coursePlanActivityMedia;
|
||||
final List<String> coursePlanModules;
|
||||
final List<String> coursePlanTopics;
|
||||
final PolymorphicRelationship? createdBy;
|
||||
final PolymorphicRelationship? updatedBy;
|
||||
final String updatedAt;
|
||||
|
|
@ -95,7 +97,7 @@ class CmsCoursePlanActivity {
|
|||
required this.roles,
|
||||
required this.vocabs,
|
||||
required this.coursePlanActivityMedia,
|
||||
required this.coursePlanModules,
|
||||
required this.coursePlanTopics,
|
||||
this.createdBy,
|
||||
this.updatedBy,
|
||||
required this.updatedAt,
|
||||
|
|
@ -129,7 +131,7 @@ class CmsCoursePlanActivity {
|
|||
.toList(),
|
||||
coursePlanActivityMedia:
|
||||
JoinField.fromJson(json['coursePlanActivityMedia']),
|
||||
coursePlanModules: List<String>.from(json['coursePlanModules']),
|
||||
coursePlanTopics: List<String>.from(json['coursePlanTopics']),
|
||||
createdBy: json['createdBy'] != null
|
||||
? PolymorphicRelationship.fromJson(json['createdBy'])
|
||||
: null,
|
||||
|
|
@ -154,7 +156,7 @@ class CmsCoursePlanActivity {
|
|||
'roles': roles.map((role) => role.toJson()).toList(),
|
||||
'vocabs': vocabs.map((vocab) => vocab.toJson()).toList(),
|
||||
'coursePlanActivityMedia': coursePlanActivityMedia?.toJson(),
|
||||
'coursePlanModules': coursePlanModules,
|
||||
'coursePlanTopics': coursePlanTopics,
|
||||
'createdBy': createdBy?.toJson(),
|
||||
'updatedBy': updatedBy?.toJson(),
|
||||
'updatedAt': updatedAt,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import 'package:fluffychat/pangea/payload_client/polymorphic_relationship.dart';
|
|||
|
||||
/// Represents course plan activity media from the CMS API
|
||||
class CmsCoursePlanActivityMedia {
|
||||
static const String slug = "course-plan-activity-medias";
|
||||
|
||||
final String id;
|
||||
final String? alt;
|
||||
final List<String> coursePlanActivities;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:fluffychat/pangea/payload_client/polymorphic_relationship.dart';
|
|||
|
||||
/// Represents course plan media from the CMS API
|
||||
class CmsCoursePlanMedia {
|
||||
static const String slug = "course-plan-media";
|
||||
final String id;
|
||||
final String? alt;
|
||||
final List<String> coursePlans;
|
||||
|
|
|
|||
|
|
@ -1,25 +1,26 @@
|
|||
import 'package:fluffychat/pangea/payload_client/join_field.dart';
|
||||
import 'package:fluffychat/pangea/payload_client/polymorphic_relationship.dart';
|
||||
|
||||
/// Represents a course plan module from the CMS API
|
||||
class CmsCoursePlanModule {
|
||||
/// Represents a course plan topic from the CMS API
|
||||
class CmsCoursePlanTopic {
|
||||
static const String slug = "course-plan-topics";
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
final JoinField? coursePlanActivities;
|
||||
final JoinField? coursePlanModuleLocations;
|
||||
final JoinField? coursePlanTopicLocations;
|
||||
final List<String> coursePlans;
|
||||
final PolymorphicRelationship? createdBy;
|
||||
final PolymorphicRelationship? updatedBy;
|
||||
final String updatedAt;
|
||||
final String createdAt;
|
||||
|
||||
CmsCoursePlanModule({
|
||||
CmsCoursePlanTopic({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.coursePlanActivities,
|
||||
required this.coursePlanModuleLocations,
|
||||
required this.coursePlanTopicLocations,
|
||||
required this.coursePlans,
|
||||
this.createdBy,
|
||||
this.updatedBy,
|
||||
|
|
@ -27,16 +28,16 @@ class CmsCoursePlanModule {
|
|||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory CmsCoursePlanModule.fromJson(Map<String, dynamic> json) {
|
||||
return CmsCoursePlanModule(
|
||||
factory CmsCoursePlanTopic.fromJson(Map<String, dynamic> json) {
|
||||
return CmsCoursePlanTopic(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
coursePlanActivities: JoinField.fromJson(
|
||||
json['coursePlanActivities'],
|
||||
),
|
||||
coursePlanModuleLocations: JoinField.fromJson(
|
||||
json['coursePlanModuleLocations'],
|
||||
coursePlanTopicLocations: JoinField.fromJson(
|
||||
json['coursePlanTopicLocations'],
|
||||
),
|
||||
coursePlans: List<String>.from(json['coursePlans']),
|
||||
createdBy: json['createdBy'] != null
|
||||
|
|
@ -56,7 +57,7 @@ class CmsCoursePlanModule {
|
|||
'title': title,
|
||||
'description': description,
|
||||
'coursePlanActivities': coursePlanActivities?.toJson(),
|
||||
'coursePlanModuleLocations': coursePlanModuleLocations?.toJson(),
|
||||
'coursePlanTopicLocations': coursePlanTopicLocations?.toJson(),
|
||||
'coursePlans': coursePlans,
|
||||
'createdBy': createdBy?.toJson(),
|
||||
'updatedBy': updatedBy?.toJson(),
|
||||
|
|
@ -1,36 +1,37 @@
|
|||
import 'package:fluffychat/pangea/payload_client/polymorphic_relationship.dart';
|
||||
|
||||
/// Represents a course plan module location from the CMS API
|
||||
class CmsCoursePlanModuleLocation {
|
||||
/// Represents a course plan topic location from the CMS API
|
||||
class CmsCoursePlanTopicLocation {
|
||||
static const String slug = "course-plan-topic-locations";
|
||||
final String id;
|
||||
final String name;
|
||||
// [longitude, latitude] - minItems: 2, maxItems: 2
|
||||
final List<double>? coordinates;
|
||||
final List<String> coursePlanModules;
|
||||
final List<String> coursePlanTopics;
|
||||
final PolymorphicRelationship? createdBy;
|
||||
final PolymorphicRelationship? updatedBy;
|
||||
final String updatedAt;
|
||||
final String createdAt;
|
||||
|
||||
CmsCoursePlanModuleLocation({
|
||||
CmsCoursePlanTopicLocation({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.coordinates,
|
||||
required this.coursePlanModules,
|
||||
required this.coursePlanTopics,
|
||||
this.createdBy,
|
||||
this.updatedBy,
|
||||
required this.updatedAt,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory CmsCoursePlanModuleLocation.fromJson(Map<String, dynamic> json) {
|
||||
return CmsCoursePlanModuleLocation(
|
||||
factory CmsCoursePlanTopicLocation.fromJson(Map<String, dynamic> json) {
|
||||
return CmsCoursePlanTopicLocation(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
coordinates: (json['coordinates'] as List<dynamic>?)
|
||||
?.map((coord) => (coord as num).toDouble())
|
||||
.toList(),
|
||||
coursePlanModules: List<String>.from(json['coursePlanModules']),
|
||||
coursePlanTopics: List<String>.from(json['coursePlanTopics']),
|
||||
createdBy: json['createdBy'] != null
|
||||
? PolymorphicRelationship.fromJson(json['createdBy'])
|
||||
: null,
|
||||
|
|
@ -47,7 +48,7 @@ class CmsCoursePlanModuleLocation {
|
|||
'id': id,
|
||||
'name': name,
|
||||
'coordinates': coordinates,
|
||||
'coursePlanModules': coursePlanModules,
|
||||
'coursePlanTopics': coursePlanTopics,
|
||||
'createdBy': createdBy?.toJson(),
|
||||
'updatedBy': updatedBy?.toJson(),
|
||||
'updatedAt': updatedAt,
|
||||
Loading…
Add table
Reference in a new issue