course-service 0.2.0

Course Service — a course-administration microservice modelled on schema.org/Course; interoperates with the course-matcher crate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
//! SeaORM entity modules.
//!
//! One module per table from `migrations/`. JSONB columns are typed as
//! `serde_json::Value` and rehydrated to typed collections by the
//! repository.

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

// ───────────────────────── providers ─────────────────────────

/// Entity for the `providers` table (course-authoring organisations).
pub mod providers {
    use super::*;

    /// A row in the `providers` table; maps to
    /// [`Provider`](crate::models::organization::Provider).
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "providers")]
    pub struct Model {
        /// Provider UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// Canonical name.
        pub name: String,
        /// Alternate names (JSONB array).
        pub alternate_names: Json,
        /// Website URL.
        pub url: Option<String>,
        /// External authority URLs (JSONB array).
        pub same_as: Json,
        /// Provider kind, stored as a string.
        pub kind: Option<String>,
        /// Row creation timestamp.
        pub created_at: DateTimeUtc,
        /// Row last-update timestamp.
        pub updated_at: DateTimeUtc,
        /// Soft-delete timestamp, if deleted.
        pub deleted_at: Option<DateTimeUtc>,
    }

    /// Foreign-key relations from `providers`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {
        /// One provider authors many courses.
        #[sea_orm(has_many = "super::courses::Entity")]
        Courses,
    }

    impl Related<super::courses::Entity> for Entity {
        fn to() -> RelationDef { Relation::Courses.def() }
    }

    impl ActiveModelBehavior for ActiveModel {}
}

// ───────────────────────── courses ─────────────────────────

/// Entity for the `courses` table — the schema.org/Course template row.
pub mod courses {
    use super::*;

    /// A row in the `courses` table; maps to
    /// [`Course`](crate::models::course::Course). Collection fields are
    /// JSONB; enum fields are stored as JSONB or bare strings.
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "courses")]
    pub struct Model {
        /// Course UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// Course name.
        pub name: String,
        /// Alternate names (JSONB array).
        pub alternate_names: Json,
        /// Long description.
        pub description: Option<String>,
        /// Disambiguating one-liner.
        pub disambiguating_description: Option<String>,
        /// Canonical course URL.
        pub url: Option<String>,
        /// Image URLs (JSONB array).
        pub image: Json,
        /// External authority URLs (JSONB array).
        pub same_as: Json,
        /// Keyword tags (JSONB array).
        pub keywords: Json,
        /// schema.org/additionalType.
        pub additional_type: Option<String>,
        /// schema.org/about subjects (JSONB array).
        pub about: Json,
        /// Target audience.
        pub audience: Option<String>,
        /// Languages of instruction (JSONB array).
        pub in_language: Json,
        /// License URL/text.
        pub license: Option<String>,
        /// Typical learner age range.
        pub typical_age_range: Option<String>,
        /// ISO 8601 duration.
        pub time_required: Option<String>,
        /// Version label.
        pub version: Option<String>,
        /// Whether the course is free to access.
        pub is_accessible_for_free: Option<bool>,
        /// Competencies taught (JSONB array).
        pub teaches: Json,
        /// Competencies assessed (JSONB array).
        pub assesses: Json,
        /// Required prior competencies (JSONB array).
        pub competency_required: Json,
        /// Educational level enum (JSONB).
        pub educational_level: Option<Json>,
        /// schema.org/educationalUse.
        pub educational_use: Option<String>,
        /// Learning-resource-type enum (JSONB).
        pub learning_resource_type: Option<Json>,
        /// Interactivity-type enum (bare string).
        pub interactivity_type: Option<String>,
        /// Provider catalog code.
        pub course_code: Option<String>,
        /// Credit count (stored as `i32`).
        pub number_of_credits: Option<i32>,
        /// Prerequisite descriptions (JSONB array).
        pub course_prerequisites: Json,
        /// Available languages (JSONB array).
        pub available_language: Json,
        /// Financial-aid eligibility notes (JSONB array).
        pub financial_aid_eligible: Json,
        /// Educational credential awarded (JSONB).
        pub educational_credential_awarded: Option<Json>,
        /// Occupational credential awarded (JSONB).
        pub occupational_credential_awarded: Option<Json>,
        /// Historical enrollment count (stored as `i64`).
        pub total_historical_enrollment: Option<i64>,
        /// Lifecycle status (bare string).
        pub status: String,
        /// Active flag.
        pub active: bool,
        /// FK to the owning provider.
        pub provider_id: Option<Uuid>,
        /// Row creation timestamp.
        pub created_at: DateTimeUtc,
        /// Row last-update timestamp.
        pub updated_at: DateTimeUtc,
        /// Soft-delete timestamp, if deleted.
        pub deleted_at: Option<DateTimeUtc>,
    }

    /// Foreign-key relations from `courses`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {
        /// Child identifier rows.
        #[sea_orm(has_many = "super::course_identifiers::Entity")]
        CourseIdentifiers,
        /// Child instance rows.
        #[sea_orm(has_many = "super::course_instances::Entity")]
        CourseInstances,
        /// Child syllabus-section rows.
        #[sea_orm(has_many = "super::syllabus_sections::Entity")]
        SyllabusSections,
        /// Owning provider.
        #[sea_orm(
            belongs_to = "super::providers::Entity",
            from = "Column::ProviderId",
            to = "super::providers::Column::Id"
        )]
        Provider,
    }

    impl Related<super::course_identifiers::Entity> for Entity {
        fn to() -> RelationDef { Relation::CourseIdentifiers.def() }
    }
    impl Related<super::course_instances::Entity> for Entity {
        fn to() -> RelationDef { Relation::CourseInstances.def() }
    }
    impl Related<super::syllabus_sections::Entity> for Entity {
        fn to() -> RelationDef { Relation::SyllabusSections.def() }
    }
    impl Related<super::providers::Entity> for Entity {
        fn to() -> RelationDef { Relation::Provider.def() }
    }

    impl ActiveModelBehavior for ActiveModel {}
}

