refactor: update response model and location handling

- Renamed RawResponse model to Response for clarity.
- Changed location field type from String to JSON in the Response model.
- Updated result handling logic to store location as a JSON object instead of a string.
This commit is contained in:
Miu Li 2025-06-16 06:47:40 +08:00
parent 7cb36eb1af
commit ce020a5674
2 changed files with 3 additions and 3 deletions

2
app.py
View File

@ -130,7 +130,7 @@ async def result(request: Request, scale_id: str, db: Session = Depends(get_db))
scale_id=scale_id,
user_agent=request.headers.get("user-agent", "Unknown"),
ip_address=ip,
location=json.dumps(location) if location else None,
location=location,
raw_response=dict(form_data),
sum_response=responses,
avg_response=average

View File

@ -15,13 +15,13 @@ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
class RawResponse(Base):
class Response(Base):
__tablename__ = "responses"
id = Column(Integer, primary_key=True, index=True)
scale_id = Column(String, index=True)
user_agent = Column(String)
ip_address = Column(String)
location = Column(String)
location = Column(JSON)
raw_response = Column(JSON)
sum_response = Column(JSON)
avg_response = Column(JSON)