ADD: added database connection for players data handling and started login funtion with database
This commit is contained in:
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"volleyball/internal/auth"
|
||||
"volleyball/internal/database"
|
||||
"volleyball/internal/player"
|
||||
"volleyball/internal/tournament"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
@@ -10,6 +12,19 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var host = "localhost"
|
||||
var DBport = 5432
|
||||
var user = "volleyball"
|
||||
|
||||
db := database.New(host, DBport, user, "volleyball", "volleyball")
|
||||
db.Connect()
|
||||
|
||||
// Setup the database and tables
|
||||
if err := db.SetupTables(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
// CORS
|
||||
@@ -21,7 +36,10 @@ func main() {
|
||||
}))
|
||||
|
||||
// Public
|
||||
r.POST("/api/login", auth.LoginHandler)
|
||||
r.POST("/api/login", func(c *gin.Context) {
|
||||
auth.LoginHandler(c, db.GetDB())
|
||||
})
|
||||
|
||||
r.GET("/api/tournaments", tournament.ListTournaments)
|
||||
|
||||
// Protected API
|
||||
@@ -32,6 +50,19 @@ func main() {
|
||||
api.POST("/tournaments/:id/join", tournament.JoinTournament)
|
||||
api.PUT("/tournaments/:id", tournament.UpdateTournament)
|
||||
|
||||
api.GET("/players", func(c *gin.Context) {
|
||||
player.GetPlayers(c, db.GetDB())
|
||||
})
|
||||
api.POST("/players", func(c *gin.Context) {
|
||||
player.CreatePlayer(c, db.GetDB())
|
||||
})
|
||||
api.PUT("/players/:id", func(c *gin.Context) {
|
||||
player.UpdatePlayer(c, db.GetDB())
|
||||
})
|
||||
api.DELETE("/players/:id", func(c *gin.Context) {
|
||||
player.DeletePlayer(c, db.GetDB())
|
||||
})
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
|
||||
Reference in New Issue
Block a user