Refactor: Introduce service layer and thin down controller layer#207
Refactor: Introduce service layer and thin down controller layer#207anderslindho merged 8 commits intoChannelFinder:masterfrom
Conversation
3105641 to
2082fad
Compare
- Add LegacyApiProperties @ConfigurationProperties bean for channelfinder.legacy.service-root, normalizing leading/trailing slashes; defaults to ChannelFinder. - Remove hardcoded CFResourceDescriptors constants from all six API interface @RequestMapping declarations; interfaces now carry only HTTP method contracts. - Inject scroll resource URI via @value in ChannelRepository to avoid static constant coupling. - Document the property in application.properties.
fb0a338 to
59eebe9
Compare
jacomago
left a comment
There was a problem hiding this comment.
I don't particularly like the name legacy, I would prefer v0 or something clearer. Legacy is confusing as if you have two things called legacy or old, you don't know what the sequence is.
59eebe9 to
7afee66
Compare
|
Weird you manage to have both code coverage and integration tests working and now they are failing again... |
…egation All business logic (authorization, validation, orchestration) moves out of controllers into dedicated application services. Controllers now contain only constructor injection and single-line delegation calls. - Add ChannelService, TagService, PropertyService, InfoService, ChannelScrollService. - Move processAllChannels scroll orchestration and CF_ADMIN auth check into ChannelProcessorService; remove IChannelScroll dependency from its controller. - Add seven domain exception types (ChannelNotFoundException, TagNotFoundException, PropertyNotFoundException, *ValidationException, UnauthorizedException). - Add ChannelFinderExceptionHandler (@RestControllerAdvice) mapping domain exceptions to HTTP status codes. - Remove validateChannelRequest/validateTagRequest/validatePropertyRequest from API interfaces; validation now lives entirely in the service layer. - Switch all six controllers to constructor injection. - Update ChannelProcessorServiceTest to match the expanded constructor signature.
Introduce a web package hierarchy that makes the structural intent clear and leaves room for a future web.v1 package alongside it. - rest.api.* -> web.v0.api.* - rest.controller.* -> web.v0.controller.* - ChannelFinderExceptionHandler -> web (cross-cutting, not legacy-specific) Update all test imports accordingly. No behaviour change.
Replace the implicit per-controller @crossorigin annotations with an explicit CorsConfigurationSource bean in WebSecurityConfig, backed by a configurable cors.allowed-origins property (default: *). - Remove @crossorigin from all legacy controllers (committed as fixup). - Add corsConfigurationSource() bean and wire it into the filter chain. - Document the property in application.properties.
…n errors Bulk requests of 1500+ channels with rich property payloads exceeded the default ES circuit-breaker limit (~102 MiB), causing 429/413 rejections in CI. Split channel inserts into batches of 1000 and throw on bulk errors rather than logging and continuing with a silently empty index. Same fail-fast treatment applied to checkBulkResponse (properties/tags).
7afee66 to
8cb3de5
Compare
Unmapped exceptions (NPE, unexpected RuntimeException, etc.) bypassed the advice entirely and fell through to Spring's default error handler, which can leak a full stack trace to the client depending on server configuration. - Add catch-all @ExceptionHandler(Exception.class) returning 500 with a generic message; log at SEVERE with the full exception cause - Downgrade 4xx handler log level from SEVERE to WARNING — client errors are not server faults and SEVERE drowns out real failures - Pass ex as third argument to logger.log in all handlers so stack traces are preserved rather than swallowed
The fall-back exception handler 🙃 FWIW I always had either both passing or both failing, in case you are insinuating that the tests historically have been flaky. |
8cb3de5 to
d1c071d
Compare
jacomago
left a comment
There was a problem hiding this comment.
I would prefer anything you added called legacy be v0 instead.
The advice is scoped to web.v0.controller and returns ResponseStatusException, which is the pre-Spring 6 style. Marking it @deprecated and naming it V0ExceptionHandler makes room for a global ChannelFinderExceptionHandler using ProblemDetail (RFC 9457) when the v1 API lands — the absence of that file is an intentional prompt to add it.
45c756a
d1c071d to
45c756a
Compare
|



Moves towards a clean controller -> service -> repository layering as the foundation for a future versioned REST API.