From 65697ff1fc3f6562082c707b693300cb7721c98b Mon Sep 17 00:00:00 2001 From: Zaptoss Date: Thu, 10 Oct 2024 18:24:44 +0300 Subject: [PATCH] Add question deadlines clearing --- .../service/handlers/daily_question_delete.go | 4 ++++ internal/service/handlers/daily_question_get.go | 15 --------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/internal/service/handlers/daily_question_delete.go b/internal/service/handlers/daily_question_delete.go index 812732e..c65ec19 100644 --- a/internal/service/handlers/daily_question_delete.go +++ b/internal/service/handlers/daily_question_delete.go @@ -55,6 +55,10 @@ func DeleteDailyQuestion(w http.ResponseWriter, r *http.Request) { return } + if !timeReq.After(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, location).Add(time.Hour * 24)) { + DailyQuestions(r).ClearDeadlines() + } + _, err = DailyQuestionsQ(r).New().FilterByID(ID).Delete() if err != nil { Log(r).WithError(err).Error("Error deleting daily question") diff --git a/internal/service/handlers/daily_question_get.go b/internal/service/handlers/daily_question_get.go index 4de5fa7..fc1220f 100644 --- a/internal/service/handlers/daily_question_get.go +++ b/internal/service/handlers/daily_question_get.go @@ -9,7 +9,6 @@ import ( "github.com/go-chi/chi" "github.com/rarimo/geo-auth-svc/pkg/auth" "github.com/rarimo/geo-points-svc/internal/data" - "github.com/rarimo/geo-points-svc/internal/data/evtypes/models" "github.com/rarimo/geo-points-svc/resources" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" @@ -47,20 +46,6 @@ func GetDailyQuestion(w http.ResponseWriter, r *http.Request) { localDayStart := atDayStart(dq.LocalTime(time.Now().UTC())) - ev, err := EventsQ(r).FilterByNullifier(nullifier).FilterByType(models.TypeDailyQuestion).GetLast() - if err != nil { - log.WithError(err).Error("Failed to get last daily_question event") - ape.RenderErr(w, problems.InternalError()) - return - } - if ev != nil && - ev.CreatedAt > int32(localDayStart.Unix()) && - ev.CreatedAt < int32(localDayStart.Add(24*time.Hour).Unix()) { - log.Debug("Points already accruing for daily question") - ape.RenderErr(w, problems.Conflict()) - return - } - question, err := DailyQuestionsQ(r).FilterByStartsAtAfter(localDayStart).Get() if err != nil { log.WithError(err).Error("Failed to get question")