Skip to content

Commit

Permalink
feat(stat): check time before writing to db
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphJACK committed Sep 21, 2024
1 parent c1e1dfa commit 4f9891d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion services/stat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package services

import (
"fmt"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -39,10 +40,14 @@ func EndpointStat(ng *gin.Engine) {
err := db.Transaction(func(tx *gorm.DB) error {
for _, v := range form {
for _, t := range v.At {
timeParsed := time.Unix(t, 0)
if timeParsed.After(time.Now().Add(time.Hour)) {
return fmt.Errorf("play time is significantly larger than current time: %v", timeParsed)
}
record := model.PlayRecord{
UserID: user.ID,
Track: v.Track,
At: time.Unix(t, 0),
At: timeParsed,
}
if err := tx.Save(&record).Error; err != nil {
return err
Expand Down

0 comments on commit 4f9891d

Please sign in to comment.