Skip to content

Form validation #15

Description

@marciomyst

Summary

Implement consistent validation for movie create and edit forms.

This issue improves reliability and user experience by validating movie data both on the frontend and at the API boundary.

Goal

Prevent invalid movie data from being submitted or accepted.

Scope

  • Define validation rules for movie create/edit input.
  • Add backend validation at the API boundary.
  • Add frontend validation feedback in the movie form.
  • Show field-level messages where appropriate.
  • Disable or prevent invalid submission.
  • Ensure backend validation still protects the API even if frontend validation is bypassed.
  • Keep validation error responses consistent with application/problem+json.

Suggested Validation Rules

Required fields:

  • title
  • releaseYear

Recommended constraints:

  • title: required, max length
  • originalTitle: optional, max length
  • releaseYear: valid year range
  • countryCode: optional ISO-like code
  • originalLanguage: optional language code
  • genres: optional list, max item length
  • director: optional, max length
  • synopsis: optional, max length
  • durationMinutes: optional positive number
  • ageRating: optional, max length

Example semantic validation error response:

HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json
{
  "type": "https://smartmoviecatalog.dev/problems/validation-error",
  "title": "Validation failed.",
  "status": 422,
  "detail": "One or more validation errors occurred.",
  "instance": "/api/movies",
  "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00",
  "errors": {
    "title": [
      "Title is required."
    ],
    "releaseYear": [
      "Release year must be greater than or equal to 1888."
    ],
    "durationMinutes": [
      "Duration must be greater than zero."
    ]
  }
}

Acceptance Criteria

  • Required fields are validated on the frontend.
  • Required fields are validated on the backend.
  • Malformed API requests return 400 Bad Request with application/problem+json.
  • Semantic validation failures return 422 Unprocessable Content with application/problem+json.
  • Frontend displays understandable validation messages.
  • Form submission is blocked or clearly rejected when invalid.
  • Validation rules are consistent between create and edit.
  • Validation does not depend only on UI logic.
  • No secrets or internal exception details are exposed in validation responses.

Technical Notes

  • Keep validation rules pragmatic for V1.
  • Problem responses should use the base contract: type, title, status, detail, instance, optional traceId, and optional field-level errors.
  • Avoid over-modeling domain invariants before the domain model matures.
  • Use existing framework conventions before adding new validation libraries.
  • If a validation library is introduced, document why.

Out of Scope

  • Advanced duplicate detection.
  • TMDb validation.
  • AI-based validation.
  • Localization of validation messages.
  • Complex country/language normalization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiHTTP API endpoints, contracts, routing, and responsesarea:backendBackend application, domain, infrastructure, or server codearea:catalogMovie catalog domain and catalog-related featuresarea:frontendAngular frontend application codepriority:highHigh-priority work for the current milestonetype:featureNew user-facing or product capabilityv1Included in the Version 1 product scope

    Projects

    Status
    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions