@@ -11,6 +11,48 @@ import (
1111 "github.com/rs/zerolog/log"
1212)
1313
14+ func (p * Plexams ) AddExamToSlottime (ctx context.Context , ancode int , time time.Time ) (bool , error ) {
15+ exam , err := p .GetZpaExamByAncode (ctx , ancode )
16+ duration := 90 // good default
17+ if err != nil {
18+ // TODO: maybe external exam?
19+ } else {
20+ // ZPA exam
21+ constraints , err := p .ConstraintForAncode (ctx , ancode )
22+ if err != nil {
23+ log .Error ().Err (err ).Int ("ancode" , ancode ).
24+ Msg ("error while trying to get constraints" )
25+ return false , err
26+ }
27+ if ! constraints .NotPlannedByMe {
28+ err := fmt .Errorf ("add exam to slot time is only allowed for exams not planned by me" )
29+ return false , err
30+ }
31+ duration = exam .Duration
32+ }
33+ if exam == nil {
34+ err = fmt .Errorf ("exam with ancode %d not found" , ancode )
35+ return false , err
36+ }
37+ log .Debug ().Str ("module" , exam .Module ).Str ("main-examer" , exam .MainExamer ).
38+ Msg ("found exam" )
39+ slot , err := p .getSlotForTime (time , duration )
40+ if err != nil {
41+ log .Error ().Err (err ).Time ("slottime" , time ).
42+ Msg ("no slot for slottime found" )
43+ }
44+ log .Debug ().Int ("day" , slot .DayNumber ).Int ("slot" , slot .SlotNumber ).
45+ Msg ("found slot" )
46+
47+ return p .dbClient .AddExamToSlot (ctx , & model.PlanEntry {
48+ DayNumber : slot .DayNumber ,
49+ SlotNumber : slot .SlotNumber ,
50+ ExternalTime : & time ,
51+ Ancode : ancode ,
52+ Locked : false ,
53+ })
54+ }
55+
1456func (p * Plexams ) AddExamToSlot (ctx context.Context , ancode int , dayNumber int , timeNumber int , force bool ) (bool , error ) {
1557 var slot * model.Slot
1658
@@ -325,6 +367,13 @@ func (p *Plexams) PreExamsInSlot(ctx context.Context, day int, time int) ([]*mod
325367
326368 preExams := make ([]* model.PreExam , 0 , len (planEntries ))
327369 for _ , planEntry := range planEntries {
370+
371+ if planEntry .ExternalTime != nil {
372+ fmt .Printf ("External Time = %s\n " , planEntry .ExternalTime .String ())
373+ } else {
374+ fmt .Println ("no external time" )
375+ }
376+
328377 exam , err := p .GetZPAExam (ctx , planEntry .Ancode )
329378 if err != nil {
330379 log .Error ().Err (err ).Int ("ancode" , planEntry .Ancode ).Msg ("cannot get exam" )
0 commit comments