-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Api: Get one movie/package/extra (#15)
- Loading branch information
Showing
26 changed files
with
384 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::error_handling::{ApiError, ApiResult}; | ||
use crate::services; | ||
use domain::models::file::File; | ||
use infrastructure::Database; | ||
use rocket::serde::json::Json; | ||
use rocket::serde::uuid::Uuid; | ||
use rocket_okapi::okapi::openapi3::OpenApi; | ||
use rocket_okapi::settings::OpenApiSettings; | ||
use rocket_okapi::{openapi, openapi_get_routes_spec}; | ||
|
||
pub fn get_routes_and_docs(settings: &OpenApiSettings) -> (Vec<rocket::Route>, OpenApi) { | ||
openapi_get_routes_spec![settings: get_file] | ||
} | ||
|
||
/// Get a Single File | ||
#[openapi(tag = "Files")] | ||
#[get("/<uuid>")] | ||
async fn get_file(db: Database, uuid: Uuid) -> ApiResult<File> { | ||
db.run(move |conn| services::file::find(&uuid, conn)) | ||
.await | ||
.map_or_else(|e| Err(ApiError::from(e)), |v| Ok(Json(v))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub mod artists; | ||
pub mod extras; | ||
pub mod files; | ||
pub mod images; | ||
pub mod index; | ||
pub mod movies; | ||
pub mod packages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::error_handling::{ApiError, ApiResult}; | ||
use crate::responses::package::PackageResponse; | ||
use crate::services; | ||
use infrastructure::Database; | ||
use rocket::serde::json::Json; | ||
use rocket_okapi::okapi::openapi3::OpenApi; | ||
use rocket_okapi::settings::OpenApiSettings; | ||
use rocket_okapi::{openapi, openapi_get_routes_spec}; | ||
|
||
pub fn get_routes_and_docs(settings: &OpenApiSettings) -> (Vec<rocket::Route>, OpenApi) { | ||
openapi_get_routes_spec![settings: get_package] | ||
} | ||
|
||
/// Get a Single Package | ||
#[openapi(tag = "Package")] | ||
#[get("/<slug_or_uuid>")] | ||
async fn get_package(db: Database, slug_or_uuid: String) -> ApiResult<PackageResponse> { | ||
db.run(move |conn| services::package::find(&slug_or_uuid, conn)) | ||
.await | ||
.map_or_else(|e| Err(ApiError::from(e)), |v| Ok(Json(v))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use domain::models::chapter::Chapter; | ||
use domain::models::image::Image; | ||
use rocket_okapi::okapi::schemars; | ||
use rocket_okapi::okapi::schemars::JsonSchema; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize, JsonSchema)] | ||
pub struct ChapterResponse { | ||
#[serde(flatten)] | ||
pub chapter: Chapter, | ||
pub thumbnail: Option<Image>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod artist; | ||
pub mod extra_creation; | ||
pub mod movie_creation; | ||
pub mod chapter; | ||
pub mod extra; | ||
pub mod movie; | ||
pub mod package; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use domain::models::{artist::Artist, image::Image, package::Package}; | ||
use rocket_okapi::okapi::schemars; | ||
use rocket_okapi::okapi::schemars::JsonSchema; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize, JsonSchema)] | ||
pub struct PackageResponse { | ||
#[serde(flatten)] | ||
pub package: Package, | ||
pub poster: Option<Image>, | ||
#[schemars(skip)] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub artist: Option<Option<Artist>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use diesel::prelude::*; | ||
use domain::models::{chapter::Chapter, image::Image}; | ||
use rocket::serde::uuid::Uuid; | ||
|
||
use crate::responses::chapter::ChapterResponse; | ||
|
||
pub fn find_by_movie( | ||
movie_uuid: &Uuid, | ||
connection: &mut PgConnection, | ||
) -> Result<Vec<ChapterResponse>, diesel::result::Error> { | ||
use domain::schema::chapters::dsl::*; | ||
use domain::schema::images::dsl::*; | ||
|
||
let movie_chapters: Vec<(Chapter, Option<Image>)> = chapters | ||
.filter(movie_id.eq(movie_uuid)) | ||
.left_join(images) | ||
.order(start_time.asc()) | ||
.get_results(connection)?; | ||
|
||
Ok(movie_chapters | ||
.iter() | ||
.map(move |(chapter, thumbnail)| -> ChapterResponse { | ||
ChapterResponse { | ||
chapter: chapter.clone(), | ||
thumbnail: thumbnail.clone(), | ||
} | ||
}) | ||
.collect()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod artist; | ||
pub mod chapter; | ||
pub mod chapters; | ||
pub mod extra; | ||
pub mod file; | ||
pub mod image; | ||
|
Oops, something went wrong.