40 lines
No EOL
845 B
Go
40 lines
No EOL
845 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"veza-backend-api/internal/services"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var SearchHandlersInstance *SearchHandlers
|
|
|
|
type SearchHandlers struct {
|
|
searchService *services.SearchService
|
|
}
|
|
|
|
func NewSearchHandlers(searchService *services.SearchService) {
|
|
SearchHandlersInstance = &SearchHandlers{
|
|
searchService: searchService,
|
|
}
|
|
}
|
|
|
|
// Search performs a full-text search across tracks, users, and playlists
|
|
func (sh *SearchHandlers) Search(c *gin.Context) {
|
|
query := c.Query("q")
|
|
if query == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Search query is required"})
|
|
return
|
|
}
|
|
|
|
types := c.QueryArray("type")
|
|
|
|
results, err := sh.searchService.Search(query, types)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, results)
|
|
} |