Skip to content

feat(rw): crud rw - #64

Merged
hanchan-dev merged 1 commit into
devfrom
feature/rws
Sep 3, 2026
Merged

feat(rw): crud rw#64
hanchan-dev merged 1 commit into
devfrom
feature/rws

Conversation

@aaz132

@aaz132 aaz132 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Lanjutan EV5-7-S1 (RegionController) — CRUD untuk resource rws (RW): list (dengan filter hamlet_id), tambah, edit, dan hapus. Polanya mengikuti persis PR hamlets sebelumnya (guard otorisasi + guard integritas data warga), termasuk validasi nomor RW unik per dusun.

Jira Ticket

Ticket: EV5-7-S1

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Configuration change

Changes Made

  • Tambah method indexRws, storeRw, updateRw, destroyRw di RegionController.php
  • Guard otorisasi: hanya role petugas_desa yang boleh create/update/delete RW (403 untuk role lain)
  • Guard integritas data: RW yang masih punya warga aktif tidak bisa dinonaktifkan atau dihapus (409)
  • Validasi number RW harus unik per hamlet_id, dengan pesan error custom Bahasa Indonesia
  • Refactor kecil: helper guardDeactivation sekarang menerima parameter $message, biar bisa dipakai bareng antara hamlets dan rws tanpa mengubah pesan error yang sudah ada di endpoint hamlets
  • Route baru di routes/api.php dalam group auth:sanctum: GET/POST /rws, PATCH/DELETE /rws/{rw}
  • Tambah 4 feature test baru di RegionControllerTest.php: create/list/update/delete sukses, non-petugas_desa ditolak, duplicate number ditolak, guard nonaktifkan & hapus dengan warga aktif

How to Test

  1. Generate token Sanctum buat user role=petugas_desa yang punya village_id terisi (bukan user admin seeder yang village_id-nya null) lewat php artisan tinker
  2. Test lewat Postman pakai Authorization: Bearer <token>:
    • GET /api/rws?hamlet_id=1 → daftar RW di dusun tersebut
    • POST /api/rws body {"hamlet_id": 1, "number": "002"} → 201
    • POST /api/rws dengan hamlet_id + number yang sama lagi → 422 (duplikat)
    • PATCH /api/rws/{id} body {"is_active": false} → 200 kalau tidak ada warga aktif, 409 kalau masih ada
    • DELETE /api/rws/{id} → 200 kalau tidak ada warga terdaftar, 409 kalau masih ada
  3. Ulangi salah satu request di atas pakai user role selain petugas_desa → harus dapat 403
  4. php artisan test --filter=RegionControllerTest — semua 9 test (5 hamlets + 4 rws) harus pass

Screenshots (if applicable)

Checklist

  • Kode sudah di-test secara lokal
  • Tidak ada console.log / dd() / dump() yang tertinggal
  • Tidak ada conflict dengan branch target
  • Nama branch mengikuti konvensi (feature/nama-fitur, fix/nama-bug)
  • PR ditujukan ke branch dev (bukan langsung ke main)

@hanchan-dev
hanchan-dev merged commit dc4ed90 into dev Sep 3, 2026
6 checks passed
@hanchan-dev
hanchan-dev deleted the feature/rws branch September 3, 2026 07:42
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.

2 participants