[BE] PR 2/3: Point History Retrieval Logic (#216)#1118
Conversation
...enge-challenge/src/main/java/com/itachallenge/gamification/service/UserScoreServiceImpl.java
Show resolved
Hide resolved
...hallenge-challenge/src/main/java/com/itachallenge/gamification/service/UserScoreService.java
Show resolved
Hide resolved
| class PointsHistoryResponseDtoTest { | ||
|
|
||
| @Test | ||
| void testDtoStructure() { |
There was a problem hiding this comment.
Issues commented in orginal PR:
[ivilarop]:
This test only checks Lombok-generated builder/getters. It increases coverage but doesn’t protect behavior. If we want to validate the API contract, a Jackson serialization test (e.g., date mapping) would provide real value.
Answer:
[Lucy-SD]:
Done (in separated class).
There was a problem hiding this comment.
I understand that testDtoStructure is for coverage/Sonar, but now that we have @JsonTest that validates the actual contract, could we remove this test and the class?
There was a problem hiding this comment.
Apparently it could be done, I'll remove it and if for some reason Sonar fails again I'll add it back.
...-challenge/src/test/java/com/itachallenge/gamification/service/UserScoreServiceImplTest.java
Show resolved
Hide resolved
|
Issues addressed in original PR: [ivilarop]: Proposal: move the mapping to a private method in PointsServiceImpl (or to the stream itself using a lambda function), and if future reuse or further transformations arise (ISO date format, derived fields, etc.), then extract a PointsHistoryMapper with a specific name. Answer: |
carlosPc1987
left a comment
There was a problem hiding this comment.
This aligns well with the persistence layer we have in #1108:
UserScoreDocument with pointsEarned, UserScoreRepository.findByUserIdOrderByCreatedAtDesc,
and the unique index on (user_id, challenge_id).
The removal of distinct() is consistent with that.
When we merge both PRs we’ll have recordPoints (from #1108) and getUserPointsHistory (this PR) under the same UserScoreService naming.
No further comments from my side.
Good job Lucy!
pantalois
left a comment
There was a problem hiding this comment.
Good Lucy! I the work keeps improving!
...hallenge-challenge/src/main/java/com/itachallenge/gamification/service/UserScoreService.java
Show resolved
Hide resolved
...enge-challenge/src/main/java/com/itachallenge/gamification/service/UserScoreServiceImpl.java
Show resolved
Hide resolved
| class PointsHistoryResponseDtoTest { | ||
|
|
||
| @Test | ||
| void testDtoStructure() { |
There was a problem hiding this comment.
I understand that testDtoStructure is for coverage/Sonar, but now that we have @JsonTest that validates the actual contract, could we remove this test and the class?
.../src/test/java/com/itachallenge/challenge/dto/gamification/PointsHistoryResponseDtoTest.java
Show resolved
Hide resolved
...-challenge/src/test/java/com/itachallenge/gamification/service/UserScoreServiceImplTest.java
Show resolved
Hide resolved
# Conflicts: # CHANGELOG.md # itachallenge-challenge/src/main/java/com/itachallenge/gamification/document/UserScoreDocument.java # itachallenge-challenge/src/main/java/com/itachallenge/gamification/repository/UserScoreRepository.java # itachallenge-challenge/src/test/java/com/itachallenge/gamification/document/UserScoreDocumentTest.java # itachallenge-challenge/src/test/java/com/itachallenge/gamification/repository/UserScoreRepositoryTest.java
# Conflicts: # CHANGELOG.md
…e/dto/gamification/PointsHistoryResponseDtoTest.java
fce0295 to
ced6d51
Compare
.../src/test/java/com/itachallenge/challenge/dto/gamification/PointsHistoryResponseDtoTest.java
Show resolved
Hide resolved
|





Feature: Implementation of points history and accumulation logic
closes sub-issue: #IT-Academy-BCN/ita-challenges#216
📝 Description
Implementation of the core business logic to retrieve a student's point history. This service processes raw database entries into a structured format suitable for growth charts.
✅ Acceptance Criteria
totalPointsas the sum of all historical entries.🔧 Technical Details
PointsHistoryResponseDto(containstotalPointsand a list ofPointHistoryEntryDto).UserScoreServiceImpconsumes theFlux<UserScoreDocument>from the repository, usingcollectList()operator to process the data reactively. In a single transformation step, it calculates the arithmetic sum oftotalPointsand maps the documents to thePointHistoryEntryDto, returning aMono<PointsHistoryResponseDto>.UserNotFoundusing thecommon.exceptionpackage.💰 Value Provided
Transforms raw data into "Progress Information," allowing students to visualize their growth over time.
🔓Unlocks
Unblocks the final API Controller: sub-issue #217; and provides the data structure for Frontend graph components.
🔗 Dependencies
Chained to #215 - (PR #1107)
Closes #IT-Academy-BCN/ita-challenges#216
🧪 Test Implementations
🔄 Acceptance Criteria (DoD)
👨💻 Technical Debts
totalPointsis calculated on-the-fly. For high-volume users, an "Aggregated Totals" table might be needed in the future.