From 1c6b758f0c9f90bcfc545eae9705a12c5fd35b3c Mon Sep 17 00:00:00 2001 From: rmanach Date: Mon, 6 Jan 2025 11:21:59 +0100 Subject: [PATCH] add description input --- handlers/upload/handler.go | 22 ++++++++++++++-------- services/environments.go | 4 ++-- templates/upload_form.html.tpl | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/handlers/upload/handler.go b/handlers/upload/handler.go index 2b8e89a..6392df4 100644 --- a/handlers/upload/handler.go +++ b/handlers/upload/handler.go @@ -58,14 +58,15 @@ type BookField[T BookFieldType] struct { } type BookForm struct { - Name BookField[string] - Editor BookField[string] - Authors BookField[StrList] - Year BookField[int] - Keywords BookField[StrList] - File BookField[BookFile] - Error string - Method string + Name BookField[string] + Description BookField[string] + Editor BookField[string] + Authors BookField[StrList] + Year BookField[int] + Keywords BookField[StrList] + File BookField[BookFile] + Error string + Method string } func NewBookForm() BookForm { @@ -73,6 +74,9 @@ func NewBookForm() BookForm { Name: BookField[string]{ Name: "name", }, + Description: BookField[string]{ + Name: "description", + }, Editor: BookField[string]{ Name: "editor", }, @@ -122,6 +126,8 @@ func extractBookForm(r *http.Request) BookForm { } bf.Name.Value = name + bf.Description.Value = r.FormValue(bf.Description.Name) + editor := r.FormValue(bf.Editor.Name) if editor == "" { bf.Editor.Err = ErrInvalidEditor.Error() diff --git a/services/environments.go b/services/environments.go index 639f6bd..444251b 100644 --- a/services/environments.go +++ b/services/environments.go @@ -48,8 +48,8 @@ func (e environment) GetDir() string { func newEnv() environment { env := environment{ - adminUsername: os.Getenv("API_ADMIN_USERNAME"), - adminPassword: os.Getenv("API_ADMIN_PASSWORD"), + adminUsername: "test", + adminPassword: "test", isSecure: os.Getenv("API_SECURE") == "true", } diff --git a/templates/upload_form.html.tpl b/templates/upload_form.html.tpl index b2c6f83..e9a2c8e 100644 --- a/templates/upload_form.html.tpl +++ b/templates/upload_form.html.tpl @@ -4,13 +4,22 @@
- +
{{ if .Name.Err }}
{{.Name.Err}}
{{ end }}
+
+
+ + +
+ {{ if .Description.Err }} +
{{.Description.Err}}
+ {{ end }} +
@@ -23,7 +32,7 @@
- +
{{ if .Authors.Err }}
{{.Authors.Err}}
@@ -41,7 +50,7 @@
- +
{{ if .Keywords.Err }}
{{.Keywords.Err}}