Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Define schema for response

Daoud Clarkec980b9138217
diff --git a/mwmbl/crawler/app.py b/mwmbl/crawler/app.py
index e1ecbfd..6d51a86 100644
--- a/mwmbl/crawler/app.py
+++ b/mwmbl/crawler/app.py
@@ -14,7 +14,7 @@ from fastapi import HTTPException
from ninja import NinjaAPI, Schema
from redis import Redis
-from mwmbl.crawler.batch import Batch, NewBatchRequest, HashedBatch, Results
+from mwmbl.crawler.batch import Batch, NewBatchRequest, HashedBatch, Results, PostResultsResponse, Error
from mwmbl.crawler.stats import MwmblStats, StatsManager
from mwmbl.database import Database
from mwmbl.indexer.batch_cache import BatchCache
@@ -173,7 +173,7 @@ def create_router(batch_cache: BatchCache, queued_batches: RedisURLQueue, versio
'status': 'ok'
}
- @router.post('/results')
+ @router.post('/results', response={200: PostResultsResponse, 401: Error})
def post_results(request, results: Results):
# Check the API key
api_key = ApiKey.objects.filter(key=results.api_key).first()
diff --git a/mwmbl/crawler/batch.py b/mwmbl/crawler/batch.py
index 433fa2e..994ce76 100644
--- a/mwmbl/crawler/batch.py
+++ b/mwmbl/crawler/batch.py
@@ -72,3 +72,12 @@ class Result(Schema):
class Results(Schema):
api_key: str
results: list[Result]
+
+
+class PostResultsResponse(Schema):
+ status: str
+ url: str
+
+
+class Error(Schema):
+ message: str