First stab at a form submit off an alpine.js form. Honestly not great. It's a lot of code already for even less functionality.
This commit is contained in:
parent
e4153fd74a
commit
3fd8169d83
7 changed files with 46 additions and 26 deletions
|
@ -85,7 +85,7 @@ func Update(table string, value reflect.Value) error {
|
|||
builder = builder.Set(tag, field.Interface())
|
||||
}
|
||||
|
||||
builder.Where(sq.Eq{"id": value.FieldByName("Id").Interface()})
|
||||
builder = builder.Where(sq.Eq{"id": value.FieldByName("Id").Interface()})
|
||||
sql_query, args, err := builder.ToSql()
|
||||
|
||||
fmt.Println("UPDATE QUERY", sql_query, args)
|
||||
|
|
|
@ -3,6 +3,8 @@ package admin
|
|||
import (
|
||||
"maps"
|
||||
"strconv"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"zedshaw.games/webapp/data"
|
||||
. "zedshaw.games/webapp/common"
|
||||
|
@ -59,7 +61,14 @@ func GetPageSelectOne(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
func PostApiUpdate(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{})
|
||||
user, err := ReceivePost[data.User](c)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
fmt.Println("post received", user)
|
||||
|
||||
err = Update(c.Params("table"), reflect.ValueOf(user).Elem())
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
return c.JSON(fiber.Map{"status": "ok"})
|
||||
}
|
||||
|
||||
func PutApiInsert(c *fiber.Ctx) error {
|
||||
|
|
|
@ -8,7 +8,7 @@ type Login struct {
|
|||
}
|
||||
|
||||
type User struct {
|
||||
Id int `db:"id" json:"id" validate:"isdefault"`
|
||||
Id int `db:"id" json:"id" validate:"numeric"`
|
||||
Username string `db:"username" validate:"required,max=30"`
|
||||
Email string `db:"email" validate:"required,email,max=128"`
|
||||
Password string `db:"password" validate:"required,min=8,max=64"`
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<meta name="viewport" content="initial-scale=1.0" />
|
||||
<meta name="author" content="Zed A. Shaw" />
|
||||
<meta name="description" content="My Go learning project, which is a Twitch support thing." />
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" href="/global.css">
|
||||
<link rel="stylesheet" href="/color.css">
|
||||
<link rel="stylesheet" href="/blockstart.css">
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
class GetJson {
|
||||
constructor(url) {
|
||||
this.url = url;
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
<script>
|
||||
let Data = new GetJson("/api/admin/table/{{ .Table }}/{{ .Id }}/");
|
||||
|
||||
const PostForm = async (url, data) => {
|
||||
console.log("DATA", JSON.stringify(data));
|
||||
return await fetch(url, {
|
||||
method: "POST",
|
||||
mode: "same-origin",
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<blockstart>
|
||||
|
@ -13,15 +25,15 @@
|
|||
<template x-for="(value, key) in item">
|
||||
<div>
|
||||
<label x-text="key" x-bind:for="key"></label>
|
||||
<input x-text="value" x-bind:value="value" x-bind:id="key" />
|
||||
<input x-text="value" x-model="item[key]" x-bind:id="key" />
|
||||
</div>
|
||||
</template>
|
||||
</middle>
|
||||
<bottom>
|
||||
<button-group>
|
||||
<button type="button">Back</button>
|
||||
<button type="submit">Update</button>
|
||||
<button type="button">Delete</button>
|
||||
<button type="button" @click.prevent="PostForm('/api/admin/table/{{ .Table }}/{{ .Id }}/', item)">Update</button>
|
||||
<button type="button" @click.prevent="console.log('DELETE', item.id)">Delete</button>
|
||||
</button-group>
|
||||
</bottom>
|
||||
</card>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<meta name="viewport" content="initial-scale=1.0" />
|
||||
<meta name="author" content="Zed A. Shaw" />
|
||||
<meta name="description" content="My Go learning project, which is a Twitch support thing." />
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" href="/global.css">
|
||||
<link rel="stylesheet" href="/color.css">
|
||||
<link rel="stylesheet" href="/blockstart.css">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue