Skip to content

Commit

Permalink
Fix question creating and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaptoss committed Sep 6, 2024
1 parent 4a5046e commit 7af345e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/service/handlers/daily_question_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
7 changes: 5 additions & 2 deletions internal/service/handlers/daily_question_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7af345e

Please sign in to comment.