From 30ba2e8c7f4b4279d8d02253dab4ec726f6dd3c7 Mon Sep 17 00:00:00 2001 From: Abdulsamad Sheikh <abdulsas@stud.ntnu.no> Date: Wed, 21 Feb 2024 19:44:26 +0000 Subject: [PATCH] Upload New File --- handlers/handlers.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 handlers/handlers.go diff --git a/handlers/handlers.go b/handlers/handlers.go new file mode 100644 index 0000000..66b09cd --- /dev/null +++ b/handlers/handlers.go @@ -0,0 +1,40 @@ +package handlers + +import ( + // ... other imports + "assignment1/models" + "assignment1/services" +) + +func BookCountHandler(w http.ResponseWriter, r *http.Request) { + // Parse query parameters for language + query := r.URL.Query() + language := query.Get("language") + + // Fetch book data from the Gutendex API + books, err := services.FetchBooksByLanguage(language) + if err != nil { + // Handle error + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // Process the books to calculate the book count and author count + // ... (Implementation required) + + // Create a response object + response := models.GutenbergBookCount{ + Language: language, + // Books: Number of books (to be calculated), + // Authors: Number of unique authors (to be calculated), + // Fraction: Fraction of books in the language (to be calculated), + } + + // Write the response back as JSON + w.Header().Set("Content-Type", "application/json") + if err := json.NewEncoder(w).Encode(response); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} + +// ... Other handlers -- GitLab