Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
c1dcb73f
Commit
c1dcb73f
authored
Jul 03, 2018
by
Hugo Beauzée-Luyssen
Browse files
Show: Split sorting in a separate function
Also ensure that sorting by release date is functionnal
parent
fa9de2ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Show.cpp
View file @
c1dcb73f
...
...
@@ -203,7 +203,14 @@ std::shared_ptr<Show> Show::create( MediaLibraryPtr ml, const std::string& name
Query
<
IShow
>
Show
::
listAll
(
MediaLibraryPtr
ml
,
const
QueryParameters
*
params
)
{
std
::
string
req
=
"FROM "
+
policy
::
ShowTable
::
Name
+
" ORDER BY "
;
std
::
string
req
=
"FROM "
+
policy
::
ShowTable
::
Name
;
req
+=
orderBy
(
params
);
return
make_query
<
Show
,
IShow
>
(
ml
,
"*"
,
std
::
move
(
req
)
);
}
std
::
string
Show
::
orderBy
(
const
QueryParameters
*
params
)
{
std
::
string
req
=
" ORDER BY "
;
SortingCriteria
sort
=
params
!=
nullptr
?
params
->
sort
:
SortingCriteria
::
Default
;
switch
(
sort
)
{
...
...
@@ -219,7 +226,7 @@ Query<IShow> Show::listAll( MediaLibraryPtr ml, const QueryParameters* params )
}
if
(
params
!=
nullptr
&&
params
->
desc
==
true
)
req
+=
" DESC"
;
return
make_query
<
Show
,
IShow
>
(
ml
,
"*"
,
req
)
;
return
req
;
}
}
src/Show.h
View file @
c1dcb73f
...
...
@@ -74,6 +74,9 @@ class Show : public IShow, public DatabaseHelpers<Show, policy::ShowTable>
static
Query
<
IShow
>
listAll
(
MediaLibraryPtr
ml
,
const
QueryParameters
*
params
);
private:
static
std
::
string
orderBy
(
const
QueryParameters
*
params
);
protected:
MediaLibraryPtr
m_ml
;
...
...
test/unittest/ShowTests.cpp
View file @
c1dcb73f
...
...
@@ -202,8 +202,11 @@ TEST_F( Shows, SetEpisodeTvdbId )
TEST_F
(
Shows
,
ListAll
)
{
auto
show1
=
ml
->
createShow
(
"aaaa"
);
show1
->
setReleaseDate
(
5
);
auto
show2
=
ml
->
createShow
(
"zzzz"
);
show2
->
setReleaseDate
(
1
);
auto
show3
=
ml
->
createShow
(
"pppp"
);
show3
->
setReleaseDate
(
10
);
auto
shows
=
ml
->
shows
(
nullptr
)
->
all
();
ASSERT_EQ
(
3u
,
shows
.
size
()
);
...
...
@@ -217,6 +220,14 @@ TEST_F( Shows, ListAll )
ASSERT_EQ
(
show2
->
id
(),
shows
[
0
]
->
id
()
);
ASSERT_EQ
(
show3
->
id
(),
shows
[
1
]
->
id
()
);
ASSERT_EQ
(
show1
->
id
(),
shows
[
2
]
->
id
()
);
params
.
sort
=
SortingCriteria
::
ReleaseDate
;
params
.
desc
=
false
;
shows
=
ml
->
shows
(
&
params
)
->
all
();
ASSERT_EQ
(
3u
,
shows
.
size
()
);
ASSERT_EQ
(
show2
->
id
(),
shows
[
0
]
->
id
()
);
ASSERT_EQ
(
show1
->
id
(),
shows
[
1
]
->
id
()
);
ASSERT_EQ
(
show3
->
id
(),
shows
[
2
]
->
id
()
);
}
TEST_F
(
Shows
,
ListEpisodes
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment