refactor (FS-495): demonstrate usage of records and mapstructs to simplify the codebase - #805
Draft
gsraich wants to merge 6 commits into
Draft
refactor (FS-495): demonstrate usage of records and mapstructs to simplify the codebase#805gsraich wants to merge 6 commits into
gsraich wants to merge 6 commits into
Conversation
…ies taking over the link construction logic from the ResponseMapper. This co-locates the URL format strings with the data they produce.
…o a test data builder, add MapStruct dependency to convert CompanyProfileApi to CompanyProfile via MapStruct mapping instead of using the builder.
…creator from controllers, use MapStruct to map DissolutionUserData to CreatedBy dao
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors immutable data objects using Java records and MapStruct, simplifying mapping and reducing boilerplate.
Changes:
- Converts company profiles, user data and dissolution links to records.
- Introduces MapStruct mappers and immutable test builders.
- Updates services, controllers and tests for the new interfaces.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pom.xml |
Adds MapStruct and annotation processing. |
src/main/java/uk/gov/companieshouse/controller/DissolutionController.java |
Constructs immutable user data. |
src/main/java/uk/gov/companieshouse/controller/TransactionsDissolutionController.java |
Constructs immutable user data for drafts. |
src/main/java/uk/gov/companieshouse/mapper/CompanyProfileMapper.java |
Adds company-profile mapping. |
src/main/java/uk/gov/companieshouse/mapper/CreatedByMapper.java |
Adds created-by mapping. |
src/main/java/uk/gov/companieshouse/mapper/DissolutionDirectorResponseMapper.java |
Uses link factories. |
src/main/java/uk/gov/companieshouse/mapper/DissolutionRequestMapper.java |
Uses records and MapStruct. |
src/main/java/uk/gov/companieshouse/mapper/DissolutionResponseMapper.java |
Uses immutable links. |
src/main/java/uk/gov/companieshouse/mapper/DissolutionUserDataMapper.java |
Removes obsolete mapper. |
src/main/java/uk/gov/companieshouse/mapper/ResponseMapper.java |
Removes superseded link helper. |
src/main/java/uk/gov/companieshouse/model/domain/DissolutionUserData.java |
Converts user data to a record. |
src/main/java/uk/gov/companieshouse/model/dto/companyprofile/CompanyProfile.java |
Converts company profile to a record. |
src/main/java/uk/gov/companieshouse/model/dto/dissolution/DissolutionLinks.java |
Converts links to a record with factories. |
src/main/java/uk/gov/companieshouse/service/CompanyProfileService.java |
Delegates profile conversion to MapStruct. |
src/main/java/uk/gov/companieshouse/service/dissolution/DissolutionCreator.java |
Accepts immutable user data. |
src/main/java/uk/gov/companieshouse/service/dissolution/DissolutionService.java |
Propagates immutable user data. |
src/main/java/uk/gov/companieshouse/service/dissolution/validator/CompanyClosableValidator.java |
Uses record accessors. |
src/test/java/uk/gov/companieshouse/controller/DissolutionControllerTest.java |
Updates controller tests. |
src/test/java/uk/gov/companieshouse/controller/TransactionsDissolutionControllerTest.java |
Updates draft-controller tests. |
src/test/java/uk/gov/companieshouse/fixtures/CompanyProfileFixtures.java |
Removes mutable profile fixture. |
src/test/java/uk/gov/companieshouse/fixtures/CompanyProfileTestDataBuilder.java |
Adds immutable profile builder. |
src/test/java/uk/gov/companieshouse/fixtures/DissolutionFixtures.java |
Updates user-data fixture. |
src/test/java/uk/gov/companieshouse/mapper/CompanyProfileMapperTest.java |
Tests profile mapping. |
src/test/java/uk/gov/companieshouse/mapper/DissolutionDirectorResponseMapperTest.java |
Updates link assertions. |
src/test/java/uk/gov/companieshouse/mapper/DissolutionRequestMapperTest.java |
Tests record-based mapping. |
src/test/java/uk/gov/companieshouse/mapper/DissolutionResponseMapperTest.java |
Updates immutable-link assertions. |
src/test/java/uk/gov/companieshouse/model/dto/companyprofile/CompanyProfileTest.java |
Removes obsolete mutable-model tests. |
src/test/java/uk/gov/companieshouse/service/CompanyProfileServiceTest.java |
Tests mapper integration. |
src/test/java/uk/gov/companieshouse/service/dissolution/DissolutionCreatorTest.java |
Updates creator tests. |
src/test/java/uk/gov/companieshouse/service/dissolution/DissolutionServiceTest.java |
Updates service tests. |
src/test/java/uk/gov/companieshouse/service/dissolution/validator/CompanyClosableValidatorTest.java |
Uses immutable profiles. |
src/test/java/uk/gov/companieshouse/service/dissolution/validator/DissolutionValidatorTest.java |
Uses immutable profiles and JUnit 5. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JIRA Ticket ID: FS-495
Description
This PR demonstrates the refactoring of a few domain / dto / dao objects we have in the api by leveraging Java
recordsandMapStruct.The core idea is that all the setters on these classes are suboptimal, they are just data objects that can be immutable, we can reduce the LOC and therefore the cognitive load when working on the API.