Skip to content

Commit

Permalink
DEAR-130 dto, endpoint for all insights
Browse files Browse the repository at this point in the history
  • Loading branch information
smuefsmuef committed Jul 29, 2024
1 parent 0f7c08c commit 589f899
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ public class InsightsController {
@Autowired
private InsightsService insightsService;

// Line Chart: overall happiness team vs personal
// Overall
@GetMapping("/{userId}/team/{teamId}/sprint/{sprint}")
public ResponseEntity<List<InsightDTO>> getInsightsByTeam(
@PathVariable Integer userId,
@PathVariable Integer teamId,
@PathVariable String sprint) {
List<InsightDTO> insights = insightsService.getInsightsByTeamAndSprint(userId, teamId, sprint);
return ResponseEntity.ok(insights);
}

// happiness team vs personal
@GetMapping("/happiness/{userId}/team/{teamId}/sprint/{sprint}")
public ResponseEntity<List<HappinessInsightDTO>> getHappinessInsightsByTeam(
@PathVariable Integer userId, @PathVariable Integer teamId, @PathVariable String sprint) {
Expand All @@ -29,22 +39,4 @@ public ResponseEntity<List<HappinessInsightDTO>> getHappinessInsightsByTeam(
}
}

// Bar Chart: workkind team vs personal
@GetMapping("/workkind/{userId}/team/{teamId}/sprint/{sprint}")
public List<TeamWorkKindInsightDTO> getWorkKindHappinessByUserId(@PathVariable Integer userId, @PathVariable Integer teamId, @PathVariable String sprint) {
// return insightsService.getWorkKindHappinessByUserId(userId);
return List.of();
}

// Line Chart/Area Chart: velocity of the sprint vs happiness vs workkind
// no timestamp
// y: workkind, velocity
// x: days

// Radar Chart
// Top 10 Emotions Personal & Team

// Radar Chart
// Top 10 Workkinds Personal & Team

}
11 changes: 11 additions & 0 deletions src/main/java/ch/fhnw/deardevbackend/dto/InsightDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.fhnw.deardevbackend.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class InsightDTO {
HappinessInsightDTO happinessInsightDTO;
WorkKindInsightDTO workKindInsightDTO;
}
28 changes: 21 additions & 7 deletions src/main/java/ch/fhnw/deardevbackend/services/InsightsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ public InsightsService(InsightsRepository insightsRepository,
this.workKindInsightMapper = workKindInsightMapper;
}

@Transactional(readOnly = true)
public List<InsightDTO> getInsightsByTeamAndSprint(@ValidateUserIdParam Integer userId, Integer teamId, String sprint) {
List<HappinessInsightDTO> happinessInsights = getHappinessInsightsByTeam(userId, teamId, sprint);
List<WorkKindInsightDTO> workKindInsights = getWorkKindInsightsByUserId(userId);

return happinessInsights.stream()
.map(happinessInsightDTO -> new InsightDTO(happinessInsightDTO, findMatchingWorkKindInsight(happinessInsightDTO, workKindInsights)))
.collect(Collectors.toList());
}

// todo later asap structure is defined
private WorkKindInsightDTO findMatchingWorkKindInsight(HappinessInsightDTO happinessInsightDTO, List<WorkKindInsightDTO> workKindInsights) {
return workKindInsights.stream()
// .filter(workKindInsightDTO -> workKindInsightDTO.getTeamId().equals(happinessInsightDTO.getTeamId()))
.findFirst()
.orElse(null);
}


@Transactional(readOnly = true)
public List<TeamHappinessInsightDTO> getDailyAveragesByUserId(@ValidateUserIdParam Integer userId) {
List<Integer> teamIds = teamMemberRepository.findTeamIdByUserId(userId);
Expand Down Expand Up @@ -113,23 +132,18 @@ public List<HappinessInsightDTO> getHappinessInsightsByTeam(@ValidateUserIdParam

}


@Transactional(readOnly = true)
public List<TeamWorkKindInsightDTO> getWorkKindHappinessByUserId(@ValidateUserIdParam Integer userId) {
public List<WorkKindInsightDTO> getWorkKindInsightsByUserId(@ValidateUserIdParam Integer userId) {
List<Object[]> results = insightsRepository.findWorkKindHappinessByUserId(userId);

Map<Integer, List<WorkKindInsightDTO>> groupedByTeam = results.stream()
return results.stream()
.map(row -> workKindInsightMapper.toDTO(
(Integer) row[0],
(Integer) row[1],
(String) row[2],
(Double) row[3],
(Long) row[4]
))
.collect(Collectors.groupingBy(WorkKindInsightDTO::getTeamId));

return groupedByTeam.entrySet().stream()
.map(entry -> new TeamWorkKindInsightDTO(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
}

0 comments on commit 589f899

Please sign in to comment.