mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
go lint
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/nprasad2077/NBA_Go/models"
|
||||
"github.com/nprasad2077/NBA_Go/services"
|
||||
"gorm.io/gorm"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/nprasad2077/NBA_Go/models"
|
||||
"github.com/nprasad2077/NBA_Go/services"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// FetchPlayerShotChartAPI godoc
|
||||
@@ -32,7 +32,9 @@ import (
|
||||
// ScrapePlayerShotChart godoc
|
||||
// @Summary Scrape a player's shot-chart from BR website
|
||||
// @Description Scrapes seasons [startSeason…endSeason] for the given playerId
|
||||
// (playerName is auto-detected).
|
||||
//
|
||||
// (playerName is auto-detected).
|
||||
//
|
||||
// @Tags PlayerShotChart
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -43,25 +45,25 @@ import (
|
||||
// @Failure 400,500 {object} map[string]string
|
||||
// @Router /api/playershotchart/scrape [get]
|
||||
func ScrapePlayerShotChart(db *gorm.DB) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
pid := c.Query("playerId")
|
||||
start := c.QueryInt("startSeason", 0)
|
||||
end := c.QueryInt("endSeason", 0)
|
||||
if pid == "" || start == 0 || end == 0 {
|
||||
return c.Status(400).JSON(fiber.Map{
|
||||
"error": "playerId, startSeason and endSeason are required",
|
||||
})
|
||||
}
|
||||
if start < end {
|
||||
return c.Status(400).JSON(fiber.Map{
|
||||
"error": "startSeason must be >= endSeason",
|
||||
})
|
||||
}
|
||||
if err := services.FetchAndStoreShotChartScrapedForPlayer(db, pid, start, end); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"message": "Shot chart scraped and saved for " + pid})
|
||||
}
|
||||
return func(c *fiber.Ctx) error {
|
||||
pid := c.Query("playerId")
|
||||
start := c.QueryInt("startSeason", 0)
|
||||
end := c.QueryInt("endSeason", 0)
|
||||
if pid == "" || start == 0 || end == 0 {
|
||||
return c.Status(400).JSON(fiber.Map{
|
||||
"error": "playerId, startSeason and endSeason are required",
|
||||
})
|
||||
}
|
||||
if start < end {
|
||||
return c.Status(400).JSON(fiber.Map{
|
||||
"error": "startSeason must be >= endSeason",
|
||||
})
|
||||
}
|
||||
if err := services.FetchAndStoreShotChartScrapedForPlayer(db, pid, start, end); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"message": "Shot chart scraped and saved for " + pid})
|
||||
}
|
||||
}
|
||||
|
||||
// GetPlayerShotChart godoc
|
||||
@@ -77,21 +79,21 @@ func ScrapePlayerShotChart(db *gorm.DB) fiber.Handler {
|
||||
// @Failure 500 {object} map[string]string
|
||||
// @Router /api/playershotchart [get]
|
||||
func GetPlayerShotChart(db *gorm.DB) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
var shots []models.PlayerShotChart
|
||||
return func(c *fiber.Ctx) error {
|
||||
var shots []models.PlayerShotChart
|
||||
|
||||
query := db.Model(&models.PlayerShotChart{})
|
||||
query := db.Model(&models.PlayerShotChart{})
|
||||
|
||||
if pid := c.Query("playerId"); pid != "" {
|
||||
query = query.Where("player_id = ?", pid)
|
||||
}
|
||||
if s := c.QueryInt("season", 0); s != 0 {
|
||||
query = query.Where("season = ?", s)
|
||||
}
|
||||
if pid := c.Query("playerId"); pid != "" {
|
||||
query = query.Where("player_id = ?", pid)
|
||||
}
|
||||
if s := c.QueryInt("season", 0); s != 0 {
|
||||
query = query.Where("season = ?", s)
|
||||
}
|
||||
|
||||
if err := query.Find(&shots).Error; err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(shots)
|
||||
}
|
||||
}
|
||||
if err := query.Find(&shots).Error; err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(shots)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user