2023-11-07 22:34:57 -05:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config"
|
|
|
|
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/db"
|
2023-11-16 13:00:28 -05:00
|
|
|
"git.preston-baxter.com/Preston_PLB/capstone/webhook-service/vendors/pco"
|
2023-11-07 22:34:57 -05:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/sirupsen/logrus"
|
2023-11-14 13:48:12 -05:00
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
"google.golang.org/api/youtube/v3"
|
2023-11-07 22:34:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-11-16 20:45:48 -05:00
|
|
|
log *logrus.Logger
|
|
|
|
mongo *db.DB
|
|
|
|
ytClientMap map[primitive.ObjectID]*youtube.Service
|
2023-11-16 13:00:28 -05:00
|
|
|
pcoClientMap map[primitive.ObjectID]*pco.PcoApiClient
|
2023-11-07 22:34:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func BuildRouter(r *gin.Engine) {
|
|
|
|
conf := config.Config()
|
|
|
|
|
|
|
|
log = logrus.New()
|
|
|
|
log.SetFormatter(&logrus.TextFormatter{
|
|
|
|
ForceColors: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
var err error
|
|
|
|
mongo, err = db.NewClient(conf.Mongo.Uri)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-11-14 13:48:12 -05:00
|
|
|
ytClientMap = make(map[primitive.ObjectID]*youtube.Service)
|
2023-11-16 13:00:28 -05:00
|
|
|
pcoClientMap = make(map[primitive.ObjectID]*pco.PcoApiClient)
|
2023-11-14 13:48:12 -05:00
|
|
|
|
2023-11-07 22:34:57 -05:00
|
|
|
pco := r.Group("/pco")
|
|
|
|
pco.Use(ValidatePcoWebhook)
|
|
|
|
pco.POST("/:userid", ConsumePcoWebhook)
|
|
|
|
}
|