-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
92 lines (80 loc) · 3.69 KB
/
Copy pathmain.go
File metadata and controls
92 lines (80 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"hoopspace_api/initializers"
"hoopspace_api/services"
"hoopspace_api/middleware"
"hoopspace_api/controllers"
"fmt"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func init() {
initializers.LoadEnvVariables()
initializers.ConnectDB()
// initializers.ConnectGDB()
}
func main() {
fmt.Println("Running API Server")
r := gin.Default()
go services.CronJob() // creates go routine for the cron job
// Configure CORS
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000", "https://yourdomain.com"}, // Add your frontend domains
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
protected := r.Group("")
protected.Use(middleware.AuthMiddleware())
// Define routes
protected.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "This is home",
})
})
protected.GET("/players", controllers.FetchAllPlayers)
protected.GET("/teams", controllers.FetchAllTeams)
protected.GET("/organizers", controllers.FetchAllOrganizers)
protected.POST("/createUser", controllers.CreateUser)
protected.GET("/getPlayerStat/:id", controllers.FetchPlayerStat)
protected.POST("/sendInvite", controllers.SendInvite)
protected.POST("/acceptInvite", controllers.AcceptInvite)
protected.POST("/declineInvite", controllers.DeclineInvite)
protected.GET("/fetchInvitesTeam/:team_id", controllers.FetchInvitesByTeam)
protected.GET("/fetchInvitesPlayer/:player_id", controllers.FetchInvitesPlayer)
protected.GET("/fetchEvents", controllers.FetchEventList)
protected.POST("/createEvent", controllers.CreateEvent)
protected.POST("/deleteEvent", controllers.DeleteEvent)
protected.POST("/enrollInEvent", controllers.EnrollInEvent)
protected.GET("/validate", controllers.Validate)
protected.GET("/fetchMatchDetailsTeam/:team_id", controllers.FetchMatchDetailsByTeam)
protected.GET("/fetchMatchDetailsPlayer/:player_id", controllers.FetchMatchDetailsByPlayer)
protected.POST("/updateMatchDetails", controllers.UpdateMatchDetails)
protected.GET("/fetchPlayersByTeam/:team_id", controllers.FetchPlayersByTeam)
protected.GET("/fetchTeamMatches/:team_id", controllers.FetchTeamMatches)
protected.GET("/fetchTeamsByPlayer/:player_id", controllers.FetchTeamsByPlayers)
protected.GET("/fetchOrgData/:id", controllers.FetchOrgData)
protected.GET("/fetchEventByOrganizer/:organizer_id", controllers.FetchEventByOrganizer)
protected.GET("/fetchTeamDetails/:id", controllers.FetchTeamDetail)
protected.POST("/deleteInvite", controllers.DeleteInvite)
protected.GET("/fetchInviteByAgent/:agent_id", controllers.FetchInviteByAgent)
protected.GET("/fetchInviteByOrganizer/:organizer_id", controllers.FetchInviteByOrganizer)
protected.GET("/fetchTeamsByEvent/:event_id", controllers.FetchTeamsByEvent)
protected.GET("/fetchPlayerPerformanceByMatch/:match_id", controllers.FetchPlayerPerfByMatch)
protected.GET("/fetchLeagues", controllers.FetchLeagues)
protected.GET("/fetchTeamsByLeague/:league_id", controllers.FetchTeamsByLeague)
protected.POST("/createLeague", controllers.AddLeague)
protected.POST("/fixture/:event_id", controllers.CreatingFixtures)
protected.GET("/fetchAgentDetails/:id", controllers.FetchAgentDetail)
protected.GET("/fetchTeamInvitesByOrg/:team_id", controllers.FetchTeamInviteByOrg)
protected.POST("/setRoster", controllers.SetRoster)
protected.POST("/editProfile", controllers.UpdateUserDetails)
protected.POST("/search", controllers.Search)
r.POST("/login", controllers.Login)
r.POST("/register", controllers.Register)
// Start server
r.Run()
}