Skip to content

Commit

Permalink
Merge pull request #38 from rarimo/fix/admin-endpoints
Browse files Browse the repository at this point in the history
Fix/admin endpoints
Zaptoss authored Sep 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 4a5046e + e6012d3 commit b8a2e0d
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions internal/service/handlers/daily_question_create.go
Original file line number Diff line number Diff line change
@@ -47,16 +47,18 @@ 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()),
})...)
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())
7 changes: 5 additions & 2 deletions internal/service/handlers/daily_question_delete.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b8a2e0d

Please sign in to comment.