Skip to content

Commit

Permalink
DEAR-120 submit emotion survey
Browse files Browse the repository at this point in the history
  • Loading branch information
smuefsmuef committed Jul 20, 2024
1 parent 5aba8a5 commit 56f376a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ch.fhnw.deardevbackend.controller;

import ch.fhnw.deardevbackend.dto.DashboardDTO;
import ch.fhnw.deardevbackend.dto.SubmitEmotionSurveyDTO;
import ch.fhnw.deardevbackend.dto.SubmitHappinessSurveyDTO;
import ch.fhnw.deardevbackend.dto.SubmitWorkKindSurveyDTO;
import ch.fhnw.deardevbackend.entities.EmotionSurvey;
import ch.fhnw.deardevbackend.entities.HappinessSurvey;
import ch.fhnw.deardevbackend.entities.WorkKindSurvey;
import ch.fhnw.deardevbackend.services.DashboardService;
Expand Down Expand Up @@ -42,4 +44,10 @@ public ResponseEntity<WorkKindSurvey> submitWorkKindSurvey(@RequestBody SubmitWo
WorkKindSurvey data = dashboardService.save(request);
return ResponseEntity.ok().body(data);
}

@PostMapping("survey/emotion")
public ResponseEntity<EmotionSurvey> submitEmotionSurvey(@RequestBody SubmitEmotionSurveyDTO request) {
EmotionSurvey data = dashboardService.save(request);
return ResponseEntity.ok().body(data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ch.fhnw.deardevbackend.dto;

import lombok.Data;

@Data
public class SubmitEmotionSurveyDTO {
private int userId;
private int emotionId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class EmotionSurvey {
private int id;

@Column(name = "user_id")
private String userId;
private int userId;

@Column(name = "submitted")
@Column(name = "submitted", columnDefinition = "TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false)
private String submitted;

@Column(name = "score")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ch.fhnw.deardevbackend.mapper;

import ch.fhnw.deardevbackend.dto.SubmitEmotionSurveyDTO;
import ch.fhnw.deardevbackend.entities.EmotionSurvey;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;


@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SubmitEmotionSurveyMapper {
SubmitEmotionSurveyMapper INSTANCE = Mappers.getMapper(SubmitEmotionSurveyMapper.class);

@Mapping(target = "submitted", expression = "java(java.time.OffsetDateTime.now().toString())")
EmotionSurvey toEmotionSurvey(SubmitEmotionSurveyDTO dto);
}

Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package ch.fhnw.deardevbackend.services;

import ch.fhnw.deardevbackend.dto.DashboardDTO;
import ch.fhnw.deardevbackend.dto.SubmitEmotionSurveyDTO;
import ch.fhnw.deardevbackend.dto.SubmitHappinessSurveyDTO;
import ch.fhnw.deardevbackend.dto.SubmitWorkKindSurveyDTO;
import ch.fhnw.deardevbackend.entities.EmotionSurvey;
import ch.fhnw.deardevbackend.entities.HappinessSurvey;
import ch.fhnw.deardevbackend.entities.WorkKind;
import ch.fhnw.deardevbackend.entities.WorkKindSurvey;
import ch.fhnw.deardevbackend.mapper.DashboardMapper;
import ch.fhnw.deardevbackend.mapper.SubmitEmotionSurveyMapper;
import ch.fhnw.deardevbackend.mapper.SubmitHappinessSurveyMapper;
import ch.fhnw.deardevbackend.mapper.SubmitWorkKindSurveyMapper;
import ch.fhnw.deardevbackend.repositories.HappinessSurveyRepository;
import ch.fhnw.deardevbackend.repositories.WorkKindRepository;
import ch.fhnw.deardevbackend.repositories.WorkKindSurveyRepository;
import ch.fhnw.deardevbackend.repositories.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -29,6 +30,9 @@ public class DashboardService {
@Autowired
private WorkKindSurveyRepository workKindSurveyRepository;

@Autowired
private EmotionSurveyRepository emotionSurveyRepository;

@Autowired
private WorkKindRepository workKindRepository;

Expand All @@ -38,6 +42,9 @@ public class DashboardService {
@Autowired
private SubmitWorkKindSurveyMapper submitWorkKindSurveyMapper;

@Autowired
private SubmitEmotionSurveyMapper submitEmotionSurveyMapper;

@Transactional
public HappinessSurvey save(SubmitHappinessSurveyDTO dto) {
HappinessSurvey survey = submitHappinessSurveyMapper.toHappinessSurvey(dto);
Expand All @@ -50,6 +57,12 @@ public WorkKindSurvey save(SubmitWorkKindSurveyDTO dto) {
return workKindSurveyRepository.save(survey);
}

@Transactional
public EmotionSurvey save(SubmitEmotionSurveyDTO dto) {
EmotionSurvey survey = submitEmotionSurveyMapper.toEmotionSurvey(dto);
return emotionSurveyRepository.save(survey);
}

@Transactional(readOnly = true)
public Integer getAverageScoreByUserId(int userId) {
List<Object[]> dailyAverages = happinessSurveyRepository.findDailyAveragesByUserId(userId);
Expand Down

0 comments on commit 56f376a

Please sign in to comment.