2023-10-28 14:42:29 -04:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2023-10-28 17:50:44 -04:00
|
|
|
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config"
|
|
|
|
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/db"
|
2023-11-03 01:01:33 -04:00
|
|
|
"github.com/gin-contrib/cors"
|
2023-10-28 14:42:29 -04:00
|
|
|
"github.com/gin-gonic/gin"
|
2023-10-28 18:29:57 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2023-10-28 14:42:29 -04:00
|
|
|
)
|
|
|
|
|
2023-10-28 17:50:44 -04:00
|
|
|
var mongo *db.DB
|
|
|
|
var log *logrus.Logger
|
2023-10-28 14:42:29 -04:00
|
|
|
|
|
|
|
func BuildRouter(r *gin.Engine) {
|
2023-10-28 17:50:44 -04:00
|
|
|
conf := config.Config()
|
|
|
|
|
|
|
|
var err error
|
|
|
|
mongo, err = db.NewClient(conf.Mongo.Uri)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-10-28 18:29:57 -04:00
|
|
|
log = logrus.New()
|
|
|
|
log.SetFormatter(&logrus.TextFormatter{
|
2023-11-23 13:22:16 -05:00
|
|
|
DisableColors: true,
|
2023-10-28 18:29:57 -04:00
|
|
|
})
|
2023-11-22 18:47:13 -05:00
|
|
|
log.SetLevel(logrus.DebugLevel)
|
2023-10-28 18:29:57 -04:00
|
|
|
|
2023-11-03 01:01:33 -04:00
|
|
|
r.Use(cors.Default())
|
2023-11-04 23:43:01 -04:00
|
|
|
|
2023-11-24 03:01:38 -05:00
|
|
|
r.Static("/static", "/var/capstone/dist")
|
2023-11-03 01:01:33 -04:00
|
|
|
//mainpage
|
2023-10-29 19:10:32 -04:00
|
|
|
r.GET("/", AuthMiddleware(false), LandingPage)
|
2023-11-03 01:01:33 -04:00
|
|
|
|
|
|
|
//Auth
|
2023-10-28 19:25:51 -04:00
|
|
|
r.GET("/login", AuthMiddleware(false), LoginPage)
|
2023-11-01 22:40:50 -04:00
|
|
|
r.GET("/signup", AuthMiddleware(false), SignUpPage)
|
2023-10-28 17:50:44 -04:00
|
|
|
r.POST("/login", LoginHandler)
|
|
|
|
r.POST("/signup", SignUpHandler)
|
|
|
|
r.POST("/logout", LogoutHandler)
|
2023-10-28 14:42:29 -04:00
|
|
|
|
2023-10-28 17:50:44 -04:00
|
|
|
dashboard := r.Group("/dashboard")
|
2023-10-28 19:25:51 -04:00
|
|
|
dashboard.Use(AuthMiddleware(true))
|
2023-11-03 01:01:33 -04:00
|
|
|
dashboard.GET("", DashboardPage)
|
2023-11-07 22:34:57 -05:00
|
|
|
//Dashboard Actions
|
|
|
|
dashboardActions := dashboard.Group("/action")
|
|
|
|
dashboardActions.POST("/add", AddActionFromForm)
|
2023-11-04 23:43:01 -04:00
|
|
|
//Dashboard Forms
|
|
|
|
dashboardForms := dashboard.Group("/forms")
|
|
|
|
dashboardForms.GET("/addAction", GetAddActionForm)
|
2023-11-23 15:07:57 -05:00
|
|
|
//Dashboard Components
|
|
|
|
dashboardComponents := dashboard.Group("/components")
|
|
|
|
dashboardComponents.GET("/metric_card", GetMetricCard)
|
2023-11-24 02:00:28 -05:00
|
|
|
//Dashboard Events
|
|
|
|
dashboardEvents := dashboard.Group("/events")
|
|
|
|
dashboardEvents.GET("", EventsPage)
|
|
|
|
dashboardEventComponents := dashboardEvents.Group("/components")
|
|
|
|
dashboardEventComponents.GET("/table_data", GetTableComponent)
|
2023-11-03 01:01:33 -04:00
|
|
|
|
|
|
|
//Vendor stuff
|
|
|
|
vendor := r.Group("/vendor")
|
|
|
|
vendor.Use(AuthMiddleware(true))
|
|
|
|
|
|
|
|
youtube := vendor.Group("/youtube")
|
|
|
|
youtube.POST("/initiate", InitiateYoutubeOuath)
|
2023-11-03 20:00:14 -04:00
|
|
|
youtube.GET("/callback", ReceiveYoutubeOauth)
|
2023-11-03 01:01:33 -04:00
|
|
|
|
|
|
|
pco := vendor.Group("/pco")
|
|
|
|
pco.POST("/initiate", InitiatePCOOuath)
|
2023-11-04 18:52:41 -04:00
|
|
|
pco.GET("/callback", RecievePCOOuath)
|
2023-10-28 14:42:29 -04:00
|
|
|
}
|