Skip to content

refactor: move mapping logic from services to mapper class - #54

Merged
Dejmenek merged 3 commits into
mainfrom
52-refactor-mapping-logic-to-mappercs
Oct 27, 2025
Merged

Dejmenek merged 3 commits into
mainfrom
52-refactor-mapping-logic-to-mappercs

Conversation

@Dejmenek

Copy link
Copy Markdown
Owner

Summary

This pull request moves mapping logic from services to mapper class.

Changes

  • Mapper.cs: Added methods ToStackDTOList, ToCardDTOList, and ToStudySessionDTOList for batch conversion of entities to DTOs.
  • CardsService.cs: Refactored to use Mapper.ToCardDTOList, replacing manual iteration for card conversion.
  • StacksService.cs: Updated to utilize Mapper.ToStackDTOList for stack DTO conversion, improving clarity.
  • StudySessionsService.cs: Modified to employ Mapper.ToStudySessionDTOList, simplifying study session DTO conversion.

A new method `ToCardDTOList` was added to the `Mapper` class in `Mapper.cs` to convert an `IEnumerable<BaseCard>` to a `List<BaseCardDto>`. This change replaces the previous `foreach` loop and `switch` statement in both the `CardsService` and `StacksService` classes with a call to the new method, simplifying the code and enhancing maintainability. This refactor improves the overall structure and readability of the card conversion logic.
Added a new method `ToStudySessionDTOList` in the `Mapper` class to convert a collection of `StudySession` objects into a list of `StudySessionDto` objects using LINQ.

Updated the `StudySessionsService` class to utilize this new method, replacing a manual loop for conversion. This change simplifies the code and enhances readability by leveraging the new mapping functionality.
@Dejmenek Dejmenek linked an issue Oct 27, 2025 that may be closed by this pull request
@Dejmenek
Dejmenek merged commit 8f78d0a into main Oct 27, 2025
2 checks passed
@Dejmenek
Dejmenek deleted the 52-refactor-mapping-logic-to-mappercs branch October 27, 2025 13:48
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.

Refactor Mapping Logic to Mapper.cs

1 participant