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

Add api route for postal areas #386

Closed
wants to merge 3 commits into from

Conversation

FLoreauIGN
Copy link
Contributor

#364

Cette PR ajoute une route d'API permettant d'intégrer le fichier geojson de contours postaux fourni par La Poste dans la base de données postgres.

@FLoreauIGN FLoreauIGN linked an issue Apr 18, 2024 that may be closed by this pull request
@FLoreauIGN FLoreauIGN force-pushed the add-api-route-for-postal-areas branch from 06d2369 to 4b5c11a Compare April 18, 2024 13:10
@FLoreauIGN FLoreauIGN force-pushed the add-api-route-for-postal-areas branch from 5ee9358 to 69aba5e Compare April 26, 2024 12:46
@FLoreauIGN FLoreauIGN force-pushed the add-api-route-for-postal-areas branch from 69aba5e to cc86730 Compare April 26, 2024 12:48
@@ -26,6 +27,9 @@ export default async function apiConsumers({data: {dataType, jobType, data, stat
case 'district':
await districtConsumer(jobType, data, statusID)
break
case 'postalCode':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postalCode ou postalArea ? Dans l'envoi du job par l'api, c'est postalArea qui est utilisé

Comment on lines +299 to +315
const formatPayloadPostalAreas = async function (payload) {
const postalCodeDBResponse = await getAllPostalAreas() || []
const postalCodesFromDB = new Set(postalCodeDBResponse.map(({postalCode}) => postalCode))

const {features, crs} = payload || {}

const bulkOperations = features.map(({properties, geometry}) => {
const postalCode = properties.cp
postalCodesFromDB.delete(postalCode)
if (geometry.crs === undefined) {
geometry.crs = crs
}

return {postalCode, geometry}
})

return {operations: bulkOperations, expiredPostalAreas: postalCodesFromDB}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à mettre dans un fichier utils ?

const statusID = nanoid()

await apiQueue.add(
{dataType: 'postalArea', jobType: 'update', data: postalAreas, statusID},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ici on utilise postalArea et dans le consumer, on utilise postalCode

@@ -0,0 +1,15 @@
import {PostalArea} from '../../util/sequelize.js'

export const getAllPostalAreas = () => PostalArea.findAll({attributes: ['postalCode']})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici la fonction s'appelle getAllPostalAreas mais on ne récupère que les postalCode des getAllPostalAreas.


export const getAllPostalAreas = () => PostalArea.findAll({attributes: ['postalCode']})

export const putPostalAreas = postalAreas => PostalArea.bulkCreate(postalAreas, {updateOnDuplicate: ['geometry'], subQuery: false})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nom de fonction avec 'put' alors que l'on fait de la création.

postalCodes.map(postalCode => PostalArea.destroy({where: {postalCode}}))
}

export const updatePostalAreas = async ({operations, expiredPostalAreas}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peut-être trouvé un autre nom pour cette fonction aussi car on ne fait pas des updates mais des créations et suppressions.

@jbouhadoun jbouhadoun force-pushed the add-api-route-for-postal-areas branch from 319fe1c to cc86730 Compare June 18, 2024 17:31
@vinsag
Copy link
Member

vinsag commented Jul 3, 2024

Cette partie a été revue avec un nouveau dev, on ferme la PR

@vinsag vinsag closed this Jul 3, 2024
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.

Intégrer les contours postaux dans PG
3 participants