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/save notebook focus pe 2 #1919

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d1a3df0
chore: rend le creator nullable
lionelB Jul 11, 2023
1ba66e9
chore: deplace notebook_situations
lionelB Jul 11, 2023
d6c465c
fixup! chore: rend le creator nullable
lionelB Jul 11, 2023
ad5e5fa
feat: add diff_contraintes
lionelB Jul 11, 2023
9b9faa5
feat: add diff contraintes
lionelB Jul 11, 2023
ef26399
fixup! chore: rend le creator nullable
lionelB Jul 12, 2023
462fd7c
feat: regarde les différences entre les contraintes FT et Cdb
lionelB Jul 12, 2023
8e13ab4
chore: renomme ENABLE_SITUATION_API en ENABLE_PEIO_API
lionelB Jul 12, 2023
cd656c5
fixup! chore: deplace notebook_situations
lionelB Jul 12, 2023
704f53c
refactor: na pas utiliser de templte pour notebook_situation
lionelB Jul 12, 2023
f84d651
refactor: ajoute les differences de focus
lionelB Jul 12, 2023
de05885
feat: synchro des objectif fait ou abandonnée
lionelB Jul 17, 2023
ebc3611
chore: update schema
lionelB Jul 17, 2023
0cba4d4
test: fix existing tests
lionelB Jul 17, 2023
91ca080
refactor: rename refresh_notebook_situation to update_notebook
lionelB Jul 18, 2023
ee9ed66
feat: sauve les infos du diagnostic pe dans cdb
lionelB Jul 19, 2023
bee973d
Merge branch 'main' into feat/save-notebook-focus-pe
Jul 19, 2023
ae2de27
feat: ajout de la date pour la création des objectifs
lionelB Jul 19, 2023
5fe470b
fix: refactor: rename feature flag
lionelB Jul 20, 2023
9390261
ci: installe les dépendances pour les tests JS
jonathanperret Jul 20, 2023
620b5d5
fix: conflicts
HadrienMP Jul 24, 2023
dbbec89
fix: retours de pr
HadrienMP Jul 25, 2023
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
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ APP_URL=http://localhost:3000
DATABASE_URL=postgres://cdb:test@localhost:5432/carnet_de_bord
LOG_AS_JSON=false
GQL_LOG_LEVEL=INFO # graphql cient logging level
ENABLE_PE_DIAGNOSTIC_API=True
ENABLE_SYNC_CONTRAINTES=False

PE_AUTH_BASE_URL=https://entreprise.pe-qvr.fr
PE_BASE_URL=https://api.peio.pe-qvr.fr
Expand Down
3 changes: 2 additions & 1 deletion .env.test.sample
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ APP_URL=http://localhost:3001
GQL_LOG_LEVEL=INFO # graphql cient logging level
PE_AUTH_BASE_URL=https://entreprise.pe-qvr.fr
PE_BASE_URL=https://api.peio.pe-qvr.fr
ENABLE_SITUATION_API=true
ENABLE_PE_DIAGNOSTIC_API=True
ENABLE_SYNC_CONTRAINTES=False

# You can't name your test database as you want. It has to be
# carnet_de_bord otherwise you will not be able to apply
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ jobs:
- name: Install Hasura CLI
uses: ./.github/actions/hasura-cli

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{env.PYTHON_VERSION}}

- name: Setup Poetry
uses: abatilo/actions-poetry@v2.1.6
with:
poetry-version: ${{env.POETRY_VERSION}}

- name: Install Python dependencies
working-directory: ./backend
run: poetry install

- name: Run functional tests
run: |
cp .env.test.sample .env.test
Expand Down
2 changes: 1 addition & 1 deletion app/elm/Diagnostic/AllSituations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ syncWithPE notebookId responseMsg =
Extra.GraphQL.postOperation
(Diagnostic.SyncWithPE.mutation { notebookId = notebookId })
(Result.map
(.refresh_notebook_situations_from_pole_emploi
(.update_notebook_from_pole_emploi
>> Maybe.map
(\data ->
{ data_has_been_updated = data.data_has_been_updated
Expand Down
2 changes: 1 addition & 1 deletion app/elm/Diagnostic/SyncWithPE.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation ($notebookId: uuid!) {
refresh_notebook_situations_from_pole_emploi(notebookId: $notebookId) {
update_notebook_from_pole_emploi(notebookId: $notebookId) {
data_has_been_updated
has_pe_diagnostic
}
Expand Down
2 changes: 1 addition & 1 deletion backend/cdb/api/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Settings(BaseSettings):
LOG_AS_JSON: bool = True
GQL_LOG_LEVEL: str = "WARNING"

ENABLE_SITUATION_API: bool = False
ENABLE_PE_DIAGNOSTIC_API: bool = False
ENABLE_SYNC_CONTRAINTES: bool = False

SENTRY_DSN: str | None
Expand Down
96 changes: 96 additions & 0 deletions backend/cdb/api/db/crud/notebook_focus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import json
from datetime import datetime
from typing import List
from uuid import UUID

from gql import gql
from gql.client import AsyncClientSession
from pydantic import BaseModel

from cdb.api.domain.contraintes import FocusDifferences, FocusToAdd


class TargetInsertInput(BaseModel):
target: str


class TargetData(BaseModel):
data: List[TargetInsertInput]


class FocusInsertInput(BaseModel):
theme: str
notebookId: UUID
createdAt: None | datetime = None
targets: TargetData | None = None

def jsonb(self) -> dict:
return json.loads(self.json())


def to_focuses_insert_input(notebook_id: UUID, focuses: List[FocusToAdd]) -> List[dict]:
return [
FocusInsertInput(
notebookId=notebook_id,
theme=focus.theme,
createdAt=focus.created_at,
targets=TargetData(
data=[
TargetInsertInput(target=target.target) for target in focus.targets
]
),
).jsonb()
for focus in focuses
]


async def add_remove_notebook_focuses(
client: AsyncClientSession, notebook_id: UUID, focus_differences: FocusDifferences
):
mutation = gql(
"""
mutation (
$focuses_to_add: [notebook_focus_insert_input!]!
$focuses_ids_to_delete: [uuid!]!
$targets_to_add: [notebook_target_insert_input!]!
$target_ids_to_cancel: [uuid!]!
$target_ids_to_end: [uuid!]!
) {
insert_notebook_focus(objects: $focuses_to_add) {
affected_rows
}
delete_notebook_focus(where: { id: { _in: $focuses_ids_to_delete } }) {
affected_rows
}
insert_notebook_target(objects: $targets_to_add) {
affected_rows
}
update_notebook_target_many(
updates: [
{
where: { id: { _in: $target_ids_to_cancel } }
_set: { status: "abandonned" }
}
{ where: { id: { _in: $target_ids_to_end } }, _set: { status: "done" } }
]
) {
affected_rows
}
}"""
)

await client.execute(
mutation,
variable_values={
"focuses_to_add": to_focuses_insert_input(
notebook_id, focus_differences.focuses_to_add
),
"focuses_ids_to_delete": focus_differences.focus_ids_to_delete,
"targets_to_add": [
target.jsonb()
for target in focus_differences.target_differences.targets_to_add
],
"target_ids_to_cancel": focus_differences.target_differences.target_ids_to_cancel, # noqa: E501
"target_ids_to_end": focus_differences.target_differences.target_ids_to_end,
},
)
4 changes: 2 additions & 2 deletions backend/cdb/api/db/crud/notebook_situation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from gql.client import AsyncClientSession

from cdb.api.db.models.ref_situation import RefSituation
from cdb.api.v1.payloads.socio_pro import SituationToAdd
from cdb.api.v1.payloads.socio_pro import SituationInsertInput


async def get_ref_situations(client: AsyncClientSession) -> List[RefSituation]:
Expand Down Expand Up @@ -34,7 +34,7 @@ async def get_ref_situations(client: AsyncClientSession) -> List[RefSituation]:
async def save_notebook_situations(
client: AsyncClientSession,
notebookId: UUID,
situations_to_add: List[SituationToAdd],
situations_to_add: List[SituationInsertInput],
situation_ids_to_delete: List[UUID],
):
mutation = gql(
Expand Down
2 changes: 1 addition & 1 deletion backend/cdb/api/db/models/focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Focus(BaseModel):
id: UUID
theme: str
creator_id: UUID
creator_id: UUID | None
notebook_id: UUID
created_at: datetime
updated_at: datetime
Expand Down
13 changes: 0 additions & 13 deletions backend/cdb/api/db/models/ref_situation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,3 @@ class NotebookSituation(BaseModel):
situationId: UUID
createdAt: datetime
deleteAt: datetime | None

@staticmethod
def selection_set():
return """ { id situationId createdAt deletedAt } """

@staticmethod
def parse_list(situations):
notebook_situations_parsed = []
if situations:
notebook_situations_parsed = [
NotebookSituation.parse_obj(situation) for situation in situations
]
return notebook_situations_parsed
2 changes: 1 addition & 1 deletion backend/cdb/api/db/models/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Target(BaseModel):
id: UUID
focus_id: UUID
target: str
creator_id: UUID
creator_id: UUID | None
created_at: datetime
updated_at: datetime
status: str
Expand Down
Loading
Loading