Skip to content

feat(contact): add validation, tests, types and API docs for contact create api#14

Open
ROHITNANERA wants to merge 1 commit intocodersgyan:masterfrom
ROHITNANERA:feat/add-input-validation-to-contact-creation-endpoint
Open

feat(contact): add validation, tests, types and API docs for contact create api#14
ROHITNANERA wants to merge 1 commit intocodersgyan:masterfrom
ROHITNANERA:feat/add-input-validation-to-contact-creation-endpoint

Conversation

@ROHITNANERA
Copy link

Closes #11

Summary

Adds complete input validation to POST /api/contacts with proper error handling, phone normalization, tags support, and documentation.

Changes

  • Required fields: first_name, last_name, email
  • Email format + length validation
  • Optional phone validated + normalized to E.164 using github.com/nyaruka/phonenumbers
  • Optional tags array accepted (matches current API usage)
  • All fields trimmed
  • Dynamic error messages (max 100 characters)
  • Structured 400 JSON error response
  • Create types for request and error structure

Tests

  • validator_test.go – full unit tests (matches repository test style)
  • handler_test.go – integration tests using real in-memory DB + migrations
  • All validation cases covered, including error format
  • Success cases verify 201 + "id" field (no change to current response design)

Documentation

  • Updated apis.rest with:
    • Valid + invalid examples using {{base_url}}
    • Full validation rules
    • Error response format

All tests pass locally:

go test ./internal/contact
# → ok

@ROHITNANERA ROHITNANERA force-pushed the feat/add-input-validation-to-contact-creation-endpoint branch from c7fbbf3 to f7c9c49 Compare November 23, 2025 10:26
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.

[Feature] Add Input Validation to Contact Creation Endpoint

1 participant