diff --git a/internal/app/handlers/auth_handler.go b/internal/app/handlers/auth_handler.go index b4b536b..6b28357 100644 --- a/internal/app/handlers/auth_handler.go +++ b/internal/app/handlers/auth_handler.go @@ -57,7 +57,9 @@ func GoogleCallback(ctx *gin.Context) { // Logout removes the token from the user's browser. Effectively "logging them out." Routes that // require authentication will require the user to sign back in before accessing them again. +// This route will direct the user back to the home page. func Logout(ctx *gin.Context) { // TODO: Use same values as the GoogleCallback function ctx.SetCookie("jwt_token", "", -1, "/", "localhost", false, true) + ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME) } diff --git a/internal/app/handlers/page_handler.go b/internal/app/handlers/page_handler.go index 7f3c12c..71368e0 100644 --- a/internal/app/handlers/page_handler.go +++ b/internal/app/handlers/page_handler.go @@ -40,7 +40,7 @@ func CreatePage(ctx *gin.Context) { func ProfilePage(ctx *gin.Context) { // If not logged in, direct to the login page if !domain.IsLoggedIn(ctx) { - ctx.Redirect(http.StatusSeeOther, "/v1/web/login") + ctx.Redirect(http.StatusSeeOther, domain.WEB_LOGIN) return } diff --git a/internal/app/server/server.go b/internal/app/server/server.go index 291bc4c..7f3e608 100644 --- a/internal/app/server/server.go +++ b/internal/app/server/server.go @@ -58,8 +58,10 @@ func (s *Server) ConfigureAuth() *Server { panic("Could not load env file") } + redirect_domain := os.Getenv("DOMAIN") + var ( - redirectUrl string = "http://localhost:3000/v1/api/auth/callback" + redirectUrl string = fmt.Sprintf("%s%s", redirect_domain, domain.API_AUTH_CALLBACK) clientId string = os.Getenv("GOOGLE_CLIENT_ID") clientSecret string = os.Getenv("GOOGLE_CLIENT_SECRET") scope []string = []string{ @@ -124,14 +126,14 @@ func (s *Server) Setup() *Server { s.Router.Use(JwtAuthMiddleWare(jwtSecret)) // Redirect index to home page: Update this as needed - s.Router.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, "/v1/web/home") }) + s.Router.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME) }) // Wrap all routes with a version - router_v1 := s.Router.Group("/v1") + router_v1 := s.Router.Group(domain.VERSION) // Domain specific routers - router_web := router_v1.Group("/web") - router_api := router_v1.Group("/api") + router_web := router_v1.Group(domain.WEB) + router_api := router_v1.Group(domain.API) // Static routes router_web.Static("/static", "./web/static") @@ -151,8 +153,8 @@ func (s *Server) Setup() *Server { }) // WEB router endpoints + router_web.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME) }) router_web.GET("/login", handlers.LoginPage) - router_web.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, "/v1/web/home") }) router_web.GET("/home", handlers.HomePage) router_web.GET("/favorites", handlers.FavoritesPage) router_web.GET("/create", handlers.CreatePage) diff --git a/internal/domain/recipe/recipe.go b/internal/domain/recipe/recipe.go deleted file mode 100644 index e69de29..0000000 diff --git a/internal/domain/recipe/repository.go b/internal/domain/recipe/repository.go deleted file mode 100644 index e69de29..0000000 diff --git a/internal/domain/recipe/service.go b/internal/domain/recipe/service.go deleted file mode 100644 index e69de29..0000000 diff --git a/internal/domain/server/routes.go b/internal/domain/server/routes.go new file mode 100644 index 0000000..48c96a6 --- /dev/null +++ b/internal/domain/server/routes.go @@ -0,0 +1,20 @@ +package domain + +// Sub-routes +const VERSION = "/v1" +const WEB = "/web" +const API = "/api" + +// Web prefixed routes +const WEB_LOGIN = VERSION + WEB + "/login" +const WEB_INDEX = VERSION + WEB +const WEB_HOME = VERSION + WEB + "/home" +const WEB_FAVORITES = VERSION + WEB + "/favorites" +const WEB_CREATE = VERSION + WEB + "/create" +const WEB_PROFIlE = VERSION + WEB + "/profile" +const WEB_LIST = VERSION + WEB + "/list" + +// API prefixed routes +const API_AUTH_LOGIN = VERSION + API + "/auth/login" +const API_AUTH_CALLBACK = VERSION + API + "/auth/callback" +const API_AUTH_LOGOUT = VERSION + API + "/auth/logout" diff --git a/internal/templates/components/navbar.templ b/internal/templates/components/navbar.templ index b1560a5..ac23cc1 100644 --- a/internal/templates/components/navbar.templ +++ b/internal/templates/components/navbar.templ @@ -1,6 +1,7 @@ package components import "strings" +import "github.com/haydenhargreaves/Potion/internal/domain/server" templ hamburgerMenu() { } @@ -67,11 +68,11 @@ templ Navbar(current string) {

Potion

+ } templ searchSection() { -
- @components.BannerText("Craving Something Specific?") -
- @searchBar() - @components.FilterDropdown() -
-
+
+ @components.BannerText("Craving Something Specific?") +
+ @searchBar() + @components.FilterDropdown() +
+
} templ highlightSection(liked bool) { -
- @components.BannerText("Recipe of the Week!") -

- Our 'Recipe of the Week' is the cream of the crop! We handpick it by looking at what recipes - our community loves most. This isn't just about how many people view a recipe; it's also about - how many times it's been made, liked, reviewed, and its average rating, all combined to find - the true fan favorite of the week. It's our way of highlighting the best recipes that truly - resonate with our users! -

-
- @components.RecipeCardLarge(false) -
-
+
+ @components.BannerText("Recipe of the Week!") +

+ Our 'Recipe of the Week' is the cream of the crop! We handpick it by looking at what recipes + our community loves most. This isn't just about how many people view a recipe; it's also about + how many times it's been made, liked, reviewed, and its average rating, all combined to find + the true fan favorite of the week. It's our way of highlighting the best recipes that truly + resonate with our users! +

+
+ @components.RecipeCardLarge(false) +
+
} templ listsSection() { -
- @components.BannerText("Take Another Look.") -
-

Recently viewed

-
- @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) - @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) - @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) - @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) - @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) - @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) -
-

Make again

-
- @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) - @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) - @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) - @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) - @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) - @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) -
-
-
+
+ @components.BannerText("Take Another Look.") +
+

Recently viewed

+
+ @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) + @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) + @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) + @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) + @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) + @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) +
+

Make again

+
+ @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) + @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) + @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) + @components.RecipeCardSmall("Avocado Toast", "Breakfast - 15 min", "Hayden Hargreaves", true) + @components.RecipeCardSmall("Fried Chicken", "Dinner - 120 min", "Hayden Hargreaves", false) + @components.RecipeCardSmall("Classic Butter Chicken", "Dinner - 60 min", "Hayden Hargreaves", false) +
+
+
} templ ctaSection() { -
-

- Unleash Your Inner Chef! -

-

- Have a unique recipe idea? Want to share your culinary masterpiece with the world? - It's time to bring your creations to life! -

- +

+ Unleash Your Inner Chef! +

+

+ Have a unique recipe idea? Want to share your culinary masterpiece with the world? + It's time to bring your creations to life! +

+
- Create Your Recipe! - -
+ text-lg md:text-2xl font-bold uppercase tracking-wide" + > + Create Your Recipe! + + } templ HomePage() { -@components.Navbar("home") -
-
- @introSection() - @searchSection() - @highlightSection(false) - @listsSection() - @ctaSection() -
-
+ @components.Navbar("home") +
+
+ @introSection() + @searchSection() + @highlightSection(false) + @listsSection() + @ctaSection() +
+
} diff --git a/internal/templates/pages/home_templ.go b/internal/templates/pages/home_templ.go index 6dd1a3e..fc5fac4 100644 --- a/internal/templates/pages/home_templ.go +++ b/internal/templates/pages/home_templ.go @@ -9,6 +9,7 @@ import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" import "github.com/haydenhargreaves/Potion/internal/templates/components" +import "github.com/haydenhargreaves/Potion/internal/domain/server" func introSection() templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { @@ -313,7 +314,20 @@ func ctaSection() templ.Component { templ_7745c5c3_Var7 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "

Unleash Your Inner Chef!

Have a unique recipe idea? Want to share your culinary masterpiece with the world? It's time to bring your creations to life!

Create Your Recipe!
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "

Unleash Your Inner Chef!

Have a unique recipe idea? Want to share your culinary masterpiece with the world? It's time to bring your creations to life!

Create Your Recipe!
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -337,16 +351,16 @@ func HomePage() templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var8 := templ.GetChildren(ctx) - if templ_7745c5c3_Var8 == nil { - templ_7745c5c3_Var8 = templ.NopComponent + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = components.Navbar("home").Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -370,7 +384,7 @@ func HomePage() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/templates/pages/login.templ b/internal/templates/pages/login.templ index 45b028a..dd9cb45 100644 --- a/internal/templates/pages/login.templ +++ b/internal/templates/pages/login.templ @@ -1,5 +1,7 @@ package templates +import "github.com/haydenhargreaves/Potion/internal/domain/server" + templ LoginPage() {
@@ -15,7 +17,7 @@ templ LoginPage() {
diff --git a/internal/templates/pages/login_templ.go b/internal/templates/pages/login_templ.go index 177e261..3c5be60 100644 --- a/internal/templates/pages/login_templ.go +++ b/internal/templates/pages/login_templ.go @@ -8,6 +8,8 @@ package templates import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" +import "github.com/haydenhargreaves/Potion/internal/domain/server" + func LoginPage() templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context @@ -29,7 +31,20 @@ func LoginPage() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "

Sign in to Continue

You need to sign in to continue. Don't have an account? Signing in will create one for you!

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/templates/pages/profile.templ b/internal/templates/pages/profile.templ index 0902f75..2480b9b 100644 --- a/internal/templates/pages/profile.templ +++ b/internal/templates/pages/profile.templ @@ -1,37 +1,43 @@ package templates import "github.com/haydenhargreaves/Potion/internal/templates/components" -import "github.com/haydenhargreaves/Potion/internal/domain/user" +import domain "github.com/haydenhargreaves/Potion/internal/domain/server" +import domain_user"github.com/haydenhargreaves/Potion/internal/domain/user" -templ userDetailsSection(user domain.User) { -
-
- -
-

{ user.Name }

-

{ user.Email }

-
-
-
+templ userDetailsSection(user domain_user.User) { +
+
+ +
+

{ user.Name }

+

{ user.Email }

+
+
+
} templ logoutSection() { -
- -
+
+ + Logout + +
} -templ ProfilePage(user domain.User) { -@components.Navbar(" profile") -
-
- @userDetailsSection(user) - @logoutSection() -
-
+templ ProfilePage(user domain_user.User) { + @components.Navbar(" profile") +
+
+ @userDetailsSection(user) + @logoutSection() +
+
} diff --git a/internal/templates/pages/profile_templ.go b/internal/templates/pages/profile_templ.go index 361d9cc..8d9a680 100644 --- a/internal/templates/pages/profile_templ.go +++ b/internal/templates/pages/profile_templ.go @@ -9,9 +9,10 @@ import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" import "github.com/haydenhargreaves/Potion/internal/templates/components" -import "github.com/haydenhargreaves/Potion/internal/domain/user" +import domain "github.com/haydenhargreaves/Potion/internal/domain/server" +import domain_user "github.com/haydenhargreaves/Potion/internal/domain/user" -func userDetailsSection(user domain.User) templ.Component { +func userDetailsSection(user domain_user.User) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -37,10 +38,9 @@ func userDetailsSection(user domain.User) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var2 string - templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs( - user.ImageUrl) + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(user.ImageUrl) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/profile.templ`, Line: 10, Col: 19} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/profile.templ`, Line: 12, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -53,7 +53,7 @@ func userDetailsSection(user domain.User) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(user.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/profile.templ`, Line: 12, Col: 63} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/profile.templ`, Line: 15, Col: 61} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -66,7 +66,7 @@ func userDetailsSection(user domain.User) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(user.Email) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/profile.templ`, Line: 13, Col: 48} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/profile.templ`, Line: 16, Col: 46} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -101,7 +101,20 @@ func logoutSection() templ.Component { templ_7745c5c3_Var5 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "
Logout
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -109,7 +122,7 @@ func logoutSection() templ.Component { }) } -func ProfilePage(user domain.User) templ.Component { +func ProfilePage(user domain_user.User) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -125,16 +138,16 @@ func ProfilePage(user domain.User) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var6 := templ.GetChildren(ctx) - if templ_7745c5c3_Var6 == nil { - templ_7745c5c3_Var6 = templ.NopComponent + templ_7745c5c3_Var7 := templ.GetChildren(ctx) + if templ_7745c5c3_Var7 == nil { + templ_7745c5c3_Var7 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = components.Navbar(" profile").Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -146,7 +159,7 @@ func ProfilePage(user domain.User) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }