Skip to content

feat: add community templates API and public schema fields - #80

Merged
Basharkhan7776 merged 2 commits into
Openlabsops:mainfrom
yashraj639:feature/templates-community-api
Jul 1, 2026
Merged

Basharkhan7776 merged 2 commits into
Openlabsops:mainfrom
yashraj639:feature/templates-community-api

Conversation

@yashraj639

@yashraj639 yashraj639 commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements the [Block] Template/Community & Templates APIs to power the public template marketplace.

Changes Made

  • Prisma Schema Update: Added price (Int, default 0) and isPublic (Boolean, default true) to the Template model. Included a new index on isPublic for faster querying.
  • Validation: Updated CreateTemplateSchema to optionally accept price and isPublic when creators publish templates.
  • Publishing: Updated createTemplate controller to correctly map price and isPublic to the database payload.
  • Community Endpoint: Created GET /api/v1/templates/community which:
    • Is completely public (no requireAuth).
    • Filters strictly for isPublic: true.
    • Sorts by popularity (useCount: "desc").
    • Supports search, category, and pagination (page, limit).
    • Securely includes the creator's info (user: { id, name, username, image }) for the UI to display.
  • Tech Debt: Cleaned up residual prefer-const warnings and unused comments in form.controller.ts.

Testing

  • bun turbo lint passes with 0 errors/warnings.
  • Database migration (add_template_price) successfully generated and applied locally.
  • Verified route ordering to prevent wildcard collisions.

Related Issues

Checklist

  • Code follows project conventions
  • Tests pass
  • Documentation updated
  • No linting errors
  • Added a public community templates endpoint for the front page so users can browse shared templates without signing in.
  • Community template browsing now supports global search, category filtering, and pagination.
  • Templates shown in the public gallery are sorted by popularity to surface the most-used options first.
  • Template records now support public visibility and pricing, matching the needs of the template marketplace.
  • The template data model now includes an index to make public-template browsing faster.
  • Template creation now saves the new marketplace fields so templates can be published with a price and visibility setting.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yashraj639, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eb0601b8-bd9b-43d8-9d46-aeefccb4bc97

📥 Commits

Reviewing files that changed from the base of the PR and between 7d1f27a and 2620d8d.

📒 Files selected for processing (2)
  • apps/api/src/controllers/form.controller.ts
  • apps/api/src/controllers/template.controller.ts
📝 Walkthrough

Walkthrough

Adds price and isPublic fields to the Template model with a migration and index, extends createTemplate to persist them with defaults, introduces a new getCommunityTemplates endpoint with search/category filtering and pagination wired to a public route, and removes inline comments in form.controller.ts while adjusting definition assignment in updateForm.

Changes

Community Templates Feature

Layer / File(s) Summary
Template schema, price/isPublic fields, and migration
packages/db/prisma/schema/templates.prisma, packages/db/prisma/migrations/20260701063302_add_template_price/migration.sql, apps/api/src/lib/template-schemas.ts
Template model and migration add price (Int, default 0) and isPublic (Boolean, default true) with an index on isPublic; CreateTemplateSchema validates optional price/isPublic.
createTemplate persistence and owned-templates pagination
apps/api/src/controllers/template.controller.ts
createTemplate destructures and persists price/isPublic with defaults; getOwnedTemplates limit parsing line updated.
getCommunityTemplates endpoint and routing
apps/api/src/controllers/template.controller.ts, apps/api/src/routes/template/template.routes.ts
New getCommunityTemplates controller filters public templates by search/category, sorts by useCount, paginates, and returns nested user fields; wired to unauthenticated GET /api/v1/templates/community.

Estimated code review effort: 2 (Simple) | ~12 minutes

Form Controller Comment Cleanup

Layer / File(s) Summary
Form controller comment removal and definition assignment tweak
apps/api/src/controllers/form.controller.ts
Removes inline comments across listForms, createForm, getForm, and exportCsv; updateForm now assigns definition via a separate let from req.body.definition instead of destructuring, with no functional change to validation/update logic.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant TemplateRoutes
  participant getCommunityTemplates
  participant Database

  Client->>TemplateRoutes: GET /api/v1/templates/community?search&category&page
  TemplateRoutes->>getCommunityTemplates: invoke handler
  getCommunityTemplates->>Database: findMany(isPublic true, search, category, sort by useCount)
  getCommunityTemplates->>Database: count matching templates
  Database-->>getCommunityTemplates: templates + total count
  getCommunityTemplates-->>Client: JSON data + pagination meta
