Skip to content

Validate coordinates are required for standalone observation points (pointOnly mode) #1692

Description

@ClemRz

Is your feature request related to a problem? Please describe.

The POST /api/v1/observations/import endpoint currently allows creating observation points without coordinates even when no cave is associated. This results in orphan points that cannot be placed on a map.

Related frontend issue: GrottoCenter/grottocenter-front#1412

Describe the solution you'd like

Add server-side validation to the observations import endpoint:

  • When the submitted profile has locationMode: 'pointOnly' (or when no caveId is provided), reject the request with HTTP 400 if latitude or longitude is null/missing.
  • Error response should include a clear validation error code and message indicating that coordinates are required for standalone points.

This ensures data integrity regardless of which client submits the data.

Describe alternatives you've considered

  • Relying solely on frontend validation — rejected because API consumers could bypass it.
  • Adding a database-level CHECK constraint — possible but the constraint logic depends on locationMode which is a profile-level concept, not a column. Better handled at the application layer.

Additional context

  • The frontend already has the concept of locationMode with three values: pointAndCave, pointOnly, caveOnly
  • The locationMode field is included in the profile JSON sent as part of the multipart form submission
  • Rule: if locationMode === 'pointOnly' → lat/lng must be non-null
  • Rule: if locationMode === 'pointAndCave' or caveOnly → lat/lng remain optional

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status
Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions