Initialize Tinder API Wrapper with server configuration and Docker setup
This commit is contained in:
76
cmd/server/handlers/core.go
Normal file
76
cmd/server/handlers/core.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user