From 7af345e4a4b946daec0773c83a1c1568b197cfc1 Mon Sep 17 00:00:00 2001 From: Zaptoss Date: Fri, 6 Sep 2024 15:28:40 +0300 Subject: [PATCH 1/2] Fix question creating and delete --- internal/service/handlers/daily_question_create.go | 6 ++++-- internal/service/handlers/daily_question_delete.go | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/service/handlers/daily_question_create.go b/internal/service/handlers/daily_question_create.go index 657a8b8..ff4d30f 100644 --- a/internal/service/handlers/daily_question_create.go +++ b/internal/service/handlers/daily_question_create.go @@ -47,8 +47,10 @@ func CreateDailyQuestion(w http.ResponseWriter, r *http.Request) { })...) return } - nowTime := time.Now().UTC() - if !timeReq.After(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, DailyQuestions(r).Location)) { + // We use current time in Georgia + nowTime := time.Now().In(location) + // we check that timeReq (start time of daily question in Georgia) is before than start time of current day in Georgia + if timeReq.Before(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, location)) { Log(r).Errorf("Arg start_at must be more or equal tomorow midnoght noe: %s", timeReq.String()) ape.RenderErr(w, problems.BadRequest(validation.Errors{ "starts_at": fmt.Errorf("argument start_at must be more or equal tomorow midnoght now its: %s", timeReq.String()), diff --git a/internal/service/handlers/daily_question_delete.go b/internal/service/handlers/daily_question_delete.go index fbc308c..812732e 100644 --- a/internal/service/handlers/daily_question_delete.go +++ b/internal/service/handlers/daily_question_delete.go @@ -45,8 +45,11 @@ func DeleteDailyQuestion(w http.ResponseWriter, r *http.Request) { deletedQuestion := *question timeReq := question.StartsAt - nowTime := time.Now().UTC() - if !timeReq.After(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day()+1, 0, 0, 0, 0, DailyQuestions(r).Location)) { + location := DailyQuestions(r).Location + // We use current time in Georgia + nowTime := time.Now().In(location) + // we check that timeReq (start time of daily question in Georgia) is before than start time of current day in Georgia + if timeReq.Before(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, location)) { Log(r).Errorf("Only questions that start tomorrow or later can be delete: %s", timeReq.String()) ape.RenderErr(w, problems.BadRequest(err)...) return From e6012d3aaad0f1882d826111bf86c7a57a8c2a7e Mon Sep 17 00:00:00 2001 From: Zaptoss Date: Fri, 6 Sep 2024 15:41:10 +0300 Subject: [PATCH 2/2] Fix create --- internal/service/handlers/daily_question_create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/handlers/daily_question_create.go b/internal/service/handlers/daily_question_create.go index ff4d30f..893ec86 100644 --- a/internal/service/handlers/daily_question_create.go +++ b/internal/service/handlers/daily_question_create.go @@ -58,7 +58,7 @@ func CreateDailyQuestion(w http.ResponseWriter, r *http.Request) { return } - question, err := DailyQuestionsQ(r).FilterDayQuestions(timeReq).Get() + question, err := DailyQuestionsQ(r).FilterDayQuestions(timeReq.UTC()).Get() if err != nil { Log(r).WithError(err).Error("Error on this day") ape.RenderErr(w, problems.InternalError())