Bỏ qua nội dung

Admin sửa property bất kỳ

Feature URL
Module
admin
Status
in-development
Priority
P1
Platforms
fe · be
AC progress
10 / 13
Last reviewed
2026-05-30

Mục tiêu

Cho phép admin chỉnh sửa toàn bộ thông tin của property bất kỳ mà không cần là chủ sở hữu. Phục vụ kiểm duyệt, chỉnh sửa dữ liệu sai hoặc cập nhật trạng thái property theo yêu cầu vận hành.

Phạm vi

Trong phạm vi (In scope):

  • Admin gọi PUT /api/v1/admin/properties/{id} để ghi đè toàn bộ mutable fields của property.
  • Bỏ qua ownership check (admin không cần là createdBy).
  • Các fields có thể sửa: propertyTypeCode, houseNumber, alleyPath, streetName, ward, province, longitude, latitude, address, areaM2, width, length, alleyWidth, roadWidth, distanceToMainRoad, height, houseDirection, bedrooms, bathrooms, floorNumber, unitNumber, floors, balconyDirection, interior, towerBlock, status, legalDocument.
  • Full-replace semantics: legalDocument = null thì detach và xoá legal doc hiện tại.
  • FE form sửa property trong màn admin detail hoặc modal riêng.

Ngoài phạm vi (Out of scope):

  • Tạo property mới từ admin.
  • Xoá property, xem feature admin-property-delete.
  • Restore property đã soft-delete (chưa có endpoint).
  • Thay đổi owner (createdBy) của property.

User Stories

  • admin kiểm duyệt, tôi muốn sửa thông tin sai của property để đảm bảo dữ liệu trên sàn chính xác.
  • admin vận hành, tôi muốn chuyển property sang INACTIVE để ẩn khỏi marketplace mà không cần xoá.
  • admin, tôi muốn sửa legal document của property khi người dùng upload sai thông tin.

Luồng chức năng

sequenceDiagram
    actor Admin
    participant Web
    participant BE
    participant DB

    Admin->>Web: Mở form sửa property trong trang admin
    Web->>Admin: Hiển thị form với dữ liệu hiện tại
    Admin->>Web: Điền thông tin chỉnh sửa và submit
    Web->>BE: PUT /api/v1/admin/properties/{id}
    BE->>BE: Kiểm tra role admin
    BE->>BE: Validate UpdatePropertyRequest
    BE->>DB: Ghi đè mutable fields bỏ qua owner check
    alt Property không tồn tại
        BE-->>Web: 404 Not Found
        Web->>Admin: Báo property không tồn tại
    else Thành công
        BE-->>Web: PropertyResponse
        Web->>Admin: Thông báo cập nhật thành công
    end

Acceptance Criteria

  • AC-1: Backend có PUT /api/v1/admin/properties/{id}, chỉ admin được gọi.
  • AC-2: API bỏ qua ownership check, admin không cần là createdBy.
  • AC-3: Validate đầy đủ: propertyTypeCode, ward, province, address, areaM2, status là required.
  • AC-4: status chỉ nhận ACTIVE hoặc INACTIVE.
  • AC-5: longitude trong khoảng -180 đến 180; latitude trong khoảng -90 đến 90.
  • AC-6: areaM2, width, length, alleyWidth, roadWidth, distanceToMainRoad, height phải là số không âm.
  • AC-7: bedrooms, bathrooms, floorNumber, unitNumber, floors phải là số không âm.
  • AC-8: legalDocument = null → detach và xoá legal doc hiện tại; legalDocument có giá trị → upsert.
  • AC-9: Nếu property không tồn tại, API trả 404 Not Found.
  • AC-10: Response là PropertyResponse sau khi cập nhật thành công.
  • AC-11: FE cần form sửa property trong màn admin detail hoặc modal riêng.
  • AC-12: FE pre-fill form với dữ liệu hiện tại từ detail API.
  • AC-13: FE xử lý validation error, 404 và error state khi gọi API thất bại.

Quy tắc nghiệp vụ

  • Chỉ admin được gọi PUT /admin/properties/{id}.
  • Full-replace semantics: toàn bộ mutable fields bị ghi đè; FE phải gửi tất cả fields, không chỉ gửi field thay đổi.
  • Admin sửa được cả property đang INACTIVE hoặc đã soft-delete.
  • actingAdminId được ghi nhận qua SecurityContext cho audit.
  • Thay đổi status sang INACTIVE không đồng nghĩa soft-delete; soft-delete phải gọi DELETE endpoint riêng.

Dữ liệu & Trạng thái

Entity nghiệp vụ:

  • Property: bất động sản được cập nhật.
  • UpdatePropertyRequest: body full-replace gồm propertyTypeCode, ward, province, address, areaM2, status (required) và các fields vật lý, hướng, pháp lý (optional).
  • LegalDocumentRequest: pháp lý lồng trong UpdatePropertyRequest, full-replace semantics.
  • PropertyResponse: response sau khi update thành công.

Trạng thái user-facing:

  • form-loading — đang tải dữ liệu hiện tại để pre-fill.
  • form-ready — form hiện dữ liệu, admin có thể sửa.
  • form-submitting — đang gửi request cập nhật.
  • update-success — cập nhật thành công.
  • update-not-found — property không tồn tại.
  • update-validation-error — dữ liệu gửi không hợp lệ.
  • update-error — lỗi cập nhật.

Liên quan