search for a book with a single value

This commit is contained in:
rmanach
2025-01-07 09:29:21 +01:00
parent 1c6b758f0c
commit 42a3181797
12 changed files with 341 additions and 12 deletions
+22 -1
View File
@@ -104,6 +104,26 @@ func (bf *BookForm) IsSuccess() bool {
return bf.Method == http.MethodPost && bf.Error == "" && !bf.HasErrors()
}
func (bf *BookForm) IntoMetadata() *services.BookMetadata {
bm := &services.BookMetadata{
Name: bf.Name.Value,
Editor: bf.Editor.Value,
Authors: bf.Authors.Value,
Year: uint16(bf.Year.Value),
Keywords: nil,
}
if desc := bf.Description.Value; desc != "" {
bm.Description = &desc
}
if keywords := bf.Keywords.Value; len(keywords) > 0 {
bm.Keywords = keywords
}
return bm
}
func Handler(a services.IAuthenticate, s services.IStore) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
@@ -203,10 +223,11 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, a services.IAuthenti
filename := bf.File.Value.GetFilename()
log.Info().Str("filename", filename).Msg("file is uploading...")
if err := s.Save(filename, bf.File.Value.file); err != nil {
if err := s.Save(bf.IntoMetadata(), bf.File.Value.file); err != nil {
if err := uploadForm.Execute(buf, &BookForm{Error: err.Error()}); err != nil {
log.Err(err).Msg("unable to generate template")
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusInternalServerError)