Skip to content

Add Customer Management module with REST API, validation, and search#1

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-customer-management-feature
Open

Add Customer Management module with REST API, validation, and search#1
Copilot wants to merge 4 commits intomainfrom
copilot/add-customer-management-feature

Conversation

Copy link

Copilot AI commented Nov 8, 2025

Implements full customer lifecycle management for the real estate system with type classification (POTENTIAL, NEGOTIATING, PURCHASED), duplicate prevention, and statistics tracking.

Core Components

Entity & Repository

  • CustomerEntity extends BaseEntity for audit trail, maps to existing customer table
  • CustomerRepository with JPQL queries for combined search (name/phone/email) and type-based statistics
  • Soft delete via isActive flag

Service Layer

  • Duplicate validation on email/phone before create/update
  • Statistics aggregation by CustomerType enum
  • Batch soft delete support

REST API (/api/customers)

POST   /                    // Create customer
PUT    /{id}                // Update customer  
DELETE /{id}                // Soft delete
GET    /                    // List with pagination/search
GET    /{id}                // Get by ID
GET    /statistics          // Count by type
POST   /search              // Advanced search

Validation & Error Handling

  • Bean Validation: full name (2-100 chars), Vietnamese phone format (^0\d{9,10}$)
  • GlobalExceptionHandler returns structured errors: 400 (validation), 404 (not found), 409 (duplicate)

Database Migration

  • Adds address, customertype, notes columns to existing customer table
  • Sets default type to POTENTIAL for existing records

Example Usage

# Create customer with validation
curl -X POST /api/customers -H "Content-Type: application/json" -d '{
  "fullName": "Nguyen Van A",
  "phoneNumber": "0905123456",
  "email": "test@example.com",
  "customerType": "POTENTIAL"
}'

# Search across name/phone/email
curl -X GET "/api/customers?searchValue=nguyen&page=0&size=10"

# Get statistics
curl -X GET /api/customers/statistics
# Returns: {"POTENTIAL": 15, "NEGOTIATING": 8, "PURCHASED": 12}

Files Changed

  • Added: 10 new files (entity, repository, service, controller, DTOs, exceptions, enum)
  • Modified: CustomerDTO (validation annotations), pom.xml (validation dependency)
  • Database: Migration script for schema updates
Original prompt

Tạo chức năng quản lý khách hàng (Customer Management) cho hệ thống bất động sản với các yêu cầu sau:

  1. Tạo Customer Entity với các trường:

    • id (Long, primary key, auto-generated)
    • fullName (String, họ tên khách hàng)
    • phoneNumber (String, số điện thoại)
    • email (String, email)
    • address (String, địa chỉ)
    • customerType (Enum: POTENTIAL, NEGOTIATING, PURCHASED - khách tiềm năng, đang giao dịch, đã mua)
    • notes (String, ghi chú)
    • createdDate (LocalDateTime)
    • modifiedDate (LocalDateTime)
    • createdBy (String)
    • modifiedBy (String)
  2. Tạo CustomerRepository extends JpaRepository với các phương thức:

    • Tìm kiếm theo tên (contains, ignore case)
    • Tìm kiếm theo số điện thoại
    • Tìm kiếm theo email
    • Tìm kiếm theo loại khách hàng
    • Tìm kiếm kết hợp (tên hoặc sđt hoặc email)
  3. Tạo CustomerDTO và CustomerSearchDTO để chuyển đổi dữ liệu

  4. Tạo CustomerService và CustomerServiceImpl với các chức năng:

    • Thêm khách hàng mới (kiểm tra trùng email/sđt)
    • Cập nhật thông tin khách hàng
    • Xóa khách hàng (soft delete hoặc hard delete)
    • Lấy danh sách tất cả khách hàng (có phân trang)
    • Tìm kiếm khách hàng theo nhiều tiêu chí
    • Lấy thông tin chi tiết khách hàng
    • Thống kê khách hàng theo loại
  5. Tạo CustomerController với REST API endpoints:

    • POST /api/customers - Tạo khách hàng mới
    • PUT /api/customers/{id} - Cập nhật khách hàng
    • DELETE /api/customers/{id} - Xóa khách hàng
    • GET /api/customers - Lấy danh sách (có phân trang và tìm kiếm)
    • GET /api/customers/{id} - Lấy chi tiết khách hàng
    • GET /api/customers/statistics - Thống kê khách hàng
  6. Validation:

    • Họ tên: không được để trống, 2-100 ký tự
    • Số điện thoại: format Việt Nam (10-11 số)
    • Email: format email hợp lệ
    • Kiểm tra trùng lặp email và số điện thoại
  7. Exception Handling:

    • Custom exceptions cho các trường hợp lỗi
    • Global exception handler

Sử dụng các best practices của Spring Boot, JPA, và tuân thủ cấu trúc hiện tại của project.

This pull request was created as a result of the following prompt from Copilot chat.

Tạo chức năng quản lý khách hàng (Customer Management) cho hệ thống bất động sản với các yêu cầu sau:

  1. Tạo Customer Entity với các trường:

    • id (Long, primary key, auto-generated)
    • fullName (String, họ tên khách hàng)
    • phoneNumber (String, số điện thoại)
    • email (String, email)
    • address (String, địa chỉ)
    • customerType (Enum: POTENTIAL, NEGOTIATING, PURCHASED - khách tiềm năng, đang giao dịch, đã mua)
    • notes (String, ghi chú)
    • createdDate (LocalDateTime)
    • modifiedDate (LocalDateTime)
    • createdBy (String)
    • modifiedBy (String)
  2. Tạo CustomerRepository extends JpaRepository với các phương thức:

    • Tìm kiếm theo tên (contains, ignore case)
    • Tìm kiếm theo số điện thoại
    • Tìm kiếm theo email
    • Tìm kiếm theo loại khách hàng
    • Tìm kiếm kết hợp (tên hoặc sđt hoặc email)
  3. Tạo CustomerDTO và CustomerSearchDTO để chuyển đổi dữ liệu

  4. Tạo CustomerService và CustomerServiceImpl với các chức năng:

    • Thêm khách hàng mới (kiểm tra trùng email/sđt)
    • Cập nhật thông tin khách hàng
    • Xóa khách hàng (soft delete hoặc hard delete)
    • Lấy danh sách tất cả khách hàng (có phân trang)
    • Tìm kiếm khách hàng theo nhiều tiêu chí
    • Lấy thông tin chi tiết khách hàng
    • Thống kê khách hàng theo loại
  5. Tạo CustomerController với REST API endpoints:

    • POST /api/customers - Tạo khách hàng mới
    • PUT /api/customers/{id} - Cập nhật khách hàng
    • DELETE /api/customers/{id} - Xóa khách hàng
    • GET /api/customers - Lấy danh sách (có phân trang và tìm kiếm)
    • GET /api/customers/{id} - Lấy chi tiết khách hàng
    • GET /api/customers/statistics - Thống kê khách hàng
  6. Validation:

    • Họ tên: không được để trống, 2-100 ký tự
    • Số điện thoại: format Việt Nam (10-11 số)
    • Email: format email hợp lệ
    • Kiểm tra trùng lặp email và số điện thoại
  7. Exception Handling:

    • Custom exceptions cho các trường hợp lỗi
    • Global exception handler

Sử dụng các best practices của Spring Boot, JPA, và tuân thủ cấu trúc hiện tại của project.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 8, 2025 08:09
…nd REST API

Co-authored-by: GiangVanLuc <176579854+GiangVanLuc@users.noreply.github.com>
Co-authored-by: GiangVanLuc <176579854+GiangVanLuc@users.noreply.github.com>
Co-authored-by: GiangVanLuc <176579854+GiangVanLuc@users.noreply.github.com>
Copilot AI changed the title [WIP] Add customer management functionality for real estate system Add Customer Management module with REST API, validation, and search Nov 8, 2025
Copilot AI requested a review from GiangVanLuc November 8, 2025 08:17
@GiangVanLuc GiangVanLuc marked this pull request as ready for review March 18, 2026 15:36
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.

3 participants