extern crate diesel; use actix_web::{get, web, HttpResponse, Responder}; use crate::diesel::prelude::*; use crate::lib::establish_connection; use crate::model::*; #[get("/subtitles/list")] async fn list_all() -> impl Responder { use crate::schema::films::dsl::*; use crate::schema::subtitles::dsl::*; use crate::schema::languages::dsl::*; let connection = establish_connection().await; let results = subtitles .inner_join(films) .inner_join(languages) .load::<(Subtitle, Film, Language)>(&connection).expect("Error loading subtitles"); let mut s: Vec = vec![]; let mut f: Vec = vec![]; let mut l: Vec = vec![]; for r in results { s.push(SubtitleTrimmed::from(r.0)); let f_id = r.1.id; let l_id = r.2.id; if !f.iter().any(|film| film.id == f_id) { f.push(r.1); } if !l.iter().any(|language| language.id == l_id) { l.push(r.2); } } HttpResponse::Ok().json(SubtitleOutV1{ subtitles: s, films: f, languages: l }) } pub fn init_routes(config: &mut web::ServiceConfig) { config.service(list_all); }