diff --git a/handlers/handlers.go b/handlers/handlers.go new file mode 100644 index 0000000000000000000000000000000000000000..66b09cd63a2864336870b6a995f45fb29d05b067 --- /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