ADD: added team management
This commit is contained in:
@@ -16,16 +16,46 @@ func GetTeams(c *gin.Context, db *sql.DB) {
|
||||
teams, err := GetAllTeams(db)
|
||||
if err != nil {
|
||||
log.Printf("Error retrieving teams: %v", err)
|
||||
common.RespondError(c, http.StatusInternalServerError, "Failed to retrieve players")
|
||||
common.RespondError(c, http.StatusInternalServerError, "Failed to retrieve teams")
|
||||
return
|
||||
}
|
||||
|
||||
if len(teams) > 0 {
|
||||
log.Printf("User %s (%s) requested players", c.GetString("userId"), c.GetString("email"))
|
||||
c.JSON(http.StatusOK, teams)
|
||||
return
|
||||
}
|
||||
log.Printf("User %s (%s) requested players, but none found", c.GetString("userId"), c.GetString("email"))
|
||||
c.JSON(http.StatusOK, teams)
|
||||
// if len(teams) > 0 {
|
||||
// return
|
||||
// }
|
||||
|
||||
// common.RespondMessage(c, "No Players found")
|
||||
}
|
||||
|
||||
func CreateTeam(c *gin.Context, db *sql.DB) {
|
||||
var team Team
|
||||
if err := c.ShouldBindJSON(&team); err != nil {
|
||||
common.RespondError(c, http.StatusBadRequest, "Invalid request payload")
|
||||
return
|
||||
}
|
||||
|
||||
err := saveTeam(db, team)
|
||||
if err != nil {
|
||||
log.Printf("Error saving team: %v", err)
|
||||
common.RespondError(c, http.StatusBadRequest, "Error saving Team")
|
||||
}
|
||||
common.RespondSuccess(c, http.StatusOK)
|
||||
}
|
||||
|
||||
func UpdateTeam(c *gin.Context, db *sql.DB) {
|
||||
log.Println("team id: ", c.Param("uuid"))
|
||||
var team Team
|
||||
if err := c.ShouldBindJSON(&team); err != nil {
|
||||
common.RespondError(c, http.StatusBadRequest, "Error updating Team; Could not bind Params")
|
||||
return
|
||||
}
|
||||
team.UUID = c.Param("uuid")
|
||||
err := updateTeam(db, team)
|
||||
if err != nil {
|
||||
log.Printf("Error updating team: %v", err)
|
||||
common.RespondError(c, http.StatusBadRequest, "Error updating Team")
|
||||
}
|
||||
common.RespondSuccess(c, http.StatusOK)
|
||||
|
||||
common.RespondError(c, http.StatusNotFound, "No Players found")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user