Skip to content

Commit

Permalink
Merge pull request #199 from prefeitura-rio/frontend/patient-using-bi…
Browse files Browse the repository at this point in the history
…g-query-data

Fix: JSON Serialization + new User field
  • Loading branch information
TanookiVerde committed Aug 16, 2024
2 parents 261365f + 191be42 commit 3c1357c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
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";"""

0 comments on commit 3c1357c

Please sign in to comment.