From 4d094464cc8062726e8233c59314d03313d5facc Mon Sep 17 00:00:00 2001 From: Amar Bolkan Date: Mon, 28 Nov 2022 17:51:02 +0100 Subject: [PATCH] Issue #151: Retrieve teamSkills inside TeamScoreService --- .../custom/CustomTeamScoreServiceImpl.java | 21 +++++++++++++++++++ .../CustomTeamScoreServiceImplTest.java | 8 ++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java b/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java index cc3536ce..cd049e3e 100644 --- a/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java +++ b/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java @@ -4,19 +4,32 @@ */ package com.iteratec.teamdojo.service.impl.custom; +import com.iteratec.teamdojo.service.TeamSkillQueryService; +import com.iteratec.teamdojo.service.criteria.TeamSkillCriteria; import com.iteratec.teamdojo.service.custom.CustomTeamScoreService; import com.iteratec.teamdojo.service.dto.TeamDTO; +import com.iteratec.teamdojo.service.dto.TeamSkillDTO; import com.iteratec.teamdojo.service.dto.custom.TeamScoreDTO; +import java.util.Collection; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import tech.jhipster.service.filter.LongFilter; @Service @Slf4j public class CustomTeamScoreServiceImpl implements CustomTeamScoreService { + private final TeamSkillQueryService teamSkillQueryService; + + public CustomTeamScoreServiceImpl(TeamSkillQueryService teamSkillQueryService) { + this.teamSkillQueryService = teamSkillQueryService; + } + @Override public TeamScoreDTO calculateTeamScore(@NonNull final TeamDTO t) { + final var teamSkills = this.retrieveTeamSkills(t.getId()); + final var achieved = calculateAchieved(); final var required = calculateRequired(); final var totalScore = calculateTotalScore(); @@ -44,4 +57,12 @@ float calculateProgressInPercent() { boolean calculateCompleted(final int achieved, final int required) { return achieved >= required; } + + private Collection retrieveTeamSkills(final long teamId) { + final var teamSkillCriteria = new TeamSkillCriteria(); + final var longFilter = new LongFilter(); + longFilter.setEquals(teamId); + teamSkillCriteria.setTeamId(longFilter); + return this.teamSkillQueryService.findByCriteria(teamSkillCriteria); + } } diff --git a/src/test/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImplTest.java b/src/test/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImplTest.java index f182f1f3..af1e07f3 100644 --- a/src/test/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImplTest.java +++ b/src/test/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImplTest.java @@ -3,14 +3,20 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import com.iteratec.teamdojo.repository.TeamSkillRepository; +import com.iteratec.teamdojo.service.TeamSkillQueryService; import org.junit.jupiter.api.Test; +import org.mockito.Mock; /** * */ class CustomTeamScoreServiceImplTest { - private final CustomTeamScoreServiceImpl sut = new CustomTeamScoreServiceImpl(); + @Mock + private TeamSkillQueryService teamSkillQueryService; + + private final CustomTeamScoreServiceImpl sut = new CustomTeamScoreServiceImpl(teamSkillQueryService); @Test void calculateProgress() {}