Skip to content

Commit

Permalink
Add question deadlines clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaptoss committed Oct 10, 2024
1 parent 74a46e4 commit 65697ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
4 changes: 4 additions & 0 deletions internal/service/handlers/daily_question_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 0 additions & 15 deletions internal/service/handlers/daily_question_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 65697ff

Please sign in to comment.