Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: JSON Serialization + new User field #199

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/datalake/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
import json
import pandas as pd
from typing import Callable
from loguru import logger


REGISTERED_FORMATTERS = {}


Expand Down Expand Up @@ -77,9 +77,9 @@ def flatten(
for key, value in flattened.items():
updated_record[f"{field}__{key}"] = value
else:
updated_record[field] = str(content)
updated_record[field] = json.dumps(content)
elif isinstance(content, list) and depth >= list_max_depth:
updated_record[field] = str(content)
updated_record[field] = json.dumps(content)
else:
updated_record[field] = content

Expand Down
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class Meta:
class User(Model):
id = fields.IntField(pk=True)
username = fields.CharField(max_length=255, unique=True)
role = fields.CharField(max_length=255, null=True)
name = fields.CharField(max_length=255, null=True)
cpf = fields.CharField(max_length=11, unique=True, null=True, validators=[CPFValidator()])
email = fields.CharField(max_length=255, unique=True)
Expand Down
1 change: 1 addition & 0 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def get_user_info(

return {
"name": user.name,
"role": user.role,
"email": user.email,
"username": user.username,
"cpf": cpf,
Expand Down
1 change: 1 addition & 0 deletions app/types/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class UserInfo(BaseModel):
cpf: Optional[str]
username: Optional[str]
email: Optional[str]
role: Optional[str]

class Professional(BaseModel):
name: str
Expand Down
12 changes: 12 additions & 0 deletions migrations/app/25_20240816161616_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "user" ADD "role" VARCHAR(255);"""


async def downgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "user" DROP COLUMN "role";"""
Loading