Initialize Tinder API Wrapper with server configuration and Docker setup

This commit is contained in:
2025-03-20 22:19:48 +01:00
commit e99b56e434
17 changed files with 1459 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
package handlers
import (
"fmt"
"net/http"
"strings"
tinder "tinder-api-wrapper"
)
// HandleLike handles the /like/{userId} endpoint
func HandleLike(client *tinder.Client) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
path := strings.TrimPrefix(r.URL.Path, "/like/")
if path == "" {
http.Error(w, "User ID is required", http.StatusBadRequest)
return
}
resp, err := client.LikeUser(path)
if err != nil {
http.Error(w, fmt.Sprintf("API error: %v", err), http.StatusInternalServerError)
return
}
writeJSON(w, resp)
}
}
// HandlePass handles the /pass/{userId} endpoint
func HandlePass(client *tinder.Client) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
path := strings.TrimPrefix(r.URL.Path, "/pass/")
if path == "" {
http.Error(w, "User ID is required", http.StatusBadRequest)
return
}
resp, err := client.PassUser(path)
if err != nil {
http.Error(w, fmt.Sprintf("API error: %v", err), http.StatusInternalServerError)
return
}
writeJSON(w, resp)
}
}
// HandleGetRecs handles the /v2/recs/core endpoint
func HandleGetRecs(client *tinder.Client) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
locale := r.URL.Query().Get("locale")
resp, err := client.GetRecommendations(locale)
if err != nil {
http.Error(w, fmt.Sprintf("API error: %v", err), http.StatusInternalServerError)
return
}
writeJSON(w, resp)
}
}