Skip to content

Implement CreateNeighborService functionality with validation and database integration#86

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-75
Draft

Implement CreateNeighborService functionality with validation and database integration#86
Copilot wants to merge 2 commits intomainfrom
copilot/fix-75

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 10, 2025

This PR implements the complete functionality for the CreateNeighborService microservice, which was previously just a "Hello World" placeholder.

Changes Made

Core Implementation

  • Added POST /create-neighbor endpoint that accepts Neighbor data and persists it to the database
  • Integrated Entity Framework with CommonData models and ApplicationDbContext
  • Added dual database support: SQL Server for production, In-Memory database for development/testing
  • Added Swagger/OpenAPI documentation for the new endpoint

Validation & Business Logic

  • Admin user validation: Rejects users with Level="Admin" (must use CreateUserService instead)
  • Required field validation: Ensures all neighbor properties are provided and valid
  • Duplicate prevention: Checks for existing usernames and apartment numbers
  • Data integrity: Validates apartment numbers are positive

HTTP Response Handling

  • 201 Created: Successful neighbor creation with structured response (excludes password for security)
  • 400 Bad Request: Validation errors with descriptive messages
  • 409 Conflict: Duplicate username or apartment number
  • 500 Internal Server Error: Unexpected database or system errors

Integration & Testing

  • Health check endpoint at /health for service monitoring
  • Verified integration with MainNeighborService routing logic
  • End-to-end testing confirms the complete microservices flow works correctly

Example Usage

POST /create-neighbor
{
  "name": "John Doe",
  "number": 101,
  "user": "johndoe",
  "password": "securepassword",
  "level": "User",
  "status": "Active"
}

Response (201 Created):

{
  "message": "Neighbor created successfully",
  "neighborId": 1,
  "name": "John Doe",
  "number": 101,
  "user": "johndoe",
  "level": "User",
  "status": "Active"
}

Architecture

The implementation follows the existing microservices pattern where:

  1. MainNeighborService routes requests based on user level
  2. CreateNeighborService handles non-admin neighbor creation
  3. CreateUserService handles admin user creation (unchanged)

This maintains proper separation of concerns and follows the established routing logic in the codebase.

Fixes #75.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…abase integration

Co-authored-by: aminespinoza10 <106186354+aminespinoza10@users.noreply.github.com>
Copilot AI changed the title [WIP] Create functionality to CreateNeighborService Implement CreateNeighborService functionality with validation and database integration Jul 10, 2025
Copilot AI requested a review from aminespinoza10 July 10, 2025 22:22
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.

Create functionality to CreateNeighborService

2 participants