This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/api/user.go

37 lines
942 B
Go
Raw Normal View History

2023-05-24 14:05:27 +00:00
package api
import (
"context"
"e621_to_neo4j/e621"
"e621_to_neo4j/services"
"fmt"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"net/http"
)
// UserHandler is the handler for the user API
func UserHandler(ctx context.Context, driver neo4j.DriverWithContext, e621Client *e621.Client) func(response http.ResponseWriter, request *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(w, "Only POST requests are allowed")
return
}
username := r.FormValue("username")
if username == "" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "Username is required")
return
}
// Perform further processing with the username
services.ScrapeUser(ctx, driver, *e621Client, username)
// Send a response
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Username %s processed successfully", username)
}
}