forgot to put new api docs and fixed a bug with duplicates

This commit is contained in:
2026-02-15 22:00:19 +03:00
parent c357e78003
commit e17569909f
3 changed files with 24 additions and 4 deletions

17
main.go
View File

@@ -9,6 +9,7 @@ import (
"log"
"net/http"
"os"
"slices"
"strconv"
"strings"
"time"
@@ -267,8 +268,20 @@ func main() {
return
}
if tx := db.Create(game); tx.Error != nil {
sendError(w, "failed to create game", err, 400)
if tx := db.First(&model.Game{SteamAppID: game.SteamAppID}); tx.Error != nil {
// game doesn't exist in db, gonna create it real quick
if tx := db.Create(game); tx.Error != nil {
sendError(w, "failed to create game", err, 400)
return
}
}
alreadyHasGame := !slices.ContainsFunc(user.Games, func(g model.Game) bool {
return g.SteamAppID == game.SteamAppID
})
if !alreadyHasGame {
// user already has this game on the wishlist
sendError(w, "game is already on the wishlist", nil, 400)
return
}