Loading

Possibly related issues

Possibly related PRs

  • Openlabsops/Snap-form#60: Modifies the same template.controller.ts dashboard controllers (owned templates) that this PR extends with getCommunityTemplates.
  • Openlabsops/Snap-form#63: Introduced createTemplate/CreateTemplateSchema that this PR extends with price/isPublic fields.
  • Openlabsops/Snap-form#78: Also touches updateForm's handling of definition in form.controller.ts.

Suggested reviewers: Basharkhan7776

Poem

A rabbit hops with a template in tow,
Now public or private, price set just so 🥕
Community fields sprout new and bright,
Comments trimmed, code feels light,
Hop, hop — to the front page we go! 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The form controller edits are unrelated to the template community API requirements and appear outside the linked issue scope. Remove the unrelated form.controller.ts changes or split them into a separate PR focused on form-controller cleanup.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: community template API support and new public template fields.
Linked Issues check ✅ Passed The PR implements the community templates endpoint, search/category/pagination, and the required Template fields from issue #45.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/src/controllers/form.controller.ts`:
- Around line 170-172: The `definition` field in `form.controller.ts` has lost
its `UpdateFormInput["definition"]` type by being read directly from `req.body`,
so restore the typed contract by pulling it from the same `req.body as
UpdateFormInput` destructuring used for `title`, `description`, and the other
fields. Keep `definition` strongly typed before the
`FormDefinitionSchema.safeParse` call so TypeScript continues to enforce the
expected shape in the `updateForm` flow.

In `@apps/api/src/controllers/template.controller.ts`:
- Around line 53-54: The template creation logic in template.controller.ts is
forcing every template to be public because `isPublic || true` always becomes
true. Update the assignment in the template controller’s create flow to preserve
an explicit `false` value by using nullish coalescing or equivalent, while
keeping the `price` fallback behavior unchanged. Use the `isPublic` and `price`
fields in the controller method that builds the template payload so private
templates can be created correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a62e0526-ffbf-4867-9ee6-1c5e11492e00

📥 Commits

Reviewing files that changed from the base of the PR and between 91871fa and 7d1f27a.

📒 Files selected for processing (6)
  • apps/api/src/controllers/form.controller.ts
  • apps/api/src/controllers/template.controller.ts
  • apps/api/src/lib/template-schemas.ts
  • apps/api/src/routes/template/template.routes.ts
  • packages/db/prisma/migrations/20260701063302_add_template_price/migration.sql
  • packages/db/prisma/schema/templates.prisma
📜 Review details
🧰 Additional context used
🪛 SQLFluff (4.2.2)
packages/db/prisma/migrations/20260701063302_add_template_price/migration.sql

[error] 6-6: CREATE INDEX should use CONCURRENTLY to avoid locking the table during the build.

(PG01)

🔇 Additional comments (6)
packages/db/prisma/schema/templates.prisma (1)

11-14: LGTM!

Also applies to: 41-41

apps/api/src/lib/template-schemas.ts (1)

8-9: LGTM!

apps/api/src/controllers/template.controller.ts (1)

130-199: LGTM!

apps/api/src/routes/template/template.routes.ts (1)

7-15: LGTM!

packages/db/prisma/migrations/20260701063302_add_template_price/migration.sql (1)

5-6: 🚀 Performance & Scalability

Check whether this index should be created concurrently. On PostgreSQL, CONCURRENTLY avoids the table lock from CREATE INDEX, and Prisma 7.4+ can emit concurrent indexes directly; otherwise this is only worth changing if templates is large enough for the lock to matter.

apps/api/src/controllers/form.controller.ts (1)

17-20: LGTM!

Also applies to: 30-32, 90-91, 129-131, 139-142, 455-456, 465-468

Comment thread apps/api/src/controllers/form.controller.ts Outdated
Comment thread apps/api/src/controllers/template.controller.ts Outdated

@Basharkhan7776 Basharkhan7776 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging, will test in future

@Basharkhan7776
Basharkhan7776 merged commit 877b7ba into Openlabsops:main Jul 1, 2026
3 checks passed
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.

[Block] Template/Community & Templates APIs

2 participants