Skip to content
Snippets Groups Projects
Commit 30ba2e8c authored by Abdulsamad Sheikh's avatar Abdulsamad Sheikh :cat2:
Browse files

Upload New File

parent a828b184
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment