Rename user endpoints that return partials

master
link 2024-02-14 17:35:31 +10:00
parent a505b10124
commit e35816d3c1
3 changed files with 12 additions and 13 deletions

View File

@ -18,9 +18,8 @@
<!-- Add User Table generated server-side and sent to client when button clicked -->
<div id="addUserTable">
<!-- TODO: Create a user table on the backend with templ -->
<p>Click the button to load the tables from the REST API</p>
<button hx-get="http://localhost:1234/api/addUserTable" hx-trigger="click" hx-target="#addUserTable" hx-indicator="#indicator1">Load Tables</button>
<button hx-get="http://localhost:1234/api/partials/addUserTable" hx-trigger="click" hx-target="#addUserTable" hx-indicator="#indicator1">Load Tables</button>
<img id="indicator1" class="htmx-indicator" src="/spinning-circles.svg" />
</div>
@ -28,7 +27,7 @@
<!-- Load all users from the database on the backend, recieve html -->
<div id="allUsers">
<p>Click the button to load all users from the database</p>
<button hx-get="http://localhost:1234/api/allUsers"
<button hx-get="http://localhost:1234/api/partials/allUsersTable"
hx-trigger="click"
hx-target="#allUsers"
hx-indicator="#indicator2"

View File

@ -1,19 +1,20 @@
package handlers
import (
"fmt"
"net/http"
"database/sql"
"github.com/labstack/echo/v4"
"git.duckylabs.xyz/duckbox/echo-todo/partials"
"fmt"
"net/http"
"git.duckylabs.xyz/duckbox/echo-todo/models"
"git.duckylabs.xyz/duckbox/echo-todo/partials"
"github.com/labstack/echo/v4"
)
func UserTableHandler(c echo.Context) error {
func AddUserTableHandler(c echo.Context) error {
return render(c, partials.AddUserTable())
}
func AllUserHandler(c echo.Context) error {
func AllUserTableHandler(c echo.Context) error {
logger := c.Logger()
db := c.Get("db").(*sql.DB)
@ -72,6 +73,5 @@ func AddUserHandler(c echo.Context) error {
fmt.Printf("%v", user)
// return c.JSON(http.StatusCreated, u)
return c.String(http.StatusOK, "<h4>Successfully added " + username + "</h4>")
return c.String(http.StatusOK, "<h4>Successfully added "+username+"</h4>")
}

View File

@ -60,9 +60,9 @@ func main() {
e.POST("/api/addUser", handlers.AddUserHandler)
e.GET("/api/allUsers", handlers.AllUserHandler)
e.GET("/api/partials/allUsersTable", handlers.AllUserTableHandler)
e.GET("/api/addUserTable", handlers.UserTableHandler)
e.GET("/api/partials/addUserTable", handlers.AddUserTableHandler)
e.Logger.Fatal(e.Start(":1234"))
}