nite07
8702d3e93f
fix: save twitchtoken remove: getSteamID remove: update cmd&api add: getIGDBIDBySteamSearch add: update game info task
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"pcgamedb/db"
|
|
"pcgamedb/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type GetUnorganizedGameItemsRequest struct {
|
|
Num int `json:"num" form:"num"`
|
|
}
|
|
|
|
type GetUnorganizedGameItemsResponse struct {
|
|
Status string `json:"status"`
|
|
Message string `json:"message,omitempty"`
|
|
Size int `json:"size,omitempty"`
|
|
GameItems []*model.GameItem `json:"games,omitempty"`
|
|
}
|
|
|
|
// GetUnorganizedGameItems retrieves a list of unorganized games.
|
|
// @Summary List unorganized games
|
|
// @Description Retrieves games that have not been organized
|
|
// @Tags game
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param num query int false "Number of games to retrieve"
|
|
// @Success 200 {object} GetUnorganizedGameItemsResponse
|
|
// @Failure 400 {object} GetUnorganizedGameItemsResponse
|
|
// @Failure 500 {object} GetUnorganizedGameItemsResponse
|
|
// @Router /game/raw/unorganized [get]
|
|
func GetUnorganizedGameItemsHandler(c *gin.Context) {
|
|
var req GetUnorganizedGameItemsRequest
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, GetUnorganizedGameItemsResponse{
|
|
Status: "error",
|
|
Message: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
if req.Num == 0 || req.Num < 0 {
|
|
req.Num = -1
|
|
}
|
|
gameDownloads, err := db.GetUnorganizedGameItems(req.Num)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, GetUnorganizedGameItemsResponse{
|
|
Status: "error",
|
|
Message: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
if len(gameDownloads) == 0 {
|
|
c.JSON(http.StatusOK, GetUnorganizedGameItemsResponse{
|
|
Status: "ok",
|
|
Message: "No unorganized game downloads found",
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, GetUnorganizedGameItemsResponse{
|
|
Status: "ok",
|
|
GameItems: gameDownloads,
|
|
Size: len(gameDownloads),
|
|
})
|
|
}
|