@@ -17,6 +17,10 @@ import (
17
17
log "github.com/sirupsen/logrus"
18
18
)
19
19
20
+ // copyCourseInternal creates a deep copy of the given course.
21
+ // It copies phases, metadata, DTO mappings, graphs, and the application form if present.
22
+ // It also creates course-specific Keycloak roles and groups.
23
+ // The function runs within a database transaction.
20
24
func copyCourseInternal (ctx context.Context , sourceCourseID uuid.UUID , courseVariables courseDTO.CopyCourseRequest , requesterID string ) (courseDTO.Course , error ) {
21
25
sourceCourse , err := CourseServiceSingleton .queries .GetCourse (ctx , sourceCourseID )
22
26
if err != nil {
@@ -115,6 +119,8 @@ func copyCourseInternal(ctx context.Context, sourceCourseID uuid.UUID, courseVar
115
119
return courseDTO .GetCourseDTOFromDBModel (createdCourse )
116
120
}
117
121
122
+ // copyCoursePhases duplicates all phases from the source course to the target course.
123
+ // It returns a mapping of old phase IDs to new phase IDs.
118
124
func copyCoursePhases (ctx context.Context , qtx * db.Queries , sourceID , targetID uuid.UUID ) (map [uuid.UUID ]uuid.UUID , error ) {
119
125
sequence , err := qtx .GetCoursePhaseSequence (ctx , sourceID )
120
126
if err != nil {
@@ -161,6 +167,8 @@ func copyCoursePhases(ctx context.Context, qtx *db.Queries, sourceID, targetID u
161
167
return mapping , nil
162
168
}
163
169
170
+ // copyCoursePhaseGraph replicates the course phase dependency graph from the source course
171
+ // to the target course using the provided phase ID mapping.
164
172
func copyCoursePhaseGraph (ctx context.Context , qtx * db.Queries , sourceID , targetID uuid.UUID , phaseMap map [uuid.UUID ]uuid.UUID ) error {
165
173
graph , err := qtx .GetCoursePhaseGraph (ctx , sourceID )
166
174
if err != nil {
@@ -182,6 +190,8 @@ func copyCoursePhaseGraph(ctx context.Context, qtx *db.Queries, sourceID, target
182
190
return nil
183
191
}
184
192
193
+ // setInitialPhase sets the initial course phase in the target course by mapping
194
+ // the initial phase from the source course via the provided phase ID mapping.
185
195
func setInitialPhase (ctx context.Context , qtx * db.Queries , sourceID , targetID uuid.UUID , phaseMap map [uuid.UUID ]uuid.UUID ) error {
186
196
sequence , err := qtx .GetCoursePhaseSequence (ctx , sourceID )
187
197
if err != nil {
@@ -201,6 +211,8 @@ func setInitialPhase(ctx context.Context, qtx *db.Queries, sourceID, targetID uu
201
211
return nil
202
212
}
203
213
214
+ // copyDTOs collects all participation DTOs (inputs and outputs) used by the source course phases.
215
+ // It returns a map from source DTO IDs to themselves, to support mapping-based operations.
204
216
func copyDTOs (ctx context.Context , qtx * db.Queries , sourceID uuid.UUID ) (map [uuid.UUID ]uuid.UUID , error ) {
205
217
unordered , err := qtx .GetNotOrderedCoursePhases (ctx , sourceID )
206
218
if err != nil {
@@ -244,6 +256,8 @@ func copyDTOs(ctx context.Context, qtx *db.Queries, sourceID uuid.UUID) (map[uui
244
256
return dtoIDMap , nil
245
257
}
246
258
259
+ // copyMetaGraphs recreates the phase and participation data graphs for the target course
260
+ // using the given mappings for phases and DTOs.
247
261
func copyMetaGraphs (ctx context.Context , qtx * db.Queries , sourceID , targetID uuid.UUID , phaseMap , dtoMap map [uuid.UUID ]uuid.UUID ) error {
248
262
// Phase Data Graph
249
263
phaseGraph , err := qtx .GetPhaseDataGraph (ctx , sourceID )
@@ -295,6 +309,8 @@ func copyMetaGraphs(ctx context.Context, qtx *db.Queries, sourceID, targetID uui
295
309
return updateParticipationDataGraphHelper (ctx , qtx , targetID , converted )
296
310
}
297
311
312
+ // copyApplicationForm copies the application form—including all questions—from
313
+ // the source course phase to the target course phase.
298
314
func copyApplicationForm (ctx context.Context , qtx * db.Queries , sourceCoursePhaseID , targetCoursePhaseID uuid.UUID ) error {
299
315
applicationForm , err := getApplicationFormHelper (ctx , qtx , sourceCoursePhaseID )
300
316
if err != nil {
@@ -352,6 +368,8 @@ func copyApplicationForm(ctx context.Context, qtx *db.Queries, sourceCoursePhase
352
368
return nil
353
369
}
354
370
371
+ // updateParticipationDataGraphHelper deletes and recreates all participation data graph connections
372
+ // for the given course using the provided metadata graph items.
355
373
func updateParticipationDataGraphHelper (ctx context.Context , qtx * db.Queries , courseID uuid.UUID , graphUpdate []courseDTO.MetaDataGraphItem ) error {
356
374
// delete all previous connections
357
375
err := qtx .DeleteParticipationDataGraphConnections (ctx , courseID )
@@ -376,6 +394,8 @@ func updateParticipationDataGraphHelper(ctx context.Context, qtx *db.Queries, co
376
394
377
395
}
378
396
397
+ // getApplicationPhaseID returns the ID of the application phase for the given course.
398
+ // If no application phase exists, it returns uuid.Nil and pgx.ErrNoRows.
379
399
func getApplicationPhaseID (ctx context.Context , qtx * db.Queries , courseID uuid.UUID ) (uuid.UUID , error ) {
380
400
applicationPhaseID , err := qtx .GetApplicationPhaseIDForCourse (ctx , courseID )
381
401
if err != nil {
@@ -384,6 +404,8 @@ func getApplicationPhaseID(ctx context.Context, qtx *db.Queries, courseID uuid.U
384
404
return applicationPhaseID , nil
385
405
}
386
406
407
+ // updatePhaseDataGraphHelper deletes and recreates all phase data graph connections
408
+ // for the given course using the provided metadata graph items.
387
409
func updatePhaseDataGraphHelper (ctx context.Context , qtx * db.Queries , courseID uuid.UUID , graphUpdate []courseDTO.MetaDataGraphItem ) error {
388
410
// delete all previous connections
389
411
err := qtx .DeletePhaseDataGraphConnections (ctx , courseID )
@@ -408,6 +430,8 @@ func updatePhaseDataGraphHelper(ctx context.Context, qtx *db.Queries, courseID u
408
430
409
431
}
410
432
433
+ // updateApplicationFormHelper applies updates to a course phase's application form.
434
+ // It handles creation, deletion, and updating of text and multi-select questions.
411
435
func updateApplicationFormHelper (ctx context.Context , qtx * db.Queries , coursePhaseId uuid.UUID , form applicationDTO.UpdateForm ) error {
412
436
// Check if course phase is application phase
413
437
isApplicationPhase , err := qtx .CheckIfCoursePhaseIsApplicationPhase (ctx , coursePhaseId )
@@ -486,6 +510,8 @@ func updateApplicationFormHelper(ctx context.Context, qtx *db.Queries, coursePha
486
510
return nil
487
511
}
488
512
513
+ // getApplicationFormHelper retrieves the application form for the given course phase,
514
+ // including all associated questions. Returns an error if the phase is not an application phase.
489
515
func getApplicationFormHelper (ctx context.Context , qtx * db.Queries , coursePhaseID uuid.UUID ) (applicationDTO.Form , error ) {
490
516
ctxWithTimeout , cancel := db .GetTimeoutContext (ctx )
491
517
defer cancel ()
0 commit comments