Skip to content

feat(backend): generate PDF inheritance audit reports (#825)#909

Open
DammyAji wants to merge 5 commits into
Fracverse:masterfrom
DammyAji:feat/generate-inheritance-pdf-audit-report
Open

feat(backend): generate PDF inheritance audit reports (#825)#909
DammyAji wants to merge 5 commits into
Fracverse:masterfrom
DammyAji:feat/generate-inheritance-pdf-audit-report

Conversation

@DammyAji

@DammyAji DammyAji commented Jul 2, 2026

Copy link
Copy Markdown

Closes #825

Summary

Implements the PDF inheritance audit report generation feature for issue Fracverse/InheritX#825.

Adds GET /api/plans/:id/report — a JWT-protected endpoint that generates and streams a downloadable PDF audit report for a given inheritance plan.

Changes

backend/src/pdf.rs (new)

  • PlanReportData, BeneficiaryData, PingLogData structs for report input
  • generate() using printpdf to build an A4 PDF with Plan Details, Beneficiaries, Activity Log sections and automatic page-break

backend/src/api.rs

  • Added PingLogRow sqlx struct to query the ping_logs table
  • Added admin_routes block protected by jwt_auth_middleware
  • Registered GET /api/plans/:id/report under admin routes
  • get_plan_report handler runs PDF generation via tokio::task::spawn_blocking and returns application/pdf

backend/src/lib.rs

  • Exposed pub mod pdf

backend/Cargo.toml

  • Added printpdf = "0.7"

backend/migrations/20260627000000_add_ping_logs

  • Migration to create ping_logs table

Merge Conflicts Resolved

All conflicts with upstream master resolved (rate-limiting, metrics, security middleware):

  • backend/Cargo.toml: kept printpdf + redis alongside upstream dashmap, prometheus, once_cell
  • backend/src/api.rs: merged PDF handler on top of upstream rate-limit middleware, strict CORS, and metrics
  • backend/src/lib.rs: retained pub mod pdf alongside pub mod metrics + pub mod middleware

Acceptance Criteria

  • PDF conforms to dynamic template layouts
  • Exposed under GET /api/plans/:id/report with JWT security check
  • Runs without blocking Axum async loop (tokio::task::spawn_blocking)
  • Includes owners, beneficiary names, allocations, yield accrued, and historical ping activity logs

Closes #825

DammyAji added 4 commits June 26, 2026 18:02
- Add printpdf = 0.7 dependency for pure-Rust PDF generation
- Add ping_logs migration (plan_id, pinged_at, accrued_yield_snapshot)
- Add src/pdf.rs module with PlanReportData / generate() using built-in fonts
- Add GET /api/plans/:id/report handler protected by JWT middleware
- PDF includes owner, token, amount, status, yield, beneficiaries with
  allocation percentages, and full ping activity log with yield snapshots
- PDF generation runs in tokio::task::spawn_blocking (never blocks Axum runtime)
- Returns application/pdf with Content-Disposition: attachment

Closes Fracverse#825
- Keep both printpdf and redis dependencies in Cargo.toml
- Merge PDF report handler into master's api.rs (cache, KYC endpoints,
  paginated payouts, jwt_auth_middleware for /api/plans/:id/report)
- Add pub mod pdf alongside pub mod cache in lib.rs
- Restore config.rs, main.rs, inactivity_watchdog.rs, yield_calculator.rs,
  and cache.rs to match master (redis/PlanCache support)
…-report

Resolve conflicts with upstream master (rate-limiting, metrics, security middleware):
- backend/Cargo.toml: keep printpdf + redis alongside new dashmap, prometheus, once_cell
- backend/src/api.rs: graft PDF handler + admin_routes + PingLogRow on top of
  upstream's rate-limit middleware, strict CORS, and metrics changes
- backend/src/lib.rs: keep pub mod pdf alongside new pub mod metrics + pub mod middleware

Closes Fracverse#825
Fix all cargo fmt --check failures:
- pdf.rs: wrap long line!() macro calls to multi-line rustfmt style
- api.rs: reformat spawn_blocking match block per rustfmt

Closes Fracverse#825
@DammyAji

DammyAji commented Jul 2, 2026

Copy link
Copy Markdown
Author

@ONEONUORA please kindly review now

@ONEONUORA

Copy link
Copy Markdown
Contributor

@DammyAji
Run cargo fmt --all -- --check
and Run cargo clippy

@DammyAji

DammyAji commented Jul 2, 2026

Copy link
Copy Markdown
Author

@ONEONUORA ok

- api.rs: revert pdf_bytes match block to rustfmt-canonical style
  (method-chain .await on its own line with opening brace on same line)
- pdf.rs: collapse short line!() macro calls back to single-line form;
  only wrap the 3 lines that actually exceed 100 chars
- auth.rs: remove redundant match where both arms return the same
  StatusCode::UNAUTHORIZED (fixes clippy::match-like-matches-macro)
@DammyAji

DammyAji commented Jul 3, 2026

Copy link
Copy Markdown
Author

@ONEONUORA please tell me i am done

@ONEONUORA

Copy link
Copy Markdown
Contributor

@DammyAji
Run cargo fmt --all -- --check

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.

[Backend] Feature: Generate PDF Inheritance Audit Reports

2 participants