// ───────────────────── course_identifiers ─────────────────────

/// Entity for the `course_identifiers` table (external identifiers).
pub mod course_identifiers {
    use super::*;

    /// A row in `course_identifiers`; maps to
    /// [`CourseIdentifier`](crate::models::identifier::CourseIdentifier).
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "course_identifiers")]
    pub struct Model {
        /// Identifier-row UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// FK to the owning course.
        pub course_id: Uuid,
        /// Identifier scheme enum (JSONB).
        pub property_id: Json,
        /// Scheme-specific value.
        pub value: String,
        /// Optional label.
        pub name: Option<String>,
        /// Optional authority URL.
        pub url: Option<String>,
        /// Row creation timestamp.
        pub created_at: DateTimeUtc,
    }

    /// Foreign-key relations from `course_identifiers`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {
        /// Owning course.
        #[sea_orm(
            belongs_to = "super::courses::Entity",
            from = "Column::CourseId",
            to = "super::courses::Column::Id"
        )]
        Course,
    }

    impl Related<super::courses::Entity> for Entity {
        fn to() -> RelationDef { Relation::Course.def() }
    }

    impl ActiveModelBehavior for ActiveModel {}
}

// ───────────────────────── course_links ─────────────────────────

/// Entity for the `course_links` table (typed course-to-course links).
pub mod course_links {
    use super::*;

    /// A row in `course_links`; maps to
    /// [`CourseLink`](crate::models::course::CourseLink).
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "course_links")]
    pub struct Model {
        /// Link-row UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// FK to the source course.
        pub course_id: Uuid,
        /// FK to the linked course.
        pub other_course_id: Uuid,
        /// Link type (bare string).
        pub link_type: String,
        /// Row creation timestamp.
        pub created_at: DateTimeUtc,
    }

    /// Foreign-key relations from `course_links`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {
        /// Source course.
        #[sea_orm(
            belongs_to = "super::courses::Entity",
            from = "Column::CourseId",
            to = "super::courses::Column::Id"
        )]
        Course,
    }

    impl Related<super::courses::Entity> for Entity {
        fn to() -> RelationDef { Relation::Course.def() }
    }

    impl ActiveModelBehavior for ActiveModel {}
}

// ─────────────────────── course_instances ───────────────────────

/// Entity for the `course_instances` table (specific offerings).
pub mod course_instances {
    use super::*;

    /// A row in `course_instances`; maps to
    /// [`CourseInstance`](crate::models::course_instance::CourseInstance).
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "course_instances")]
    pub struct Model {
        /// Instance UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// FK to the parent course.
        pub course_id: Uuid,
        /// Instance name.
        pub name: Option<String>,
        /// Delivery mode enum (bare string).
        pub course_mode: Option<String>,
        /// Lifecycle status (bare string).
        pub status: String,
        /// Languages for this offering (JSONB array).
        pub in_language: Json,
        /// Free-text location.
        pub location: Option<String>,
        /// External place-service location reference.
        pub location_id: Option<Uuid>,
        /// Instructor person-service ids (JSONB array).
        pub instructor_ids: Json,
        /// Free-text instructor names (JSONB array).
        pub instructor_names: Json,
        /// Maximum capacity (stored as `i32`).
        pub maximum_attendee_capacity: Option<i32>,
        /// Current enrollment (stored as `i32`).
        pub enrolled_count: Option<i32>,
        /// Enrollment window open time.
        pub enrollment_opens: Option<DateTimeUtc>,
        /// Enrollment window close time.
        pub enrollment_closes: Option<DateTimeUtc>,
        /// Schedule struct (JSONB).
        pub schedule: Option<Json>,
        /// Row creation timestamp.
        pub created_at: DateTimeUtc,
        /// Row last-update timestamp.
        pub updated_at: DateTimeUtc,
        /// Soft-delete timestamp, if deleted.
        pub deleted_at: Option<DateTimeUtc>,
    }

    /// Foreign-key relations from `course_instances`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {
        /// Parent course.
        #[sea_orm(
            belongs_to = "super::courses::Entity",
            from = "Column::CourseId",
            to = "super::courses::Column::Id"
        )]
        Course,
    }

    impl Related<super::courses::Entity> for Entity {
        fn to() -> RelationDef { Relation::Course.def() }
    }

    impl ActiveModelBehavior for ActiveModel {}
}

