Skip to content

Add GET /plant/:id endpoint - #60

Merged
3 commits merged into
mainfrom
piersol-get-plants
Nov 22, 2026
Merged

3 commits merged into
mainfrom
piersol-get-plants

Conversation

@piersolh

@piersolh piersolh commented Nov 22, 2026 •

Copy link
Copy Markdown

ℹ️ Issue

Closes #20

📝 Description

Adds GET /plant/:id, which returns the full record for one plant plus the sites where it grows. The site page only previews up to 6 plants, so visitors who click one need this detail view.

Briefly list the changes made to the code:

  1. Added a plants module (controller, service, module) with GET /plant/:id.
  2. Added PlantResponseDto / PlantHostSiteDto as the typed response shape. Optional text fields are null when empty, and recipes / hostSites default to [].
  3. hostSites is loaded through the site_plants join table and includes all site types (existing and emerging).
  4. Malformed id returns 400, unknown id returns 404.
  5. Registered PlantsModule in app.module.ts and added a Plants swagger tag.
  6. Added unit tests for multiple host sites, no host sites, empty optional fields, 400, and 404.

✔️ Verification

  1. yarn test (full suite passes, including the new apps/backend/src/plants specs)
  2. yarn lint:check && npx nx build backend
  3. yarn migration:run && yarn seed && npx nx serve backend, then GET http://localhost:3000/api/plant/<seeded plant uuid> returns 200 with hostSites. /api/plant/abc returns 400 and a random valid UUID returns 404.

postman:

🏕️ (Optional) Future Work / Notes

  • The ticket says a numeric id, but Plant.id is a UUID, so any non-UUID (e.g. abc, 123) returns 400, consistent with GET /site/:id.
  • Field names follow the entity: name is mapped from plantName, siteType from Site.type, and imageUrl is built from imageS3Key (null if unset).
  • yarn format:check flags event-exception.entity.ts, which came from main (not touched here).

piersolh and others added 3 commits November 22, 2026 11:16
Adds a RolesGuard/@roles decorator (Cognito groups) for 403s, a validated
CreateAdminEventDto, service logic that 404s on unknown sites and inserts
into admin_events, extended response DTO, README docs and unit tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Returns the full plant record plus host sites via the site_plants join.
Malformed ids return 400, unknown ids return 404.
@saumyapalk23 saumyapalk23 closed this pull request by merging all changes into main in d4301d5 Nov 22, 2026
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.

bffc-20 GET /plant/{id}: Lists plant & information

2 participants