[Customer Entity] Extend POST /cases/search with date range, createdBy, and createdByMe filters - #902
Conversation
|
Warning Review limit reached
More reviews will be available in 53 minutes and 29 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. 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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughEight new optional filter fields are added to ChangesCase Search Filter Expansion
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
entity-service/internal/service/sn_case_service.go (1)
905-948:⚠️ Potential issue | 🟠 Major | ⚡ Quick winApply the same date-range ordering validation in the ServiceNow search path.
Line 905 flow forwards filters without rejecting inverted ranges, while the Postgres path (case_service) rejects them. That makes
/cases/searchbehavior backend-dependent and can send invalid filters downstream.Suggested fix
func (s *snCaseService) SearchCases(ctx context.Context, req domain.SearchCasesRequest) (domain.SearchCasesResponse, error) { if err := normalizePagination(&req.Pagination); err != nil { return domain.SearchCasesResponse{}, err } if err := validateSearchQuery(req.Filters.SearchQuery); err != nil { return domain.SearchCasesResponse{}, err } + if req.Filters.ClosedEndDate != nil && req.Filters.ClosedStartDate != nil && + req.Filters.ClosedEndDate.Before(*req.Filters.ClosedStartDate) { + return domain.SearchCasesResponse{}, &apierror.ValidationError{Msg: "closedEndDate must not be before closedStartDate"} + } + if req.Filters.EndCreatedDate != nil && req.Filters.StartCreatedDate != nil && + req.Filters.EndCreatedDate.Before(*req.Filters.StartCreatedDate) { + return domain.SearchCasesResponse{}, &apierror.ValidationError{Msg: "endCreatedDate must not be before startCreatedDate"} + } + if req.Filters.EndUpdatedDate != nil && req.Filters.StartUpdatedDate != nil && + req.Filters.EndUpdatedDate.Before(*req.Filters.StartUpdatedDate) { + return domain.SearchCasesResponse{}, &apierror.ValidationError{Msg: "endUpdatedDate must not be before startUpdatedDate"} + } token := middleware.UserIDTokenFromContext(ctx) if token == "" { return domain.SearchCasesResponse{}, &apierror.UnauthorizedError{Msg: "x-user-id-token header is required"} }🤖 Prompt for 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. In `@entity-service/internal/service/sn_case_service.go` around lines 905 - 948, The SearchCases method in snCaseService is missing date-range ordering validation that exists in the Postgres path (case_service). Add validation early in the SearchCases function to ensure that for all date range pairs in req.Filters (ClosedStartDate/ClosedEndDate, StartCreatedDate/EndCreatedDate, StartUpdatedDate/EndUpdatedDate), the start date is not greater than the end date. Return a ValidationError if any inverted ranges are detected, matching the pattern used in the Postgres implementation.
🤖 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.
Outside diff comments:
In `@entity-service/internal/service/sn_case_service.go`:
- Around line 905-948: The SearchCases method in snCaseService is missing
date-range ordering validation that exists in the Postgres path (case_service).
Add validation early in the SearchCases function to ensure that for all date
range pairs in req.Filters (ClosedStartDate/ClosedEndDate,
StartCreatedDate/EndCreatedDate, StartUpdatedDate/EndUpdatedDate), the start
date is not greater than the end date. Return a ValidationError if any inverted
ranges are detected, matching the pattern used in the Postgres implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: db5de7b1-6dcd-4bd6-bf32-2fa15f261810
📒 Files selected for processing (4)
entity-service/internal/domain/entity.goentity-service/internal/repository/case_repo.goentity-service/internal/service/case_service.goentity-service/internal/service/sn_case_service.go
…to POST /cases/search
ff1da6c to
7bc7751
Compare
…case search filters - Add POST /service-requests/search endpoint (entity-service PR #903) - Extend CaseSearchFilters with date range (closed/created/updated), createdBy, and createdByMe fields (entity-service PR #902) - Update OpenAPI spec with new path, schemas, and filter fields - Extend entityCaseClient interface and update test mock Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
closedStartDate,closedEndDate,startCreatedDate,endCreatedDate,startUpdatedDate,endUpdatedDate(UTC datetime) filters toPOST /cases/searchcreatedBy(array of emails) andcreatedByMe(boolean) filters;createdByMeresolves the caller's email from the JWT and appends it tocreatedBypriorityKeysis mapped toseverityKeysintegers and new filter fields are forwarded to the SN APISummary by CodeRabbit