Skip to content

Commit

Permalink
DEAR-129: add default workkinds per team
Browse files Browse the repository at this point in the history
  • Loading branch information
baurnick committed Jul 30, 2024
1 parent 89b0fbd commit 2bb415c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/main/java/ch/fhnw/deardevbackend/services/TeamService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,24 @@ public List<TeamAndRoleDTO> getTeamsAndRoleByUserId(Integer userId) {
public Team createTeam(CreateTeamDTO teamDTO) {
String uniqueCode = generateUniqueTeamCode();

Team team = createTeamMapper.toTeam(teamDTO);
team.setCode(uniqueCode);
Team savedTeam = teamRepository.save(team);

List<WorkKind> defaultWorkKinds = createDefaultWorkKinds(savedTeam.getId());
List<Integer> defaultWorkKindIds = defaultWorkKinds.stream().map(WorkKind::getId).toList();

TeamConfig config = TeamConfig.builder()
.workKindIds(Arrays.asList(1, 2))
.workKindIds(defaultWorkKindIds)
.happinessSurvey(true)
.workKindSurvey(true)
.emotionSurvey(true)
.build();

TeamConfig savedTeamConfig = teamConfigRepository.save(config);

Team team = createTeamMapper.toTeam(teamDTO);
team.setCode(uniqueCode);
team.setConfigId(savedTeamConfig.getId());

Team savedTeam = teamRepository.save(team);
savedTeam.setConfigId(savedTeamConfig.getId());
teamRepository.save(savedTeam);

TeamMember teamMember = TeamMember.builder()
.userId(teamDTO.getUserId())
Expand Down Expand Up @@ -171,4 +175,13 @@ private String generateUniqueTeamCode() {
public List<Integer> getTeamIdsForUser(int userId) {
return teamMemberRepository.findTeamIdByUserId(userId);
}

private List<WorkKind> createDefaultWorkKinds(Integer teamId) {
List<WorkKind> defaultWorkKinds = Arrays.asList(
new WorkKind(null, "Coding", teamId),
new WorkKind(null, "Meeting", teamId),
new WorkKind(null, "Scrum Events", teamId)
);
return workKindRepository.saveAll(defaultWorkKinds);
}
}

0 comments on commit 2bb415c

Please sign in to comment.