feat: add SongSearchService and GET /songs?q= search endpoint
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
mod routes;
|
||||
|
||||
use axum::{Router, routing::{get, post}};
|
||||
use common::SongService;
|
||||
use common::{SongSearchService, SongService};
|
||||
use persistence::SqliteRepositoryFactory;
|
||||
use routes::songs::{create_song, delete_song, get_song, list_songs};
|
||||
use routes::songs::{create_song, delete_song, get_song, list_songs, update_song};
|
||||
use routes::tabs::{AppState, parse_tab};
|
||||
use std::sync::Arc;
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
@@ -18,12 +18,14 @@ async fn main() {
|
||||
let repo = SqliteRepositoryFactory::create(&database_url)
|
||||
.await
|
||||
.expect("failed to connect to database");
|
||||
let songs = SongService::new(Box::new(repo));
|
||||
let songs = SongService::new(Box::new(repo.clone()));
|
||||
let search = SongSearchService::new(Box::new(repo));
|
||||
|
||||
let state = Arc::new(AppState {
|
||||
fetcher: Box::new(UgTabFetcher::new()),
|
||||
parser: Box::new(UgHtmlParser),
|
||||
songs,
|
||||
search,
|
||||
});
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
@@ -34,7 +36,7 @@ async fn main() {
|
||||
let app = Router::new()
|
||||
.route("/tabs/parse", post(parse_tab))
|
||||
.route("/songs", post(create_song).get(list_songs))
|
||||
.route("/songs/{id}", get(get_song).delete(delete_song))
|
||||
.route("/songs/{id}", get(get_song).delete(delete_song).patch(update_song))
|
||||
.layer(cors)
|
||||
.with_state(state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user