-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: get extrafields form the API #568
Conversation
BoolExtraField, | ||
EnumExtraField, | ||
TextExtraField, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@florimondmanca c'est ici que j'ai le plus de mal.
De ce que je comprends tous les handlers ne retournent pas des entities mais des view. C'est bien ça ?
Donc ma logique était de créer une ExtraFieldView.
Je m'interroge sur le meilleur moyen de passer d'un Extra_Field à un Extra_FieldView .
Est-ce que le parse_extra_fields
est le bon moyen ?
Ma première approche était de transformer un ExtraField en ExtraFieldView en faisant un mapping manuel qui aurait ressemblé à :
ExtraFieldView(
title = extra_field.title,
name = extra_field.name,
....
)
Sauf que ExtraFieldView n'est pas instanciable.
Donc j'ai recopié ce qui se faisant dans le fichier d'entitée de l'ExtraField
De ce que je comprends en lisant la doc de parse_obj_as
c'est une fonction qui permet de convertir n'importe quelle classe en un type donné. Ici ExraFieldView
Est-ce que c'est la bonne approche ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que tu pourrais définir la view explicitement, non ? "Qu'est-ce que je veux renvoyer à mon API"
class ExtraFieldView(BaseModel):
type: ExtraFieldType
name: str
title: str
# Etc...
data: dict
Ensuite tu les construis explicitement dans le handler de GetAllExtraFields
async def get_all_extra_fields(query: GetAllExtraFields) -> List[ExtraFieldView]:
repository = resolve(ExtraFieldRepository)
extra_fields = await repository.get_all(query.organization_id)
return [
ExtraFieldView(
type=extra_field.type,
name=extra_field.name,
title=extra_field.title,
# Etc...
data=extra_field.data,
) for extra_field in extra_fields
]
faf80ec
to
430fb75
Compare
siret_match = await bus.execute(CreateOrganizationFactory.build()) | ||
|
||
text_extra_field_title = "mon champs complémentaire" | ||
text_extra_field_name = "mon champs complémentaire" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dans l'esprit de ce qu'est name
, ici tu pourrais utiliser "my_extra_field"
BoolExtraField, | ||
EnumExtraField, | ||
TextExtraField, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que tu pourrais définir la view explicitement, non ? "Qu'est-ce que je veux renvoyer à mon API"
class ExtraFieldView(BaseModel):
type: ExtraFieldType
name: str
title: str
# Etc...
data: dict
Ensuite tu les construis explicitement dans le handler de GetAllExtraFields
async def get_all_extra_fields(query: GetAllExtraFields) -> List[ExtraFieldView]:
repository = resolve(ExtraFieldRepository)
extra_fields = await repository.get_all(query.organization_id)
return [
ExtraFieldView(
type=extra_field.type,
name=extra_field.name,
title=extra_field.title,
# Etc...
data=extra_field.data,
) for extra_field in extra_fields
]
ac40141
to
39058e8
Compare
rel #562
Cette PR :
extra_fields
à la réponse de la route/datasets/filters
si uncatalog_id
est renseigné comme query param