Skip to content

Commit b8a2e0d

Browse files
authored
Merge pull request #38 from rarimo/fix/admin-endpoints
Fix/admin endpoints
2 parents 4a5046e + e6012d3 commit b8a2e0d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

internal/service/handlers/daily_question_create.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ func CreateDailyQuestion(w http.ResponseWriter, r *http.Request) {
4747
})...)
4848
return
4949
}
50-
nowTime := time.Now().UTC()
51-
if !timeReq.After(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, DailyQuestions(r).Location)) {
50+
// We use current time in Georgia
51+
nowTime := time.Now().In(location)
52+
// we check that timeReq (start time of daily question in Georgia) is before than start time of current day in Georgia
53+
if timeReq.Before(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, location)) {
5254
Log(r).Errorf("Arg start_at must be more or equal tomorow midnoght noe: %s", timeReq.String())
5355
ape.RenderErr(w, problems.BadRequest(validation.Errors{
5456
"starts_at": fmt.Errorf("argument start_at must be more or equal tomorow midnoght now its: %s", timeReq.String()),
5557
})...)
5658
return
5759
}
5860

59-
question, err := DailyQuestionsQ(r).FilterDayQuestions(timeReq).Get()
61+
question, err := DailyQuestionsQ(r).FilterDayQuestions(timeReq.UTC()).Get()
6062
if err != nil {
6163
Log(r).WithError(err).Error("Error on this day")
6264
ape.RenderErr(w, problems.InternalError())

internal/service/handlers/daily_question_delete.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ func DeleteDailyQuestion(w http.ResponseWriter, r *http.Request) {
4545
deletedQuestion := *question
4646

4747
timeReq := question.StartsAt
48-
nowTime := time.Now().UTC()
49-
if !timeReq.After(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day()+1, 0, 0, 0, 0, DailyQuestions(r).Location)) {
48+
location := DailyQuestions(r).Location
49+
// We use current time in Georgia
50+
nowTime := time.Now().In(location)
51+
// we check that timeReq (start time of daily question in Georgia) is before than start time of current day in Georgia
52+
if timeReq.Before(time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, location)) {
5053
Log(r).Errorf("Only questions that start tomorrow or later can be delete: %s", timeReq.String())
5154
ape.RenderErr(w, problems.BadRequest(err)...)
5255
return

0 commit comments

Comments
 (0)