Skip to content

Commit

Permalink
fix: обновление импорта
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlexeyn committed Dec 9, 2024
1 parent be5ce30 commit 2a1bbc1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/routers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fastapi import APIRouter, HTTPException, UploadFile
from fastapi.params import Depends
from fastapi.responses import JSONResponse
from pymongo.errors import BulkWriteError

from database import db
from schemas.user import User
Expand Down Expand Up @@ -85,9 +86,11 @@ async def import_database(file: UploadFile):

# Вставка данных в коллекцию
collection = db[collection_name]
collection.insert_many(documents)
await collection.insert_many(documents)

except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON file")
except BulkWriteError as e:
raise HTTPException(status_code=400, detail="Идентичные данные уже существуют")

return {"message": "Database imported successfully"}

0 comments on commit 2a1bbc1

Please sign in to comment.