Bugfix: allow admin to update vet details and resolve user edit form …#258
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 24 minutes and 25 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis pull request adds update functionality for vet records across the frontend and backend. The frontend UserModal component now fetches existing vet data during edit mode and hydrates the form with license, specialization, and booking information. The backend introduces a new PUT endpoint and corresponding service method to update vet records with license conflict validation. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/src/components/admin/UserModal.jsx (1)
223-250:⚠️ Potential issue | 🟠 MajorAdd a
bookingInfocontrol so admins can edit all submitted vet details.
bookingInfois fetched and sent invetPayload, but the form only renders license and specialization fields. As-is, admins cannot change booking information through this edit flow.🛠️ Proposed UI addition
<div className="space-y-1.5"> <label htmlFor={specId} className="text-[10px] font-black text-blue-500 uppercase tracking-widest ml-1 italic block text-left">Specialisering</label> <input id={specId} className="w-full px-4 py-3 bg-blue-50/30 border border-blue-100 rounded-2xl focus:ring-2 focus:ring-blue-500 outline-none transition-all font-medium text-slate-700" placeholder="T.ex. Kirurgi" value={formData.specialization} onChange={(e) => setFormData({...formData, specialization: e.target.value})} /> </div> + <div className="space-y-1.5"> + <label className="text-[10px] font-black text-blue-500 uppercase tracking-widest ml-1 italic block text-left">Bokningsinformation</label> + <textarea + className="w-full px-4 py-3 bg-blue-50/30 border border-blue-100 rounded-2xl focus:ring-2 focus:ring-blue-500 outline-none transition-all font-medium text-slate-700" + placeholder="T.ex. bokningsbara tider eller instruktioner" + value={formData.bookingInfo} + onChange={(e) => setFormData({...formData, bookingInfo: e.target.value})} + /> + </div>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/src/components/admin/UserModal.jsx` around lines 223 - 250, The form only exposes licenseId and specialization but not the bookingInfo field, so admins can't edit bookingInfo even though it's included in vetPayload; update the UserModal component to add a controlled input (or textarea/select as appropriate) bound to formData.bookingInfo with onChange using setFormData({...formData, bookingInfo: e.target.value}), include an appropriate label and id (e.g., bookingInfoInput) alongside the existing VETERINÄR-DETALJER inputs, and ensure when submitting the modal the vetPayload still includes formData.bookingInfo so edits are sent to the backend.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/src/components/admin/UserModal.jsx`:
- Around line 42-53: When loading vet info in the UserModal (vetService.getAll
then setFormData), handle the case where no Vet row exists by creating one
instead of assuming update will succeed: detect whether vetRecord exists from
vetService.getAll (or catch a 404 from vetService.update) and call
vetService.create(...) with appropriate payload (userId from initialData.id and
fields like licenseId, specialization, bookingInfo) when absent; also update the
save/update handler that currently calls vetService.update(initialData.id, ...)
to fall back to vetService.create on a 404 error so converting OWNER/ADMIN→VET
creates the backend Vet row instead of failing.
In `@src/main/java/org/example/vet1177/services/VetService.java`:
- Around line 74-83: updateVet performs a pre-save duplicate-license check but
does not catch persistence-level unique constraint failures; wrap the
vetRepository.save(vet) call inside a try/catch that catches
DataIntegrityViolationException (same handling as createVet) and rethrow a
BusinessRuleException with a localized message like "Licens-ID X används redan"
(include request.licenseId()), so updateVet and createVet consistently translate
DB uniqueness violations into BusinessRuleException; reference updateVet,
vetRepository.save, DataIntegrityViolationException, and BusinessRuleException
when making the change.
---
Outside diff comments:
In `@frontend/src/components/admin/UserModal.jsx`:
- Around line 223-250: The form only exposes licenseId and specialization but
not the bookingInfo field, so admins can't edit bookingInfo even though it's
included in vetPayload; update the UserModal component to add a controlled input
(or textarea/select as appropriate) bound to formData.bookingInfo with onChange
using setFormData({...formData, bookingInfo: e.target.value}), include an
appropriate label and id (e.g., bookingInfoInput) alongside the existing
VETERINÄR-DETALJER inputs, and ensure when submitting the modal the vetPayload
still includes formData.bookingInfo so edits are sent to the backend.
🪄 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: CHILL
Plan: Pro
Run ID: a5ac726a-1548-40ba-b175-f9b7185a30e7
📒 Files selected for processing (5)
frontend/src/components/admin/UserModal.jsxfrontend/src/pages/AdminDashboard.jsxfrontend/src/services/api.jsxsrc/main/java/org/example/vet1177/controller/VetController.javasrc/main/java/org/example/vet1177/services/VetService.java
…issues (#232)
Summary by CodeRabbit
Release Notes
New Features
Improvements
Bug Fixes