// ─────────────────────── syllabus_sections ───────────────────────

/// Entity for the `syllabus_sections` table (course-outline tree).
pub mod syllabus_sections {
    use super::*;

    /// A row in `syllabus_sections`; maps to
    /// [`Syllabus`](crate::models::syllabus::Syllabus). `parent_id`
    /// makes the table a self-referential tree.
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "syllabus_sections")]
    pub struct Model {
        /// Section UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// FK to the owning course.
        pub course_id: Uuid,
        /// FK to the parent section, if nested.
        pub parent_id: Option<Uuid>,
        /// Section heading.
        pub name: String,
        /// Section description.
        pub description: Option<String>,
        /// Ordering position (stored as `i32`).
        pub position: Option<i32>,
        /// Competencies covered (JSONB array).
        pub teaches: Json,
        /// ISO 8601 duration.
        pub time_required: Option<String>,
        /// Resource URLs (JSONB array).
        pub resources: Json,
        /// Row creation timestamp.
        pub created_at: DateTimeUtc,
    }

    /// Foreign-key relations from `syllabus_sections`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {
        /// Owning course.
        #[sea_orm(
            belongs_to = "super::courses::Entity",
            from = "Column::CourseId",
            to = "super::courses::Column::Id"
        )]
        Course,
    }

    impl Related<super::courses::Entity> for Entity {
        fn to() -> RelationDef { Relation::Course.def() }
    }

    impl ActiveModelBehavior for ActiveModel {}
}

// ───────────────────────── audit_log ─────────────────────────

/// Entity for the `audit_log` table (HIPAA-style change trail).
pub mod audit_log {
    use super::*;

    /// A row in `audit_log`; projected to
    /// [`AuditEntry`](crate::db::audit::AuditEntry) for the API.
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "audit_log")]
    pub struct Model {
        /// Audit-row UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// Affected entity kind.
        pub entity_type: String,
        /// Affected entity id.
        pub entity_id: Uuid,
        /// `CREATE` / `UPDATE` / `DELETE`.
        pub action: String,
        /// Acting user id.
        pub user_id: Option<String>,
        /// Originating IP address.
        pub user_ip_address: Option<String>,
        /// Originating user-agent.
        pub user_agent: Option<String>,
        /// Pre-change snapshot (JSONB).
        pub old_values: Option<Json>,
        /// Post-change snapshot (JSONB).
        pub new_values: Option<Json>,
        /// When the action occurred.
        pub created_at: DateTimeUtc,
    }

    /// No outbound relations from `audit_log`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}

    impl ActiveModelBehavior for ActiveModel {}
}

// ─────────────────── course_match_scores ───────────────────

/// Entity for the `course_match_scores` table (review-queue rows).
pub mod course_match_scores {
    use super::*;

    /// A row in `course_match_scores`; backs
    /// [`ReviewQueueItem`](crate::models::review_queue::ReviewQueueItem).
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "course_match_scores")]
    pub struct Model {
        /// Score-row UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// First course in the candidate pair.
        pub course_id: Uuid,
        /// Second (candidate) course in the pair.
        pub candidate_id: Uuid,
        /// Overall match score.
        pub match_score: f64,
        /// Confidence band label.
        pub match_quality: String,
        /// How the pair was detected.
        pub detection_method: String,
        /// Per-component breakdown (JSONB).
        pub score_breakdown: Option<Json>,
        /// Review status (bare string).
        pub status: String,
        /// Reviewer id, once reviewed.
        pub reviewed_by: Option<String>,
        /// Row creation timestamp.
        pub created_at: DateTimeUtc,
        /// Review timestamp, if reviewed.
        pub reviewed_at: Option<DateTimeUtc>,
    }

    /// No outbound relations from `course_match_scores`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}

    impl ActiveModelBehavior for ActiveModel {}
}

// ─────────────────── course_merge_records ───────────────────

/// Entity for the `course_merge_records` table (merge audit rows).
pub mod course_merge_records {
    use super::*;

    /// A row in `course_merge_records`; maps to
    /// [`MergeRecord`](crate::models::merge::MergeRecord).
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "course_merge_records")]
    pub struct Model {
        /// Merge-record UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// Surviving course id.
        pub main_course_id: Uuid,
        /// Folded-in (soft-deleted) course id.
        pub duplicate_course_id: Uuid,
        /// Merge lifecycle status (bare string).
        pub status: String,
        /// Actor that performed the merge.
        pub merged_by: Option<String>,
        /// Free-text merge reason.
        pub merge_reason: Option<String>,
        /// Motivating match score.
        pub match_score: Option<f64>,
        /// Snapshot of transferred data (JSONB).
        pub transferred_data: Option<Json>,
        /// When the merge occurred.
        pub merged_at: DateTimeUtc,
    }

    /// No outbound relations from `course_merge_records`.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}

    impl ActiveModelBehavior for ActiveModel {}
}