2023-10-28 17:50:44 -04:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2023-10-29 19:10:32 -04:00
|
|
|
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/db/models"
|
2023-10-28 17:50:44 -04:00
|
|
|
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/templates"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func LandingPage(c *gin.Context) {
|
2023-10-29 19:10:32 -04:00
|
|
|
if raw, exists := c.Get(USER_OBJ_KEY); exists {
|
|
|
|
if user, ok := raw.(*models.User); ok {
|
|
|
|
renderTempl(c, templates.LandingPage(user))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
renderTempl(c, templates.LandingPage(nil))
|
2023-10-28 17:50:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoginPage(c *gin.Context) {
|
|
|
|
renderTempl(c, templates.LoginPage(""))
|
|
|
|
}
|
|
|
|
|
|
|
|
func SignUpPage(c *gin.Context) {
|
|
|
|
renderTempl(c, templates.SignupPage(""))
|
|
|
|
}
|
|
|
|
|
|
|
|
func DashboardPage(c *gin.Context) {
|
2023-10-29 21:20:59 -04:00
|
|
|
if raw, exists := c.Get(USER_OBJ_KEY); exists {
|
|
|
|
if user, ok := raw.(*models.User); ok {
|
2023-11-02 19:23:07 -04:00
|
|
|
//get vendors
|
|
|
|
vendors, err := mongo.FindVendorAccountByUser(user.MongoId())
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Failed to get vendors for user: %s", user.Email)
|
|
|
|
c.AbortWithStatus(502)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTempl(c, templates.DashboardPage(user, vendors))
|
2023-10-29 21:20:59 -04:00
|
|
|
return
|
2023-11-02 19:23:07 -04:00
|
|
|
} else {
|
|
|
|
c.AbortWithStatus(502)
|
2023-10-29 21:20:59 -04:00
|
|
|
}
|
|
|
|
}
|
2023-10-28 17:50:44 -04:00
|
|
|
}
|