mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
- Add refresh token support with 30-day expiry - Implement automatic token rotation on refresh - Add new endpoints: /auth/refresh, /auth/revoke-token, /auth/revoke-all-tokens - Reduce access token lifetime to 1 hour for better security - Store refresh tokens in user document with metadata - Add support for token cleanup and management - Update login flow to return both access and refresh tokens - Maintain backward compatibility with existing auth methods
46 lines
955 B
Go
46 lines
955 B
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"neomovies-api/pkg/models"
|
|
"neomovies-api/pkg/services"
|
|
)
|
|
|
|
type SearchHandler struct {
|
|
tmdbService *services.TMDBService
|
|
}
|
|
|
|
func NewSearchHandler(tmdbService *services.TMDBService) *SearchHandler {
|
|
return &SearchHandler{
|
|
tmdbService: tmdbService,
|
|
}
|
|
}
|
|
|
|
func (h *SearchHandler) MultiSearch(w http.ResponseWriter, r *http.Request) {
|
|
query := r.URL.Query().Get("query")
|
|
if query == "" {
|
|
http.Error(w, "Query parameter is required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
page := getIntQuery(r, "page", 1)
|
|
language := r.URL.Query().Get("language")
|
|
if language == "" {
|
|
language = "ru-RU"
|
|
}
|
|
|
|
results, err := h.tmdbService.SearchMulti(query, page, language)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(models.APIResponse{
|
|
Success: true,
|
|
Data: results,
|
|
})
|
|
}
|