Skip to content
Snippets Groups Projects
Select Git revision
  • 30ba2e8c7f4b4279d8d02253dab4ec726f6dd3c7
  • main default protected
2 results

handlers.go

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    handlers.go 1.16 KiB
    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