From 61070f7a4a107e9d6c318ec1d34cdcef436eab06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Wei=C3=9F?= Date: Thu, 17 Aug 2023 17:25:09 +0200 Subject: [PATCH] event for livetiming get prev and next even if given number does not exist --- service/event_service.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/service/event_service.go b/service/event_service.go index 1b052c5..4151337 100644 --- a/service/event_service.go +++ b/service/event_service.go @@ -94,6 +94,7 @@ func GetEventByMeetingAndNumberForLivetiming(id string, number int) (dto.EventLi var eventLivetiming dto.EventLivetimingDto + found := false for i := 0; i < len(events); i++ { if events[i].Number == number { eventLivetiming.Event = events[i] @@ -103,8 +104,21 @@ func GetEventByMeetingAndNumberForLivetiming(id string, number int) (dto.EventLi if i < len(events)-1 { eventLivetiming.NextEvent = events[i+1] } + found = true break } + if events[i].Number > number { + eventLivetiming.NextEvent = events[i] + if i > 0 { + eventLivetiming.PrevEvent = events[i-1] + } + found = true + break + } + } + + if !found { + eventLivetiming.PrevEvent = events[len(events)-1] } return eventLivetiming, nil