Lennard Brinkhaus
31bd0cf639
Co-authored-by: Fenpaws <soxx@fenpa.ws> Reviewed-on: anthrove/e621-to-graph#13 Reviewed-by: SoXX <fenpaws@noreply.localhost> Co-authored-by: Lennard Brinkhaus <lennard.brinkhaus@noreply.localhost> Co-committed-by: Lennard Brinkhaus <lennard.brinkhaus@noreply.localhost>
39 lines
1004 B
Go
39 lines
1004 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"e621_to_neo4j/database"
|
|
"e621_to_neo4j/e621"
|
|
"e621_to_neo4j/services"
|
|
"fmt"
|
|
log "github.com/sirupsen/logrus"
|
|
"net/http"
|
|
)
|
|
|
|
// UserHandler is the handler for the user API
|
|
func UserHandler(ctx context.Context, graphConnection database.GraphConnection, e621Client *e621.Client) func(response http.ResponseWriter, request *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
log.Println("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
|
|
go services.ScrapeUser(ctx, graphConnection, *e621Client, username)
|
|
|
|
// Send a response
|
|
w.WriteHeader(http.StatusOK)
|
|
fmt.Fprintf(w, "Username %s processed successfully", username)
|
|
|
|
}
|
|
}
|