Joining when sorting by size.

This commit is contained in:
Roland 2023-05-16 14:59:35 -06:00
parent 7c1cc07365
commit ac06a9b8b2
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 8 additions and 0 deletions

View file

@ -382,6 +382,7 @@ ORDER_GROUP_BYS = {
'size': 'fg.size, fg.primary_path',
'-size': 'fg.size, fg.primary_path',
}
FILE_ORDERS = ['size', '-size']
def search_archives(search_str: str, domain: str, limit: int, offset: int, order: str, tag_names: List[str],
@ -409,6 +410,8 @@ def search_archives(search_str: str, domain: str, limit: int, offset: int, order
try:
order_by = ARCHIVE_ORDERS[order]
group_by = f'{group_by}, {ORDER_GROUP_BYS[order]}'
if order in FILE_ORDERS:
joins = ['LEFT JOIN file_group fg ON fg.id = a.file_group_id']
except KeyError:
raise InvalidOrderBy(f'Invalid order by: {order}')

View file

@ -25,6 +25,11 @@ def test_archives_search_order(test_session, archive_directory, archive_factory,
if not response.status_code == HTTPStatus.OK:
raise AssertionError(str(response.json))
data = {'search_str': None, 'order_by': order_by}
request, response = test_client.post('/api/archive/search', content=json.dumps(data))
if not response.status_code == HTTPStatus.OK:
raise AssertionError(str(response.json))
def test_archives_search(test_session, archive_directory, archive_factory, test_client):
"""Archives can be searched by their title and their contents."""