Skip to content

Commit

Permalink
Merge pull request #41 from rarimo/fix/daily_questions_delete
Browse files Browse the repository at this point in the history
Fix/daily questions delete
  • Loading branch information
Zaptoss authored Oct 15, 2024
2 parents 74a46e4 + 0928ab1 commit c28d062
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 c28d062

Please sign in to comment.