feat(api): anonymous author profile at /_journal/api/v1/authors/{author}

- Resolve {author} by golem15_bloghub_author_slug, then by login for users with a published post
- Project only id, names, login and author slug from backend_users; payload is id, slug, first_name, last_name
- JSON 404 {"error":"Author not found"} for unknown, soft-deleted and malformed values
- Document the route in README
This commit is contained in:
2026-10-09 13:19:35 +02:00
parent f5cd5b16fe
commit 908ade9c78
5 changed files with 345 additions and 4 deletions

View File

@@ -0,0 +1,34 @@
package api
import (
"strings"
"testing"
)
func TestValidAuthorParam(t *testing.T) {
cases := []struct {
name string
in string
want bool
}{
{"slug", "jane-doe", true},
{"dotted login", "jan.kowalski", true},
{"at sign", "a@b", true},
{"max bytes", strings.Repeat("a", 255), true},
{"multibyte", "zażółć", true},
{"empty", "", false},
{"whitespace only", strings.TrimSpace(" \t "), false},
{"over max bytes", strings.Repeat("a", 256), false},
{"nul byte", "a\x00b", false},
{"newline", "a\nb", false},
{"tab", "a\tb", false},
{"invalid utf8", "\xff", false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := validAuthorParam(tc.in); got != tc.want {
t.Fatalf("validAuthorParam(%q) = %v, want %v", tc.in, got, tc.want)
}
})
}
}