백로그
0할 일
0진행 중
0리뷰
0완료 (15일)
2Admin 백엔드 - BaseController + DashboardController + 라우트 + 테스트
## 목표 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`
Admin 프론트엔드 - 레이아웃 + 사이드바 + 대시보드 뷰
## 목표 Admin 전용 레이아웃, 사이드바, 대시보드 뷰 구현 ## 구현 항목 ### 1. Admin 레이아웃 (신규) - 파일: `app/views/layouts/admin.html.erb` - 기존 application.html.erb 구조 참고하되, 관리자 전용으로 구성: - 상단 헤더: "LogBible Admin" 타이틀 - 좌측 사이드바: admin 전용 네비게이션 - 메인 컨텐츠 영역 - 하단 네비 불필요 (데스크톱 중심) - Tailwind CSS v4 의미 기반 색상 사용: - bg-surface-default, text-text-primary - brand-primary (#2563EB), surface-muted (#F9FAFB) - `<%= yield %>` 로 컨텐츠 삽입 - flash 메시지: `<%= render "shared/flash" %>` - JS/CSS: `<%= stylesheet_link_tag :app %>`, `<%= javascript_importmap_tags %>` ### 2. Admin 사이드바 (신규) - 파일: `app/views/admin/shared/_sidebar.html.erb` - 네비게이션 메뉴: - 대시보드 (admin_root_path) - 집 아이콘 - 구분선 - "사이트로 돌아가기" (root_path) - 화살표 아이콘 - SVG 아이콘 직접 인라인 사용 (외부 라이브러리 금지) - 현재 페이지 하이라이트: `current_page?` helper 활용 ### 3. 대시보드 뷰 (신규) - 파일: `app/views/admin/dashboard/index.html.erb` - 페이지 제목: "관리자 대시보드" - 통계 카드 그리드 (2x3 또는 3x2): - 전체 사용자 수 (@total_users) - 묵상 기록 수 (@total_meditations) - QT 세션 수 (@total_sessions) - 기도 제목 수 (@total_prayers) - 설교 노트 수 (@total_sermons) - 성경 읽기 수 (@total_readings) - 각 카드: 기존 shared/_card.html.erb 파셜 활용 - 카드 내부: 아이콘 + 숫자 + 라벨 - 숫자는 크게 (text-display 또는 text-2xl font-bold) - 라벨은 작게 (text-small text-text-secondary) - 최근 활동 섹션: - 최근 가입 사용자 목록 (@recent_users) - 이름, 이메일, 가입일 - 최근 묵상 기록 (@recent_meditations) - 사용자명, 날짜 - 기존 shared/_table.html.erb 파셜 활용 ## 기존 shared 파셜 참고 - `_card.html.erb`: `title:`, `padding:` (기본 "default") 파라미터 - `_table.html.erb`: `headers:` (배열), `rows:` (2차원 배열) 파라미터 - `_badge.html.erb`: `text:`, `variant:` (default/success/warning/error/info) 파라미터 - `_separator.html.erb`: `margin:` (기본 "default") 파라미터 ## 주의사항 - ERB 멀티라인 주석 안에 ERB 태그 금지 (SystemStackError) - shared 파셜의 strict locals 정확히 준수 - Tailwind CSS v4 의미 기반 클래스 사용 (하드코딩 색상 금지) - 반응형: 기본 모바일, md: 이상에서 사이드바 표시 - 기존 테스트 전체 통과 확인: `bin/rails test`