Skip to content

refactor (FS-495): demonstrate usage of records and mapstructs to simplify the codebase - #805

Draft
gsraich wants to merge 6 commits into
masterfrom
refactor/FS-495
Draft

refactor (FS-495): demonstrate usage of records and mapstructs to simplify the codebase#805
gsraich wants to merge 6 commits into
masterfrom
refactor/FS-495

Conversation

@gsraich

@gsraich gsraich commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

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 records and MapStruct.

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.

…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
@gsraich gsraich changed the title refactor (FS-495) refactor (FS-495): demonstrate usage of records and mapstructs to simplify the codebase Aug 20, 2026
@guyjackson-ch
guyjackson-ch requested a balanced review from Copilot August 24, 2026 08:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants