Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
media-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaflix
media-backend
Commits
9059eaa1
Verified
Commit
9059eaa1
authored
4 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Implement preview into the dtos
parent
0aebdfbf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/dto.rs
+7
-3
7 additions, 3 deletions
src/dto.rs
src/dto_helpers.rs
+16
-2
16 additions, 2 deletions
src/dto_helpers.rs
src/models.rs
+11
-0
11 additions, 0 deletions
src/models.rs
src/schema.rs
+11
-0
11 additions, 0 deletions
src/schema.rs
with
45 additions
and
5 deletions
src/dto.rs
+
7
−
3
View file @
9059eaa1
...
...
@@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
use
crate
::
config
::
Config
;
use
crate
::
models
::
*
;
use
crate
::
dto_helpers
::
absolute_url
;
#[derive(Serialize,
Deserialize,
PartialEq,
Debug)]
#[serde(rename_all
=
"camelCase"
)]
...
...
@@ -19,6 +20,7 @@ pub struct TitleDto {
pub
images
:
Vec
<
ImageDto
>
,
pub
media
:
Vec
<
MediaDto
>
,
pub
subtitles
:
Vec
<
SubtitleDto
>
,
pub
preview
:
Option
<
String
>
,
pub
created_at
:
chrono
::
DateTime
<
chrono
::
Utc
>
,
pub
updated_at
:
chrono
::
DateTime
<
chrono
::
Utc
>
,
}
...
...
@@ -34,6 +36,7 @@ impl TitleDto {
images
:
Vec
<
ImageDto
>
,
media
:
Vec
<
MediaDto
>
,
subtitles
:
Vec
<
SubtitleDto
>
,
preview
:
Option
<
String
>
)
->
Self
{
TitleDto
{
ids
:
TitleIdDto
{
...
...
@@ -54,6 +57,7 @@ impl TitleDto {
images
,
media
,
subtitles
,
preview
,
created_at
:
src
.created_at
,
updated_at
:
src
.updated_at
,
}
...
...
@@ -200,7 +204,7 @@ impl ImageDto {
Ok
(
ImageDto
{
kind
:
src
.kind
,
mime
:
src
.mime
,
src
:
config
.static_url
.join
(
src
.src
.as_str
())
?
.into_string
()
,
src
:
absolute_url
(
config
,
src
.src
)
?
,
})
}
}
...
...
@@ -220,7 +224,7 @@ impl MediaDto {
mime
:
src
.mime
,
codecs
:
src
.codecs
,
languages
:
src
.languages
,
src
:
config
.static_url
.join
(
src
.src
.as_str
())
?
.into_string
()
,
src
:
absolute_url
(
config
,
src
.src
)
?
,
})
}
}
...
...
@@ -258,7 +262,7 @@ impl SubtitleDto {
language
:
src
.language
,
region
:
src
.region
,
specifier
:
src
.specifier
,
src
:
config
.static_url
.join
(
src
.src
.as_str
())
?
.into_string
()
,
src
:
absolute_url
(
config
,
src
.src
)
?
,
})
}
}
...
...
This diff is collapsed.
Click to expand it.
src/dto_helpers.rs
+
16
−
2
View file @
9059eaa1
...
...
@@ -4,6 +4,7 @@ use crate::config::Config;
use
crate
::
dto
::
*
;
use
crate
::
models
::
*
;
use
crate
::
schema
::
*
;
use
url
::
ParseError
;
pub
fn
load_title
(
db
:
&
PgConnection
,
config
:
&
Config
,
title
:
Title
)
->
QueryResult
<
TitleDto
>
{
let
title_names
:
Vec
<
TitleName
>
=
TitleName
::
belonging_to
(
&
title
)
...
...
@@ -24,11 +25,14 @@ pub fn load_title(db: &PgConnection, config: &Config, title: Title) -> QueryResu
.load
::
<
TitleMedium
>
(
db
)
?
;
let
title_subtitles
:
Vec
<
TitleSubtitle
>
=
TitleSubtitle
::
belonging_to
(
&
title
)
.load
::
<
TitleSubtitle
>
(
db
)
?
;
let
title_preview
:
TitlePreview
=
TitlePreview
::
belonging_to
(
&
title
)
.first
::
<
TitlePreview
>
(
db
)
?
;
Ok
(
process_title
(
config
,
title
,
title_names
,
title_descriptions
,
title_cast
,
title_genres
,
title_ratings
,
title_images
,
title_media
,
title_subtitles
,
title_preview
,
))
}
...
...
@@ -59,6 +63,8 @@ pub fn load_titles(db: &PgConnection, config: &Config, titles: Vec<Title>) -> Qu
let
title_subtitles
:
Vec
<
Vec
<
TitleSubtitle
>>
=
TitleSubtitle
::
belonging_to
(
&
titles
)
.load
::
<
TitleSubtitle
>
(
db
)
?
.grouped_by
(
&
titles
);
let
title_preview
:
Vec
<
TitlePreview
>
=
TitlePreview
::
belonging_to
(
&
titles
)
.load
::
<
TitlePreview
>
(
db
)
?
;
Ok
(
titles
.into_iter
()
.zip
(
title_names
)
.zip
(
title_descriptions
)
...
...
@@ -68,15 +74,17 @@ pub fn load_titles(db: &PgConnection, config: &Config, titles: Vec<Title>) -> Qu
.zip
(
title_images
)
.zip
(
title_media
)
.zip
(
title_subtitles
)
.zip
(
title_preview
)
.map
(|
tuple
|
{
let
((((((((
title
,
akas
),
descriptions
),
let
((((((((
(
title
,
akas
),
descriptions
),
cast
),
genres
),
ratings
),
images
),
media
),
subtitles
)
=
tuple
;
images
),
media
),
subtitles
)
,
preview
)
=
tuple
;
process_title
(
config
,
title
,
akas
,
descriptions
,
cast
,
genres
,
ratings
,
images
,
media
,
subtitles
,
preview
,
)
})
.collect
::
<
Vec
<
TitleDto
>>
())
}
...
...
@@ -86,6 +94,7 @@ fn process_title(
title
:
Title
,
names
:
Vec
<
TitleName
>
,
descriptions
:
Vec
<
TitleDescription
>
,
cast
:
Vec
<
(
TitleCast
,
Person
)
>
,
genres
:
Vec
<
(
TitleGenre
,
Genre
)
>
,
ratings
:
Vec
<
TitleRating
>
,
images
:
Vec
<
TitleImage
>
,
media
:
Vec
<
TitleMedium
>
,
subtitles
:
Vec
<
TitleSubtitle
>
,
preview
:
TitlePreview
,
)
->
TitleDto
{
TitleDto
::
of
(
title
,
...
...
@@ -114,5 +123,10 @@ fn process_title(
subtitles
.into_iter
()
.filter_map
(|
src
|
{
SubtitleDto
::
of
(
src
,
&
config
)
.ok
()
})
.collect
::
<
Vec
<
_
>>
(),
preview
.src
.and_then
(|
preview
|
absolute_url
(
config
,
preview
)
.ok
())
)
}
pub
fn
absolute_url
(
config
:
&
Config
,
url
:
impl
Into
<
String
>
)
->
Result
<
String
,
ParseError
>
{
config
.static_url
.join
(
url
.into
()
.as_str
())
.map
(
url
::
Url
::
into_string
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/models.rs
+
11
−
0
View file @
9059eaa1
...
...
@@ -148,6 +148,17 @@ pub struct TitleSubtitle {
pub
title_id
:
uuid
::
Uuid
,
}
#[derive(Identifiable,
Queryable,
Associations,
PartialEq,
Debug)]
#[belongs_to(Title,
foreign_key
=
"title_id"
)]
#[table_name
=
"title_previews"
]
pub
struct
TitlePreview
{
pub
id
:
uuid
::
Uuid
,
pub
src
:
Option
<
String
>
,
pub
created_at
:
chrono
::
DateTime
<
chrono
::
Utc
>
,
pub
updated_at
:
chrono
::
DateTime
<
chrono
::
Utc
>
,
pub
title_id
:
uuid
::
Uuid
,
}
#[derive(Identifiable,
Queryable,
PartialEq,
Debug)]
#[table_name
=
"titles"
]
pub
struct
Title
{
...
...
This diff is collapsed.
Click to expand it.
src/schema.rs
+
11
−
0
View file @
9059eaa1
...
...
@@ -131,6 +131,16 @@ table! {
}
}
table!
{
title_previews
(
id
)
{
id
->
Uuid
,
src
->
Nullable
<
Text
>
,
created_at
->
Timestamptz
,
updated_at
->
Timestamptz
,
title_id
->
Uuid
,
}
}
table!
{
titles
(
id
)
{
id
->
Uuid
,
...
...
@@ -156,6 +166,7 @@ joinable!(title_media -> titles (title_id));
joinable!
(
title_names
->
titles
(
title_id
));
joinable!
(
title_ratings
->
titles
(
title_id
));
joinable!
(
title_subtitles
->
titles
(
title_id
));
joinable!
(
title_previews
->
titles
(
title_id
));
allow_tables_to_appear_in_same_query!
(
genres
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment