I can now submit a form and store it in the database.
This commit is contained in:
parent
eaaab2ac0b
commit
4045799ab9
4 changed files with 87 additions and 10 deletions
52
.air.toml
Normal file
52
.air.toml
Normal file
|
@ -0,0 +1,52 @@
|
|||
root = "."
|
||||
testdata_dir = "testdata"
|
||||
tmp_dir = "tmp"
|
||||
|
||||
[build]
|
||||
args_bin = []
|
||||
bin = "fibertest.exe"
|
||||
cmd = "make build"
|
||||
delay = 1000
|
||||
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
|
||||
exclude_file = []
|
||||
exclude_regex = ["_test.go"]
|
||||
exclude_unchanged = false
|
||||
follow_symlink = false
|
||||
full_bin = ""
|
||||
include_dir = []
|
||||
include_ext = ["go", "tpl", "tmpl", "html", "css", "js"]
|
||||
include_file = []
|
||||
kill_delay = "0s"
|
||||
log = "build-errors.log"
|
||||
poll = false
|
||||
poll_interval = 0
|
||||
post_cmd = []
|
||||
pre_cmd = []
|
||||
rerun = false
|
||||
rerun_delay = 500
|
||||
send_interrupt = false
|
||||
stop_on_error = false
|
||||
|
||||
[color]
|
||||
app = ""
|
||||
build = "yellow"
|
||||
main = "magenta"
|
||||
runner = "green"
|
||||
watcher = "cyan"
|
||||
|
||||
[log]
|
||||
main_only = false
|
||||
silent = false
|
||||
time = false
|
||||
|
||||
[misc]
|
||||
clean_on_exit = false
|
||||
|
||||
[proxy]
|
||||
app_port = 5001
|
||||
enabled = true
|
||||
proxy_port = 5002
|
||||
|
||||
[screen]
|
||||
clear_on_rebuild = false
|
||||
keep_scroll = true
|
7
Makefile
7
Makefile
|
@ -2,7 +2,10 @@ build:
|
|||
go build .
|
||||
|
||||
docs:
|
||||
go tool godoc -http=localhost:6060 -index
|
||||
go tool godoc -http=localhost:6060 -index -index_files godoc.idx
|
||||
|
||||
build_docs:
|
||||
go tool godoc -v -http=localhost:6060 -index -index_files godoc.idx -write_index
|
||||
|
||||
dev:
|
||||
air
|
||||
go tool air
|
||||
|
|
27
main.go
27
main.go
|
@ -12,9 +12,9 @@ import (
|
|||
|
||||
type Link struct {
|
||||
Id int `db:"id" json:"id"`
|
||||
StreamId int `db:"stream_id" json:"stream_id"`
|
||||
Url string `db:"url" json:"url"`
|
||||
Description string `db:"description" json:"description"`
|
||||
StreamId int `db:"stream_id" json:"stream_id" form:"stream_id"`
|
||||
Url string `db:"url" json:"url" form:"url"`
|
||||
Description string `db:"description" json:"description" form:"description"`
|
||||
}
|
||||
|
||||
type Stream struct {
|
||||
|
@ -74,13 +74,32 @@ func main() {
|
|||
return GetJson[Stream](db, c, err, sql, args...)
|
||||
})
|
||||
|
||||
|
||||
app.Get("/api/stream/:id/links", func (c *fiber.Ctx) error {
|
||||
sql, args, err := sq.Select("*").From("stream_link").Where("stream_id", c.Params("id")).ToSql()
|
||||
|
||||
return SelectJson[Link](db, c, err, sql, args...)
|
||||
})
|
||||
|
||||
app.Post("/api/link", func (c *fiber.Ctx) error {
|
||||
link := new(Link)
|
||||
|
||||
if err := c.BodyParser(link); err != nil {
|
||||
log.Println(err);
|
||||
return c.Redirect("/live/")
|
||||
}
|
||||
|
||||
sql, args, err := sq.Insert("stream_link").Columns("stream_id", "url", "description").Values(link.StreamId, link.Url, link.Description).ToSql()
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return c.Redirect("/live/")
|
||||
}
|
||||
|
||||
db.MustExec(sql, args...)
|
||||
|
||||
return c.Redirect("/live/")
|
||||
})
|
||||
|
||||
app.Static("/", "./public")
|
||||
|
||||
log.Fatal(app.Listen(":5001"))
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
<script defer src="/js/alpine.js"></script>
|
||||
<script src="/js/code.js"></script>
|
||||
<script>
|
||||
let req = new GetJson("/api/live/index.json");
|
||||
let req = new GetJson("/api/stream/1");
|
||||
let link_req = new GetJson("/api/stream/1/links");
|
||||
</script>
|
||||
</head>
|
||||
|
||||
|
@ -26,8 +27,8 @@
|
|||
|
||||
<block>
|
||||
<h2>Links Found in Chat</h2>
|
||||
<ul>
|
||||
<template x-for="item in Stream.links">
|
||||
<ul x-init="links = await link_req.theData()" x-data="{links: {}}">
|
||||
<template x-for="item in links">
|
||||
<li><a x-text="item.description" x-bind:href="item.url"></a></li>
|
||||
</template>
|
||||
</ul>
|
||||
|
@ -37,7 +38,9 @@
|
|||
<card>
|
||||
<top>Submit a Link</top>
|
||||
<middle>
|
||||
<input type="text" placeholder="Link Url">
|
||||
<input name="stream_id" type="hidden" value="1">
|
||||
<input name="url" type="text" placeholder="Link Url">
|
||||
<input name="description" type="text" placeholder="Description">
|
||||
</middle>
|
||||
</card>
|
||||
<buttons>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue