diff --git a/Makefile b/Makefile index d28c658..ef21177 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,12 @@ ifeq '$(OS)' 'Windows_NT' GO_IS_STUPID_EXE=.exe endif -all: tailwind site - echo "yay!" - build: go build . +all: tailwind site + echo "yay!" + site: go tool ssgod diff --git a/api/handlers.go b/api/handlers.go index 2ce66de..e77b306 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -23,6 +23,40 @@ func GetApiLogout(c *fiber.Ctx) error { return c.Redirect("/") } +func GetApiFeed(c *fiber.Ctx) error { + sql, args, err := sq.Select("*").From("message"). + Where(sq.Eq{"user_id": c.Params("user_id")}).ToSql() + if err != nil { return IfErrNil(err, c) } + + err = data.SelectJson[data.Message](c, err, sql, args...) + + return IfErrNil(err, c) +} + +func GetApiMessage(c *fiber.Ctx) error { + sql, args, err := sq.Select("*").From("message"). + Where(sq.Eq{"id": c.Params("id")}).ToSql() + + if err != nil { return IfErrNil(err, c) } + + err = data.GetJson[data.Message](c, err, sql, args...) + + return IfErrNil(err, c) +} + +func GetApiReplies(c *fiber.Ctx) error { + message_id := c.Params("message_id") + + sql, args, err := sq.Select("*").From("message"). + Where(sq.Eq{"replying_to": message_id}).ToSql() + + log.Println("SQL", sql, args); + if err != nil { return IfErrNil(err, c) } + + err = data.SelectJson[data.Message](c, err, sql, args...) + return IfErrNil(err, c) +} + func PostApiRegister(c *fiber.Ctx) error { user, err := ReceivePost[data.User](c) if err != nil { return IfErrNil(err, c) } @@ -76,6 +110,9 @@ func Setup(app *fiber.App) { app.Get("/api/logout", GetApiLogout) app.Post("/api/login", PostApiLogin) app.Post("/api/register", PostApiRegister) + app.Get("/api/feed/:user_id", GetApiFeed) + app.Get("/api/message/:id", GetApiMessage) + app.Get("/api/replies/:message_id", GetApiReplies) app.Get("/feed/", Page("feed")) app.Get("/post/view/:id/", Page("post/view")) diff --git a/data/models.go b/data/models.go index 4d9754d..74bd5f3 100644 --- a/data/models.go +++ b/data/models.go @@ -14,8 +14,25 @@ type User struct { Password string `db:"password" validate:"required,min=8,max=64"` } +type Message struct { + Id int `db:"id" json:"id" validate:"numeric"` + Text string `db:"text" json:"text" validate:"required,max=512"` + UserId int `db:"user_id" json:"user_id" validate:"numeric"` + CreatedAt string `db:"created_at" json:"created_at"` + Likes int `db:"likes" json:"likes" validate:"numeric"` + Bookmarks int `db:"bookmarks" json:"bookmarks" validate:"numeric"` + ReplyingTo int `db:"replying_to" json:"replying_to" validate:"numeric"` +} + +type Bookmark struct { + MessageId int `db:"message_id" json:"message_id" validate:"required,numeric"` + UserId int `db:"user_id" json:"user_id" validate:"required,numeric"` +} + func Models() map[string]reflect.Type { return map[string]reflect.Type{ "user": reflect.TypeFor[User](), + "message": reflect.TypeFor[Message](), + "bookmark": reflect.TypeFor[Bookmark](), } } diff --git a/migrations/20250827022830_feeds_posts_replies.sql b/migrations/20250827022830_feeds_posts_replies.sql new file mode 100644 index 0000000..15a7377 --- /dev/null +++ b/migrations/20250827022830_feeds_posts_replies.sql @@ -0,0 +1,13 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE message (id INTEGER PRIMARY KEY, text TEXT NOT NULL, user_id INTEGER NOT NULL, created_at DATETIME DEFAULT current_timestamp, likes INTEGER DEFAULT 0, bookmarks INTEGER DEFAULT 0, replying_to INTEGER); + +CREATE TABLE bookmark (user_id INTEGER NOT NULL, message_id INTEGER NOT NULL); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE message; +DROP TABLE reply; +DROP TABLE bookmark; +-- +goose StatementEnd diff --git a/static/js/code.js b/static/js/code.js index 505ab28..5c8527f 100644 --- a/static/js/code.js +++ b/static/js/code.js @@ -33,12 +33,15 @@ class PaginateTable { class GetJson { constructor(url) { + console.assert(url !== undefined, "Invalid url is undefined"); + console.log("GetJson url", url); this.item; this.url = url; } async item() { - const resp = await fetch(`${this.url}`); + const the_url = this.url; + const resp = await fetch(this.url); console.assert(resp.status == 200, "failed to get it"); this.item = await resp.json(); diff --git a/static/style.css b/static/style.css index 97e25e3..931b615 100644 --- a/static/style.css +++ b/static/style.css @@ -518,9 +518,6 @@ .p-4 { padding: calc(var(--spacing) * 4); } - .\!pt-0 { - padding-top: calc(var(--spacing) * 0) !important; - } .\!pt-1 { padding-top: calc(var(--spacing) * 1) !important; } diff --git a/views/feed.html b/views/feed.html index 077441f..52dce5c 100644 --- a/views/feed.html +++ b/views/feed.html @@ -27,10 +27,13 @@ {{end}} + -
Update the docs to document almost everything.
- -for(i = u in whatever) {
- print("whatever")
-}
- Chillwave bruh cred, succulents skateboard activated charcoal shaman freegan. Hell of four loko succulents, tote bag affogato asymmetrical disrupt selvage. 3 wolf moon post-ironic bodega boys fanny pack big mood godard offal cold-pressed sriracha before they sold out pabst mukbang readymade.
+