(CHORE): Removed the handlers directory, they were old
This commit is contained in:
parent
34b0cc4199
commit
7df879b04a
@ -1,47 +0,0 @@
|
||||
package handlers
|
||||
|
||||
// GoogleLogin directs the user to Googles select user login page. Once the user has selected an
|
||||
// account, they will be directed to the GoogleCallback handler where the main logic resides.
|
||||
//
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func GoogleLogin(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
// url := deps.AuthService.GetGoogleAuthUrl()
|
||||
//
|
||||
// ctx.Redirect(http.StatusSeeOther, url)
|
||||
// }
|
||||
|
||||
// GoogleCallback is the callback handler when the user successfully logs in with their Google
|
||||
// account. They will be directed here and a JWT is generated. This JWT is stored in the users
|
||||
// cookies and will be used by protected routes to validate their login status.
|
||||
//
|
||||
// We do not need to return all of this data, it is just for testing.
|
||||
//
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func GoogleCallback(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// var (
|
||||
// state string = ctx.Query("state")
|
||||
// code string = ctx.Query("code")
|
||||
// )
|
||||
//
|
||||
// if jwt, err := deps.AuthService.GoogleAuthSuccess(state, code); err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
// } else {
|
||||
// domain.SetCookie(ctx, "jwt_token", jwt, time.Hour*24*7)
|
||||
// ctx.Redirect(http.StatusSeeOther, "/")
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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.
|
||||
//
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func Logout(ctx *gin.Context) {
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME)
|
||||
// }
|
||||
@ -1,142 +0,0 @@
|
||||
package handlers
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func EngagementViewRecipe(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
// recipeId, _ := strconv.Atoi(ctx.Param("id"))
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// user := deps.UserService.GetAuthenicatedUser(ctx)
|
||||
// if user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// }
|
||||
//
|
||||
// if !domain.IsLoggedIn(ctx) || user == nil {
|
||||
// if _, err := deps.EngagementService.ViewRecipe(recipeId); err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// ctx.Header("HX-Redirect", fmt.Sprintf(domain.WEB_RECIPE, recipeId))
|
||||
// ctx.Status(http.StatusOK)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // We caught nil already, we can assume the user exists
|
||||
// if _, err := deps.EngagementService.UserViewRecipe(user.Id, recipeId); err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// ctx.Header("HX-Redirect", fmt.Sprintf(domain.WEB_RECIPE, recipeId))
|
||||
// ctx.Status(http.StatusOK)
|
||||
// }
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func EngagementShareRecipe(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
// recipeId, _ := strconv.Atoi(ctx.Param("id"))
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// user := deps.UserService.GetAuthenicatedUser(ctx)
|
||||
// if user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// }
|
||||
//
|
||||
// if !domain.IsLoggedIn(ctx) || user == nil {
|
||||
// if _, err := deps.EngagementService.ShareRecipe(recipeId); err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// ctx.Status(http.StatusNoContent)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if _, err := deps.EngagementService.UserShareRecipe(user.Id, recipeId); err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// ctx.Status(http.StatusNoContent)
|
||||
// }
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func EngagementFavoriteRecipe(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// user := deps.UserService.GetAuthenicatedUser(ctx)
|
||||
// if user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// }
|
||||
//
|
||||
// if !domain.IsLoggedIn(ctx) || user == nil {
|
||||
// ctx.Header("HX-Redirect", domain.WEB_LOGIN)
|
||||
// ctx.Status(http.StatusOK)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// id := ctx.Param("id")
|
||||
// recipeId, _ := strconv.Atoi(id)
|
||||
//
|
||||
// if _, err := deps.EngagementService.UserFavoriteRecipe(user.Id, recipeId); err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Something went wrong. %s.", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// ctx.Status(http.StatusNoContent)
|
||||
// }
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func EngagementMakeRecipe(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// user := deps.UserService.GetAuthenicatedUser(ctx)
|
||||
// if user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// }
|
||||
//
|
||||
// if !domain.IsLoggedIn(ctx) || user == nil {
|
||||
// ctx.Header("HX-Redirect", domain.WEB_LOGIN)
|
||||
// ctx.Status(http.StatusOK)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// id := ctx.Param("id")
|
||||
// recipeId, _ := strconv.Atoi(id)
|
||||
//
|
||||
// if _, err := deps.EngagementService.UserMakeRecipe(user.Id, recipeId); err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// ctx.Status(http.StatusNoContent)
|
||||
// }
|
||||
// }
|
||||
@ -1,296 +0,0 @@
|
||||
package handlers
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func LoginPage(ctx *gin.Context) {
|
||||
// title := "Potion - Login"
|
||||
// page := pages.LoginPage()
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func HomePage(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domainServer.InjectedDependencies)
|
||||
//
|
||||
// loggedIn := domain.IsLoggedIn(ctx)
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// if user := deps.UserService.GetAuthenicatedUser(ctx); user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// loggedIn = false
|
||||
// }
|
||||
//
|
||||
// var page templ.Component
|
||||
// if loggedIn {
|
||||
// userId := ctx.MustGet("userId").(int)
|
||||
// madeRecipes, err := deps.RecipeService.GetUserMadeRecipes(userId, 6)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Error getting made recipes. %s\n", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting made recipes. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// viewedRecipes, err := deps.RecipeService.GetUserViewedRecipes(userId, 6)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Error getting viewed recipes. %s\n", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting viewed recipes. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Get the recipe of the week
|
||||
// recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(&userId)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Error getting recipe of the week. %s\n", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting recipe of the week. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if bytes, err := ctx.Cookie("search-filters"); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to get search-filter cookie. %s\n", err.Error())
|
||||
// page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek, nil)
|
||||
// } else {
|
||||
// var filters domainRecipe.SearchFilters
|
||||
// if err := json.Unmarshal([]byte(bytes), &filters); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to unmarshal search-filter cookie. %s\n", err.Error())
|
||||
// page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek, nil)
|
||||
// } else {
|
||||
// page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek, &filters)
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // Get the recipe of the week
|
||||
// recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(nil)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Error getting recipe of the week. %s\n", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting recipe of the week. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if bytes, err := ctx.Cookie("search-filters"); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to get search-filter cookie. %s\n", err.Error())
|
||||
// page = templates.HomePage(false, nil, nil, recipeOfTheWeek, nil)
|
||||
// } else {
|
||||
// var filters domainRecipe.SearchFilters
|
||||
// if err := json.Unmarshal([]byte(bytes), &filters); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to unmarshal search-filter cookie. %s\n", err.Error())
|
||||
// page = templates.HomePage(false, nil, nil, recipeOfTheWeek, nil)
|
||||
// } else {
|
||||
// page = templates.HomePage(false, nil, nil, recipeOfTheWeek, &filters)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// title := "Potion - Home"
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func FavoritesPage(ctx *gin.Context) {
|
||||
// // If not logged in, direct to the login page
|
||||
// if !domainServer.IsLoggedIn(ctx) {
|
||||
// ctx.Redirect(http.StatusSeeOther, domainServer.WEB_LOGIN)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// title := "Potion - Favorites"
|
||||
// var page templ.Component
|
||||
//
|
||||
// // Get filters from cookies
|
||||
// if bytes, err := ctx.Cookie("search-filters"); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to get search-filter cookie. %s\n", err.Error())
|
||||
// page = pages.FavoritesPage(nil)
|
||||
// } else {
|
||||
// var filters domainRecipe.SearchFilters
|
||||
// if err := json.Unmarshal([]byte(bytes), &filters); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to unmarshal search-filter cookie. %s\n", err.Error())
|
||||
// page = pages.FavoritesPage(nil)
|
||||
// } else {
|
||||
// page = pages.FavoritesPage(&filters)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
//
|
||||
// func CreatePage(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domainServer.InjectedDependencies)
|
||||
//
|
||||
// // If not logged in, direct to the login page
|
||||
// if !domainServer.IsLoggedIn(ctx) {
|
||||
// ctx.Redirect(http.StatusSeeOther, domainServer.WEB_LOGIN)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// if user := deps.UserService.GetAuthenicatedUser(ctx); user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
//
|
||||
// ctx.Redirect(http.StatusSeeOther, domainServer.WEB_LOGIN)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// title := "Potion - Create"
|
||||
// page := pages.CreatePage()
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func ProfilePage(ctx *gin.Context) {
|
||||
// // If not logged in, direct to the login page
|
||||
// if !domainServer.IsLoggedIn(ctx) {
|
||||
// ctx.Redirect(http.StatusSeeOther, domainServer.WEB_LOGIN)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Else, get the user data
|
||||
// deps := ctx.MustGet("deps").(*domainServer.InjectedDependencies)
|
||||
// user := deps.UserService.GetAuthenicatedUser(ctx)
|
||||
// if user == nil {
|
||||
// // User is failing to be found, direct to the login page
|
||||
// ctx.Redirect(http.StatusSeeOther, domainServer.WEB_LOGIN)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// recipes, err := deps.RecipeService.GetUserRecipes(user.Id)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Error getting recipes. %s\n", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting recipes. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// favorites, err := deps.RecipeService.GetUserFavoriteRecipes(user.Id)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Error getting favorite recipes. %s\n", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting favorite recipes. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Get the engagement data, not sure what will happen when errors occur
|
||||
// engagements, err := deps.EngagementService.GetUserEngagement(user.Id, 6)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Error getting user engagements. %s\n", err.Error()))
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting user engagements. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// title := "Potion - Profile"
|
||||
// page := pages.ProfilePage(*user, recipes, favorites, engagements)
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func ListPage(ctx *gin.Context) {
|
||||
// title := "Potion - Shopping List"
|
||||
// page := pages.ListPage()
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func RecipePage(ctx *gin.Context) {
|
||||
// // Call recipe service to get via ID
|
||||
// deps := ctx.MustGet("deps").(*domainServer.InjectedDependencies)
|
||||
// id := ctx.Param("id")
|
||||
//
|
||||
// // Parse ID
|
||||
// parsed, err := strconv.Atoi(id)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("ERROR: %s", err.Error()))
|
||||
// ctx.JSON(400, err.Error())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Get signed in user, if they exist
|
||||
// var userId *int = nil
|
||||
// var loggedIn = domainServer.IsLoggedIn(ctx)
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// if user := deps.UserService.GetAuthenicatedUser(ctx); user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// loggedIn = false
|
||||
// }
|
||||
//
|
||||
// if loggedIn {
|
||||
// storeId := ctx.MustGet("userId").(int)
|
||||
// userId = &storeId
|
||||
// }
|
||||
//
|
||||
// // Get recipe
|
||||
// recipe, err := deps.RecipeService.GetRecipe(parsed, userId)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("ERROR: %s", err.Error()))
|
||||
// ctx.JSON(400, err.Error())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Get user (owner)
|
||||
// user, err := deps.UserService.GetUser(recipe.UserId)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("ERROR: %s", err.Error()))
|
||||
// ctx.JSON(400, err.Error())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// title := "Potion - View Recipe"
|
||||
// page := pages.RecipePage(*recipe, *user, loggedIn, deps.EnvironmentConfig.Domain)
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
//
|
||||
// func SearchPage(ctx *gin.Context) {
|
||||
// var page templ.Component
|
||||
// // Get filters from cookies
|
||||
// if bytes, err := ctx.Cookie("search-filters"); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to get search-filter cookie. %s\n", err.Error())
|
||||
// page = pages.SearchPage(nil, false)
|
||||
// } else {
|
||||
// var filters domainRecipe.SearchFilters
|
||||
// if err := json.Unmarshal([]byte(bytes), &filters); err != nil {
|
||||
// fmt.Printf("ERROR: Failed to unmarshal search-filter cookie. %s\n", err.Error())
|
||||
// page = pages.SearchPage(nil, false)
|
||||
// } else {
|
||||
// page = pages.SearchPage(&filters, true)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// title := "Potion - Recipe Search"
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func NotFoundPage(ctx *gin.Context) {
|
||||
// title := "Potion - Not Found"
|
||||
// page := pages.NotFoundPage()
|
||||
//
|
||||
// ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
// }
|
||||
@ -1,136 +0,0 @@
|
||||
package handlers
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// const CREATE_ERROR_HTML = `
|
||||
// <p id="response" class="text-sm text-red-500 px-4 py-1 bg-red-100 rounded-full w-fit">
|
||||
// Uh oh! Something went wrong when creating your recipe. Please try again. %s
|
||||
// </p>
|
||||
// `
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func CreateRecipe(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// recipe, err := deps.RecipeService.CreateRecipe(ctx)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.String(http.StatusOK, CREATE_ERROR_HTML, err.Error())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Send HTMX redirection
|
||||
// url := fmt.Sprintf(domain.WEB_RECIPE, recipe.Id)
|
||||
// ctx.Header("HX-Redirect", url)
|
||||
// ctx.Status(http.StatusCreated)
|
||||
// }
|
||||
|
||||
// toBits converts an array of stringified numbers into a single summed value
|
||||
//
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func toBits(arr []string) (bits int) {
|
||||
// for _, x := range arr {
|
||||
// num, _ := strconv.Atoi(x)
|
||||
// bits += num
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func SearchRecipes(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// // create filters
|
||||
// filters := domainRecipe.SearchFilters{
|
||||
// Search: ctx.PostForm("search"), // string, search query for titles
|
||||
// MealType: toBits(ctx.PostFormArray("meal")),
|
||||
// Time: toBits(ctx.PostFormArray("time")),
|
||||
// Difficulty: toBits(ctx.PostFormArray("difficulty")),
|
||||
// ServingSize: toBits(ctx.PostFormArray("serving")),
|
||||
// }
|
||||
//
|
||||
// // Set the filters into the cookies, so they can be reloaded
|
||||
// if bytes, err := json.Marshal(filters); err == nil {
|
||||
// domain.SetCookie(ctx, "search-filters", string(bytes), time.Hour*24)
|
||||
// // ctx.SetCookie(
|
||||
// // "search-filters",
|
||||
// // string(bytes),
|
||||
// // int(time.Now().Add(24*time.Hour).Sub(time.Now()).Seconds()),
|
||||
// // "/",
|
||||
// // true,
|
||||
// // )
|
||||
// }
|
||||
//
|
||||
// redirect := ctx.PostForm("redirect")
|
||||
// if redirect == "true" {
|
||||
// ctx.Header("HX-Redirect", domain.WEB_SEARCH)
|
||||
// ctx.Status(http.StatusOK)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Get user if logged in, so we can get favorite status
|
||||
// var userId *int = nil
|
||||
// if domain.IsLoggedIn(ctx) {
|
||||
// id := ctx.MustGet("userId").(int)
|
||||
// userId = &id
|
||||
// }
|
||||
//
|
||||
// // TODO: Not sure if we need to ensure the user is valid here
|
||||
//
|
||||
// // We don't care about favorite status, so use false
|
||||
// recipes, err := deps.RecipeService.SearchRecipes(filters, userId, false)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusOK, gin.H{"error": err.Error()})
|
||||
// }
|
||||
//
|
||||
// // Render content as the response
|
||||
// ctx.Status(200)
|
||||
// templates.ResultList(recipes).Render(ctx.Request.Context(), ctx.Writer)
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func SearchRecipesFavorites(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// // create filters
|
||||
// filters := domainRecipe.SearchFilters{
|
||||
// Search: ctx.PostForm("search"), // string, search query for titles
|
||||
// MealType: toBits(ctx.PostFormArray("meal")),
|
||||
// Time: toBits(ctx.PostFormArray("time")),
|
||||
// Difficulty: toBits(ctx.PostFormArray("difficulty")),
|
||||
// ServingSize: toBits(ctx.PostFormArray("serving")),
|
||||
// }
|
||||
//
|
||||
// // Set the filters into the cookies, so they can be reloaded
|
||||
// if bytes, err := json.Marshal(filters); err == nil {
|
||||
// domain.SetCookie(ctx, "search-filters", string(bytes), time.Hour*24)
|
||||
// // ctx.SetCookie(
|
||||
// // "search-filters",
|
||||
// // string(bytes),
|
||||
// // int(time.Now().Add(24*time.Hour).Sub(time.Now()).Seconds()),
|
||||
// // "/",
|
||||
// // "", // TODO: Need an actual domain
|
||||
// // false, // TODO: True in prod
|
||||
// // true,
|
||||
// // )
|
||||
// }
|
||||
//
|
||||
// // TODO: Error here if they're not logged in?
|
||||
// // Get user data (they should be logged in)
|
||||
// if !domain.IsLoggedIn(ctx) {
|
||||
// components.RenderErrorBanner(ctx, "User is not logged in. User will be nil.")
|
||||
// ctx.JSON(http.StatusOK, gin.H{"error": "User is not logged in. User will be nil."})
|
||||
// }
|
||||
//
|
||||
// userId := ctx.MustGet("userId").(int)
|
||||
//
|
||||
// recipes, err := deps.RecipeService.SearchRecipes(filters, &userId, true)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, err.Error())
|
||||
// ctx.JSON(http.StatusOK, gin.H{"error": err.Error()})
|
||||
// }
|
||||
//
|
||||
// // Render content as the response
|
||||
// ctx.Status(200)
|
||||
// templates.FavoriteList(recipes).Render(ctx.Request.Context(), ctx.Writer)
|
||||
// }
|
||||
@ -1,71 +0,0 @@
|
||||
package handlers
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// const TAG_HTML = `
|
||||
// <li
|
||||
// hx-post="%s"
|
||||
// hx-trigger="click"
|
||||
// hx-target="#tag-list"
|
||||
// hx-swap="innerHTML"
|
||||
// hx-include="#tag-list"
|
||||
// hx-vals='{"target": "%s"}'
|
||||
// class="flex text-xs items-center bg-blue-100 w-fit px-2 py-1 rounded-full gap-x-1 select-none cursor-pointer hover:bg-blue-200 duration-300">
|
||||
// × %s
|
||||
// </li>
|
||||
// `
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// const TAG_LIST_HTML = `
|
||||
// <input
|
||||
// hx-swap-oob="outerHTML"
|
||||
// type="hidden"
|
||||
// name="tags"
|
||||
// id="tags"
|
||||
// value="%s"
|
||||
// />
|
||||
// `
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func NewTag(ctx *gin.Context) {
|
||||
// tag := strings.ToLower(ctx.PostForm("tag"))
|
||||
// tags := strings.Split(ctx.PostForm("tags"), ",")
|
||||
//
|
||||
// tags = append([]string{tag}, tags...)
|
||||
//
|
||||
// var html string
|
||||
// var cleaned_tags []string
|
||||
// for _, tag := range tags {
|
||||
// if tag != "" {
|
||||
// html += fmt.Sprintf(TAG_HTML, domain.STATE_TAGS_DELETE, tag, tag)
|
||||
//
|
||||
// // Ensure that the list provided does not contain blank spaces.
|
||||
// // This is another measure to ensure this state is bulletproof.
|
||||
// cleaned_tags = append(cleaned_tags, tag)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Execute OOB swap for the tags
|
||||
// html += fmt.Sprintf(TAG_LIST_HTML, strings.Join(cleaned_tags, ","))
|
||||
//
|
||||
// ctx.String(http.StatusOK, html)
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func DeleteTag(ctx *gin.Context) {
|
||||
// tags := strings.Split(ctx.PostForm("tags"), ",")
|
||||
// target := ctx.PostForm("target")
|
||||
//
|
||||
// var html string
|
||||
// var new_tags []string
|
||||
// for _, tag := range tags {
|
||||
// if tag != target && tag != "" {
|
||||
// html += fmt.Sprintf(TAG_HTML, domain.STATE_TAGS_DELETE ,tag, tag)
|
||||
// new_tags = append(new_tags, tag)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Execute OOB swap for the tags
|
||||
// html += fmt.Sprintf(TAG_LIST_HTML, strings.Join(new_tags, ","))
|
||||
//
|
||||
// ctx.String(http.StatusOK, html)
|
||||
// }
|
||||
@ -1,83 +0,0 @@
|
||||
package handlers
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func GetUserRecipes(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// user := deps.UserService.GetAuthenicatedUser(ctx)
|
||||
// if user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// }
|
||||
//
|
||||
// // Ensure logged in
|
||||
// if !domain.IsLoggedIn(ctx) || user == nil {
|
||||
// components.RenderErrorBanner(ctx, "User is not authorized to access this endpoint. Please login to continue.")
|
||||
// ctx.JSON(http.StatusUnauthorized, gin.H{
|
||||
// "status": http.StatusUnauthorized,
|
||||
// "message": "User is not authorized to access this endpoint. Please login to continue.",
|
||||
// "recipes": nil,
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// recipes, err := deps.RecipeService.GetUserRecipes(user.Id)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Could not get user recipes. %s", err.Error()))
|
||||
// ctx.JSON(http.StatusBadRequest, gin.H{
|
||||
// "status": http.StatusBadRequest,
|
||||
// "message": fmt.Sprintf("Could not get user recipes. %s", err.Error()),
|
||||
// "recipes": nil,
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// ctx.JSON(http.StatusOK, gin.H{
|
||||
// "status": http.StatusOK,
|
||||
// "message": "User recipes successfully retrieved.",
|
||||
// "recipes": recipes,
|
||||
// })
|
||||
// }
|
||||
|
||||
// DEPRECATED: As of September 4th, 2025.
|
||||
// func GetUserFavoriteRecipes(ctx *gin.Context) {
|
||||
// deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
||||
//
|
||||
// // Ensure user is logged in with a valid account
|
||||
// user := deps.UserService.GetAuthenicatedUser(ctx)
|
||||
// if user == nil {
|
||||
// // Log (stale) user out
|
||||
// domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||
// domain.SetCookie(ctx, "search-filters", "", -1)
|
||||
// }
|
||||
//
|
||||
// // Ensure logged in
|
||||
// if !domain.IsLoggedIn(ctx) || user == nil {
|
||||
// components.RenderErrorBanner(ctx, "User is not authorized to access this endpoint. Please login to continue.")
|
||||
// ctx.JSON(http.StatusUnauthorized, gin.H{
|
||||
// "status": http.StatusUnauthorized,
|
||||
// "message": "User is not authorized to access this endpoint. Please login to continue.",
|
||||
// "recipes": nil,
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// recipes, err := deps.RecipeService.GetUserFavoriteRecipes(user.Id)
|
||||
// if err != nil {
|
||||
// components.RenderErrorBanner(ctx, fmt.Sprintf("Could not get favorite recipes. %s", err.Error()))
|
||||
// ctx.JSON(http.StatusBadRequest, gin.H{
|
||||
// "status": http.StatusBadRequest,
|
||||
// "message": fmt.Sprintf("Could not get favorite recipes. %s", err.Error()),
|
||||
// "recipes": nil,
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// ctx.JSON(http.StatusOK, gin.H{
|
||||
// "status": http.StatusOK,
|
||||
// "message": "User recipes successfully retrieved.",
|
||||
// "recipes": recipes,
|
||||
// })
|
||||
// }
|
||||
Loading…
x
Reference in New Issue
Block a user