This commit is contained in:
2025-04-05 18:45:17 +11:00
parent 35c27b28a3
commit 7f5a09098a
72 changed files with 56 additions and 3351 deletions

View File

@@ -2,7 +2,6 @@ package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
@@ -25,80 +24,3 @@ func (g *Client) GetPlatforms(query string) ([]*pb.Platform, error) {
}
return data.Platforms, nil
}
func (g *Client) GetPlatformByID(id uint64) (*pb.Platform, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
platforms, err := g.GetPlatforms(query)
if err != nil {
return nil, err
}
return platforms[0], nil
}
func (g *Client) GetPlatformsByIDs(ids []uint64) ([]*pb.Platform, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatforms(idStr)
}
func (g *Client) GetPlatformsByPlatformFamilyID(id uint64) ([]*pb.Platform, error) {
query := fmt.Sprintf(`where platform_family = %d; fields *;`, id)
return g.GetPlatforms(query)
}
func (g *Client) GetPlatformsByPlatformFamilyIDs(ids []uint64) ([]*pb.Platform, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where platform_family = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatforms(idStr)
}
func (g *Client) GetPlatformsByPlatformLogoID(id uint64) ([]*pb.Platform, error) {
query := fmt.Sprintf(`where platform_logo = %d; fields *;`, id)
return g.GetPlatforms(query)
}
func (g *Client) GetPlatformsByPlatformLogoIDs(ids []uint64) ([]*pb.Platform, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where platform_logo = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatforms(idStr)
}
func (g *Client) GetPlatformsByPlatformTypeID(id uint64) ([]*pb.Platform, error) {
query := fmt.Sprintf(`where platform_type = %d; fields *;`, id)
return g.GetPlatforms(query)
}
func (g *Client) GetPlatformsByPlatformTypeIDs(ids []uint64) ([]*pb.Platform, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where platform_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatforms(idStr)
}
func (g *Client) GetPlatformsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platforms, err := g.GetPlatforms(query)
if err != nil {
return 0, err
}
return int(platforms[0].Id), nil
}