(FIX): Working on finding all of the nil-deref errors.
This may have caught a few. Next I need to actually work on the development/testing/production environment setup.
This commit is contained in:
parent
0849a46b78
commit
65c73bddfa
@ -61,5 +61,7 @@ func GoogleCallback(ctx *gin.Context) {
|
||||
func Logout(ctx *gin.Context) {
|
||||
// TODO: Use same values as the GoogleCallback function
|
||||
ctx.SetCookie("jwt_token", "", -1, "/", "", false, true) // TODO: Update settings
|
||||
ctx.SetCookie("search-filters", "", -1, "/", "", false, true)
|
||||
|
||||
ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME)
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
@ -82,19 +83,6 @@ func FavoritesPage(ctx *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Else, get the user's favorites
|
||||
// BUG: Depreciated, not displaying a list, using search to drive this page as well
|
||||
// deps := ctx.MustGet("deps").(*domainServer.InjectedDependencies)
|
||||
// userId := ctx.MustGet("userId").(int)
|
||||
// recipes, err := deps.RecipeService.GetUserFavoriteRecipes(userId)
|
||||
// if err != nil {
|
||||
// ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||
// "status": http.StatusInternalServerError,
|
||||
// "message": fmt.Sprintf("Error getting favorites. %s\n", err.Error()),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
|
||||
ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
}
|
||||
|
||||
@ -200,24 +188,8 @@ func RecipePage(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add engagement
|
||||
// BUG: Don't want to do this here
|
||||
// if loggedIn {
|
||||
// if _, err = deps.EngagementService.UserViewRecipe(*userId, recipe.Id); err != nil {
|
||||
// fmt.Printf("ERROR: %s\n", err.Error())
|
||||
// ctx.JSON(400, err.Error())
|
||||
// return
|
||||
// }
|
||||
// } else {
|
||||
// if _, err = deps.EngagementService.ViewRecipe(recipe.Id); err != nil {
|
||||
// fmt.Printf("ERROR: %s\n", err.Error())
|
||||
// ctx.JSON(400, err.Error())
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
title := "Potion - View Recipe"
|
||||
page := pages.RecipePage(*recipe, *user, loggedIn)
|
||||
page := pages.RecipePage(*recipe, *user, loggedIn, os.Getenv("DOMAIN"))
|
||||
|
||||
ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page))
|
||||
}
|
||||
|
||||
@ -121,6 +121,10 @@ func SearchRecipesFavorites(ctx *gin.Context) {
|
||||
|
||||
// TODO: Error here if they're not logged in?
|
||||
// Get user data (they should be logged in)
|
||||
if !domain.IsLoggedIn(ctx) {
|
||||
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)
|
||||
|
||||
@ -188,22 +188,6 @@ func (s *Server) Setup() *Server {
|
||||
router_api.GET("/user/recipes", handlers.GetUserRecipes)
|
||||
router_api.GET("/user/favorites", handlers.GetUserFavoriteRecipes)
|
||||
|
||||
router_api.GET("/user/temp", func(ctx *gin.Context) {
|
||||
recipes, err := recipeService.GetUserMadeRecipes(3, 6)
|
||||
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{
|
||||
"recipes": recipes,
|
||||
"error": err.Error(),
|
||||
})
|
||||
} else {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{
|
||||
"recipes": recipes,
|
||||
"error": "",
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// Engagement endpoints
|
||||
router_api.POST("/engagement/view/:id", handlers.EngagementViewRecipe)
|
||||
router_api.POST("/engagement/share/:id", handlers.EngagementShareRecipe)
|
||||
|
||||
@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
domain "github.com/haydenhargreaves/Potion/internal/domain/user"
|
||||
_ "github.com/lib/pq"
|
||||
@ -35,6 +36,10 @@ func (r *UserRepository) CreateGoogleUser(googleUserInfo *domain.GoogleUserInfo,
|
||||
return domain.User{}, err
|
||||
}
|
||||
|
||||
if googleUserInfo == nil {
|
||||
return domain.User{}, fmt.Errorf("Google user info provided was nil")
|
||||
}
|
||||
|
||||
var user domain.User
|
||||
query := `INSERT INTO users
|
||||
(GoogleId, Name, Email, ImageUrl, GoogleRefreshToken)
|
||||
|
||||
@ -211,7 +211,7 @@ func Navbar(current string) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\"><p class=\"select-none text-red-800\">Potion</p></a></div><div class=\"hidden md:flex lg:flex items-center gap-8 select-none\">")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\"><p class=\"select-none\">Potion</p></a></div><div class=\"hidden md:flex lg:flex items-center gap-8 select-none\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@ -6,68 +6,73 @@ import "github.com/haydenhargreaves/Potion/internal/domain/recipe"
|
||||
import domainServer "github.com/haydenhargreaves/Potion/internal/domain/server"
|
||||
|
||||
templ FavoriteList(recipes []domain.Recipe) {
|
||||
<div id="result-list" class="flex flex-col w-full p-4 items-center">
|
||||
for _, recipe := range recipes {
|
||||
@favoriteResult(recipe)
|
||||
}
|
||||
if len(recipes) == 0 || recipes == nil {
|
||||
<p class="text-gray-700 text-sm py-4">No results</p>
|
||||
} else {
|
||||
<p class="text-gray-700 text-sm py-4">End of results</p>
|
||||
}
|
||||
</div>
|
||||
<div id="result-list" class="flex flex-col w-full p-4 items-center">
|
||||
for _, recipe := range recipes {
|
||||
@favoriteResult(recipe)
|
||||
}
|
||||
if len(recipes) == 0 || recipes == nil {
|
||||
<p class="text-gray-700 text-sm py-4">No results</p>
|
||||
} else {
|
||||
<p class="text-gray-700 text-sm py-4">End of results</p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
templ favoriteResult(recipe domain.Recipe) {
|
||||
<div hx-post={ fmt.Sprintf(domainServer.API_ENGAGEMENT_VIEW, recipe.Id) } hx-trigger="click" hx-swap="none"
|
||||
class="w-full p-2 border-b border-gray-200 hover:bg-gray-100 duration-200 flex items-center flex-col md:flex-row even:bg-[#f8f8f8] cursor-pointer">
|
||||
<img class="bg-gray-50 size-56 md:size-40 rounded-md border-0" src="" />
|
||||
<div class="text-gray-700 p-4 flex flex-col items-center md:items-start w-full">
|
||||
<div class="flex flex-col md:flex-row items-center md:items-start justify-between w-full">
|
||||
<div class="flex flex-col items-center md:items-start">
|
||||
<h3 class="text-xl font-semibold text-black pb-1">
|
||||
{ recipe.Title } <span class="text-sm font-normal hidden md:inline">{ recipe.Category }</span>
|
||||
</h3>
|
||||
<div class="text-sm flex gap-x-3 gap-y-1 items-center flex-wrap">
|
||||
<span class="flex gap-x-1 align-center">
|
||||
@timeIconSm()
|
||||
{ recipe.Duration.Total } min
|
||||
</span>
|
||||
<span class="flex gap-x-1 align-center">
|
||||
for _ = range(recipe.Difficulty) {
|
||||
@starIconSm(true)
|
||||
}
|
||||
for _ = range(5 - recipe.Difficulty) {
|
||||
@starIconSm(false)
|
||||
}
|
||||
</span>
|
||||
<span class="flex gap-x-1 align-center">
|
||||
@servingIconSm()
|
||||
Serves { recipe.Serves }
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-2 mt-4 md:my-0 hidden md:block">
|
||||
<svg class="h-6 text-red-500" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M2 9.1371C2 14 6.01943 16.5914 8.96173 18.9109C10 19.7294 11 20.5 12 20.5C13 20.5 14 19.7294 15.0383 18.9109C17.9806 16.5914 22 14 22 9.1371C22 4.27416 16.4998 0.825464 12 5.50063C7.50016 0.825464 2 4.27416 2 9.1371Z"
|
||||
fill="currentColor"></path>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-sm py-2 text-center md:text-left">{ recipe.Description }</p>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
hx-post={ fmt.Sprintf(domainServer.API_ENGAGEMENT_VIEW, recipe.Id) }
|
||||
hx-trigger="click"
|
||||
hx-swap="none"
|
||||
class="w-full p-2 border-b border-gray-200 hover:bg-gray-100 duration-200 flex items-center flex-col md:flex-row even:bg-[#f8f8f8] cursor-pointer"
|
||||
>
|
||||
<img class="bg-gray-50 size-56 md:size-40 rounded-md border-0" src=""/>
|
||||
<div class="text-gray-700 p-4 flex flex-col items-center md:items-start w-full">
|
||||
<div class="flex flex-col md:flex-row items-center md:items-start justify-between w-full">
|
||||
<div class="flex flex-col items-center md:items-start">
|
||||
<h3 class="text-xl font-semibold text-black pb-1">
|
||||
{ recipe.Title } <span class="text-sm font-normal hidden md:inline">{ recipe.Category }</span>
|
||||
</h3>
|
||||
<div class="text-sm flex gap-x-3 gap-y-1 items-center flex-wrap">
|
||||
<span class="flex gap-x-1 align-center">
|
||||
@timeIconSm()
|
||||
{ recipe.Duration.Total } min
|
||||
</span>
|
||||
<span class="flex gap-x-1 align-center">
|
||||
for _ = range(recipe.Difficulty) {
|
||||
@starIconSm(true)
|
||||
}
|
||||
for _ = range(5 - recipe.Difficulty) {
|
||||
@starIconSm(false)
|
||||
}
|
||||
</span>
|
||||
<span class="flex gap-x-1 align-center">
|
||||
@servingIconSm()
|
||||
Serves { recipe.Serves }
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-2 mt-4 md:my-0 hidden md:block">
|
||||
<svg class="h-6 text-red-500" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M2 9.1371C2 14 6.01943 16.5914 8.96173 18.9109C10 19.7294 11 20.5 12 20.5C13 20.5 14 19.7294 15.0383 18.9109C17.9806 16.5914 22 14 22 9.1371C22 4.27416 16.4998 0.825464 12 5.50063C7.50016 0.825464 2 4.27416 2 9.1371Z"
|
||||
fill="currentColor"
|
||||
></path>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-sm py-2 text-center md:text-left">{ recipe.Description }</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ FavoritesPage(filters domain.SearchFilters) {
|
||||
@components.Navbar("favorites")
|
||||
<div class="w-full flex justify-center">
|
||||
<div class="mx-2 md:mx-0 w-full md:w-1/2 md:pt-14 min-h-screen border-l border-r border-gray-300 bg-white">
|
||||
@components.BannerText("Favorites")
|
||||
@components.SearchBar(filters, false, true, true)
|
||||
<hr class="text-gray-300 w-full" />
|
||||
@FavoriteList(nil)
|
||||
</div>
|
||||
</div>
|
||||
@components.Navbar("favorites")
|
||||
<div class="w-full flex justify-center">
|
||||
<div class="mx-2 md:mx-0 w-full md:w-1/2 md:pt-14 min-h-screen border-l border-r border-gray-300 bg-white">
|
||||
@components.BannerText("Favorites")
|
||||
@components.SearchBar(filters, false, true, true)
|
||||
<hr class="text-gray-300 w-full"/>
|
||||
@FavoriteList(nil)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ func favoriteResult(recipe domain.Recipe) templ.Component {
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf(domainServer.API_ENGAGEMENT_VIEW, recipe.Id))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 22, Col: 71}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 23, Col: 68}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -104,7 +104,7 @@ func favoriteResult(recipe domain.Recipe) templ.Component {
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 29, Col: 24}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 33, Col: 20}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -117,7 +117,7 @@ func favoriteResult(recipe domain.Recipe) templ.Component {
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Category)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 29, Col: 95}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 33, Col: 91}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -134,7 +134,7 @@ func favoriteResult(recipe domain.Recipe) templ.Component {
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Duration.Total)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 34, Col: 35}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 38, Col: 30}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -171,7 +171,7 @@ func favoriteResult(recipe domain.Recipe) templ.Component {
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Serves)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 46, Col: 34}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 50, Col: 29}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -184,7 +184,7 @@ func favoriteResult(recipe domain.Recipe) templ.Component {
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Description)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 58, Col: 73}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/pages/favorites.templ`, Line: 63, Col: 72}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
@ -291,7 +291,7 @@ templ buttonSection(favorited bool, id int, loggedIn bool) {
|
||||
</section>
|
||||
}
|
||||
|
||||
templ RecipePage(recipe domain.Recipe, user domainUser.User, loggedIn bool) {
|
||||
templ RecipePage(recipe domain.Recipe, user domainUser.User, loggedIn bool, domain string) {
|
||||
@components.Navbar("")
|
||||
<div class="w-full flex justify-center">
|
||||
<div class="mx-2 md:mx-0 w-full md:w-1/2 md:pt-14 h-full border-l border-r border-gray-300 bg-white">
|
||||
@ -312,10 +312,10 @@ templ RecipePage(recipe domain.Recipe, user domainUser.User, loggedIn bool) {
|
||||
@tagList(recipe.Tags, recipe.Created, recipe.Modified)
|
||||
</div>
|
||||
</div>
|
||||
@scripts(recipe.Id)
|
||||
@scripts(recipe.Id, domain)
|
||||
}
|
||||
|
||||
templ scripts(id int) {
|
||||
templ scripts(id int, domain string) {
|
||||
<script>
|
||||
function shareButtonHandler() {
|
||||
const button = document.getElementById("share-button");
|
||||
@ -323,7 +323,7 @@ templ scripts(id int) {
|
||||
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
// TODO: Fix this to use the real domain somehow
|
||||
const url = "http://localhost:7331/v1/web/recipe/{{ id }}"
|
||||
const url = "{{ domain }}/v1/web/recipe/{{ id }}"
|
||||
navigator.clipboard.writeText(url).then(() => {
|
||||
button.outerHTML = `
|
||||
<button id="share-button"
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user