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

feat: get extrafields form the API #568

Merged
merged 4 commits into from
Feb 27, 2023
Merged

feat: get extrafields form the API #568

merged 4 commits into from
Feb 27, 2023

Conversation

Volubyl
Copy link
Collaborator

@Volubyl Volubyl commented Feb 23, 2023

rel #562

Cette PR :

  • ajoute les extra_fields à la réponse de la route /datasets/filters si un catalog_id est renseigné comme query param

BoolExtraField,
EnumExtraField,
TextExtraField,
)
Copy link
Collaborator Author

@Volubyl Volubyl Feb 23, 2023

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 ?

Copy link
Collaborator

@florimondmanca florimondmanca Feb 23, 2023

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
    ]

siret_match = await bus.execute(CreateOrganizationFactory.build())

text_extra_field_title = "mon champs complémentaire"
text_extra_field_name = "mon champs complémentaire"
Copy link
Collaborator

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,
)
Copy link
Collaborator

@florimondmanca florimondmanca Feb 23, 2023

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
    ]

@Volubyl Volubyl merged commit b322064 into master Feb 27, 2023
@Volubyl Volubyl deleted the feat-display-extrafield branch February 27, 2023 08:57
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants