Skip to content

Commit

Permalink
Fix custom group dekanat events
Browse files Browse the repository at this point in the history
  • Loading branch information
berejant committed Oct 15, 2023
1 parent d8038f3 commit 4a0e556
Showing 1 changed file with 31 additions and 49 deletions.
80 changes: 31 additions & 49 deletions RealtimeQueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,76 +66,41 @@ func (queue *RealtimeQueue) sendMessage(message *dekanatEvents.Message) {

func (queue *RealtimeQueue) SendLessonCreateEvent(lesson *Lesson) {
event := dekanatEvents.LessonCreateEvent{
CommonEventData: dekanatEvents.CommonEventData{
HasChanges: true,
LessonId: "0",
Semester: strconv.Itoa(lesson.Semester),
},
TypeId: strconv.Itoa(lesson.LessonTypeId),
Date: lesson.LessonDate.Format(dekanatEvents.DekanatFormDateFormat),
TeacherId: strconv.Itoa(lesson.TeachId),
CommonEventData: queue.MakeCommonEventData(lesson),
TypeId: strconv.Itoa(lesson.LessonTypeId),
Date: lesson.LessonDate.Format(dekanatEvents.DekanatFormDateFormat),
TeacherId: strconv.Itoa(lesson.TeachId),
}

if lesson.CustomGroupLessonId != 0 {
event.DisciplineId = "-1"
} else {
event.DisciplineId = strconv.Itoa(lesson.DisciplineId)
}
event.LessonId = "0"

queue.sendMessage(event.ToMessage())
}

func (queue *RealtimeQueue) SendLessonEditEvent(lesson *Lesson) {
event := dekanatEvents.LessonEditEvent{
CommonEventData: dekanatEvents.CommonEventData{
HasChanges: true,
Semester: strconv.Itoa(lesson.Semester),
},
TypeId: strconv.Itoa(lesson.LessonTypeId),
TeacherId: strconv.Itoa(lesson.TeachId),
Date: lesson.LessonDate.Format(dekanatEvents.DekanatFormDateFormat),
}

if lesson.CustomGroupLessonId != 0 {
event.DisciplineId = "-1"
event.LessonId = strconv.Itoa(lesson.CustomGroupLessonId)
} else {
event.DisciplineId = strconv.Itoa(lesson.DisciplineId)
event.LessonId = strconv.Itoa(lesson.LessonId)
CommonEventData: queue.MakeCommonEventData(lesson),
TypeId: strconv.Itoa(lesson.LessonTypeId),
TeacherId: strconv.Itoa(lesson.TeachId),
Date: lesson.LessonDate.Format(dekanatEvents.DekanatFormDateFormat),
}

queue.sendMessage(event.ToMessage())
}

func (queue *RealtimeQueue) SendLessonDeletedEvent(lesson *Lesson) {
event := dekanatEvents.LessonDeletedEvent{
CommonEventData: dekanatEvents.CommonEventData{
HasChanges: true,
LessonId: strconv.Itoa(lesson.LessonId),
DisciplineId: strconv.Itoa(lesson.DisciplineId),
Semester: strconv.Itoa(lesson.Semester),
},
}
if lesson.CustomGroupLessonId != 0 {
event.DisciplineId = "undefined"
event.LessonId = strconv.Itoa(lesson.CustomGroupLessonId)
} else {
event.DisciplineId = strconv.Itoa(lesson.DisciplineId)
event.LessonId = strconv.Itoa(lesson.LessonId)
CommonEventData: queue.MakeCommonEventData(lesson),
}

queue.sendMessage(event.ToMessage())
}

func (queue *RealtimeQueue) SendScoreEditEvent(lesson *Lesson, scores []*Score) {
event := dekanatEvents.ScoreEditEvent{
CommonEventData: dekanatEvents.CommonEventData{
HasChanges: true,
LessonId: strconv.Itoa(lesson.LessonId),
DisciplineId: strconv.Itoa(lesson.DisciplineId),
Semester: strconv.Itoa(lesson.Semester),
},
Date: lesson.LessonDate.Format(dekanatEvents.DekanatFormDateFormat),
Scores: map[int]map[uint8]string{},
CommonEventData: queue.MakeCommonEventData(lesson),
Date: lesson.LessonDate.Format(dekanatEvents.DekanatFormDateFormat),
Scores: map[int]map[uint8]string{},
}

var scoreValue string
Expand All @@ -154,3 +119,20 @@ func (queue *RealtimeQueue) SendScoreEditEvent(lesson *Lesson, scores []*Score)
}
queue.sendMessage(event.ToMessage())
}

func (queue *RealtimeQueue) MakeCommonEventData(lesson *Lesson) dekanatEvents.CommonEventData {
event := dekanatEvents.CommonEventData{
HasChanges: true,
Semester: strconv.Itoa(lesson.Semester),
}

if lesson.CustomGroupLessonId != 0 {
event.DisciplineId = "-1"
event.LessonId = strconv.Itoa(lesson.CustomGroupLessonId)
} else {
event.DisciplineId = strconv.Itoa(lesson.DisciplineId)
event.LessonId = strconv.Itoa(lesson.LessonId)
}

return event
}

0 comments on commit 4a0e556

Please sign in to comment.