forgot to put new api docs and fixed a bug with duplicates
This commit is contained in:
@@ -6,10 +6,17 @@ meta {
|
|||||||
|
|
||||||
post {
|
post {
|
||||||
url: {{base_url}}/api/user/games
|
url: {{base_url}}/api/user/games
|
||||||
body: none
|
body: json
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"steamAppId": 105600
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
settings {
|
settings {
|
||||||
encodeUrl: true
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
}
|
}
|
||||||
|
|||||||
17
main.go
17
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -267,8 +268,20 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if tx := db.Create(game); tx.Error != nil {
|
if tx := db.First(&model.Game{SteamAppID: game.SteamAppID}); tx.Error != nil {
|
||||||
sendError(w, "failed to create game", err, 400)
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ type Game struct {
|
|||||||
Model
|
Model
|
||||||
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
SteamAppID int `json:"steamAppId"`
|
SteamAppID int `json:"steamAppId" gorm:"unique"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
ReleaseDate string `json:"releaseDate"`
|
ReleaseDate string `json:"releaseDate"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user