Files
neomovies-api/pkg/handlers/search.go
factory-droid[bot] ea3159fb8e feat: implement JWT refresh token mechanism and improve auth
- 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
2025-09-28 11:37:56 +00:00

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,
})
}