Skip to content

Commit f725f13

Browse files
committed
refactor: place domain logic into controller
1 parent 7958e54 commit f725f13

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# This file is part of the QuestionPy SDK. (https://questionpy.org)
22
# The QuestionPy SDK is free software released under terms of the MIT license. See LICENSE.md.
33
# (c) Technische Universität Berlin, innoCampus <[email protected]>
4-
54
from typing import TYPE_CHECKING
65

7-
from questionpy_common.manifest import Manifest
86
from questionpy_sdk.webserver.controllers.base import BaseController
97
from questionpy_server.worker import PackageFileData
108

@@ -13,10 +11,12 @@
1311

1412

1513
class FileController(BaseController):
16-
async def get_static_file(self, path: str) -> PackageFileData:
14+
async def get_static_file(self, namespace: str, short_name: str, path: str) -> PackageFileData:
15+
if self._manifest.namespace != namespace or self._manifest.short_name != short_name:
16+
# TODO: Support static files in non-main packages by using namespace and short_name.
17+
msg = "Static file retrieval from non-main packages is not supported yet."
18+
raise ValueError(msg)
19+
1720
worker: Worker
1821
async with self._worker_pool.get_worker(self._package_location, 0, None) as worker:
1922
return await worker.get_static_file(path)
20-
21-
def get_manifest(self) -> Manifest:
22-
return self._manifest

questionpy_sdk/webserver/routes/file.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ async def get(self) -> web.Response:
2121
short_name = self.request.match_info["short_name"]
2222
path = self.request.match_info["path"]
2323

24-
manifest = self.controller.get_manifest()
25-
if manifest.namespace != namespace or manifest.short_name != short_name:
26-
# TODO: Support static files in non-main packages by using namespace and short_name.
27-
raise HTTPNotImplemented(text="Static file retrieval from non-main packages is not supported yet.")
28-
2924
try:
30-
file = await self.controller.get_static_file(path)
25+
file = await self.controller.get_static_file(namespace, short_name, path)
3126
except FileNotFoundError as e:
3227
raise web.HTTPNotFound(text="File not found.") from e
28+
except ValueError as e:
29+
raise HTTPNotImplemented(text=str(e)) from e
3330

3431
return web.Response(
3532
body=file.data,

0 commit comments

Comments
 (0)