Admin 백엔드 - BaseController + DashboardController + 라우트 + 테스트

ID: 1cc93ea1-f35b-421f-9b93-f46af0774eb2

높음 완료

## 목표
Admin namespace 백엔드 인프라 구축 (컨트롤러, 라우트, 테스트)

## 구현 항목

### 1. Admin::BaseController (신규)
- 파일: `app/controllers/admin/base_controller.rb`
- ApplicationController 상속
- `before_action :authorize_admin!`
- `authorize_admin!` 메서드: `current_user.admin?` 체크, 실패 시 root_path redirect + alert
- `layout "admin"` 선언

### 2. Admin::DashboardController (신규)
- 파일: `app/controllers/admin/dashboard_controller.rb`
- Admin::BaseController 상속
- `index` 액션에서 통계 수집:
- @total_users = User.count
- @total_meditations = UserMeditation.count
- @total_sessions = QtSession.count
- @total_prayers = PrayerRequest.count
- @total_sermons = SermonNote.count
- @total_readings = BibleReadingLog.count
- @recent_users = User.order(created_at: :desc).limit(5)
- @recent_meditations = UserMeditation.order(created_at: :desc).limit(5)

### 3. 라우트 수정
- 파일: `config/routes.rb`
- 기존 라우트 유지, 맨 아래(authenticated 블록 밖)에 추가:
```ruby
# Admin
namespace :admin do
root "dashboard#index"
end
```

### 4. 테스트 (신규)
- 파일: `test/controllers/admin/dashboard_controller_test.rb`
- 테스트 케이스:
- admin 사용자로 /admin 접근 → 200
- 일반 사용자로 /admin 접근 → redirect
- 미인증 사용자로 /admin 접근 → redirect
- 통계 데이터가 올바르게 표시되는지 확인
- Fixture 사용: users(:admin), users(:daniel)
- 인증: `sign_in users(:admin)` (Devise test helper)

## 주의사항
- UUID PK 사용 (ApplicationRecord의 set_uuid 자동 처리)
- `parallelize(workers: 1)` 테스트 설정 확인
- 기존 routes.rb 구조 깨지지 않게 주의
- 기존 테스트 전체 통과 확인: `bin/rails test`

첨부 이미지

이미지 추가 (Ctrl+V로 붙여넣기 또는 클릭)

JPEG, PNG, GIF, WebP / 최대 10MB

담당자: admin-backend
생성일: 2026년 03월 02일 04:37

활동 로그

  • 팀리드 상태 변경: 리뷰 → 완료

    2026년 03월 02일 04:47:42

  • A
    admin-backend 상태 변경: 할 일 → 리뷰

    2026년 03월 02일 04:42:06

  • A
    admin-backend Admin 백엔드 구현 완료 - 4개 테스트 전체 통과

    2026년 03월 02일 04:42:06

    상세 보기

    ## 생성한 파일
    - `app/controllers/admin/base_controller.rb` - 관리자 인증/인가 (authorize_admin!)
    - `app/controllers/admin/dashboard_controller.rb` - 통계 6종 + 최근 활동 2종
    - `app/views/layouts/admin.html.erb` - 최소 admin 레이아웃 (프론트엔드 에이전트가 확장 예정)
    - `app/views/admin/dashboard/index.html.erb` - 통계 카드 6개 그리드
    - `test/controllers/admin/dashboard_controller_test.rb` - 4개 테스트 케이스

    ## 수정한 파일
    - `config/routes.rb` - `namespace :admin { root "dashboard#index" }` 추가

    ## 테스트 결과
    - Admin 테스트: 4 runs, 19 assertions, 0 failures
    - 전체 테스트: 331 runs, 750 assertions, 0 failures (3 errors = 기존 SQLite BusyException)

  • A
    admin-backend 작업 시작: Admin 백엔드 구현

    2026년 03월 02일 04:39:33

    상세 보기

    ## 작업 범위
    - Admin::BaseController (인증/인가)
    - Admin::DashboardController (통계)
    - 라우트 설정
    - 컨트롤러 테스트