- Tests complets pour search_handlers.go (6 tests)
- Tests complets pour comment_handler.go (12 tests)
- Interfaces créées pour permettre le mock (SearchServiceInterface, CommentServiceInterface)
- Couverture actuelle: 30.6% (objectif: 80%)
Files: veza-backend-api/internal/handlers/search_handlers.go
veza-backend-api/internal/handlers/search_handlers_test.go
veza-backend-api/internal/handlers/comment_handler.go
veza-backend-api/internal/handlers/comment_handler_test.go
VEZA_ROADMAP.json
Hours: 16 estimated, 17 actual
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"veza-backend-api/internal/services"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var SearchHandlersInstance *SearchHandlers
|
|
|
|
// SearchServiceInterface defines the interface for search operations
|
|
// This allows for easier testing with mocks
|
|
type SearchServiceInterface interface {
|
|
Search(query string, types []string) (*services.SearchResult, error)
|
|
}
|
|
|
|
type SearchHandlers struct {
|
|
searchService SearchServiceInterface
|
|
}
|
|
|
|
func NewSearchHandlers(searchService *services.SearchService) {
|
|
SearchHandlersInstance = &SearchHandlers{
|
|
searchService: searchService,
|
|
}
|
|
}
|
|
|
|
// NewSearchHandlersWithInterface creates new search handlers with an interface (for testing)
|
|
func NewSearchHandlersWithInterface(searchService SearchServiceInterface) *SearchHandlers {
|
|
return &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
|
|
}
|
|
|
|
RespondSuccess(c, http.StatusOK, results)
|
|
}
|