Skip to content

Commit

Permalink
Dear 120 survey datamodel
Browse files Browse the repository at this point in the history
* DEAR-115: add datamodel for team

* DEAR-115: fix user service tests

* DEAR-115: add create team endpoint

* DEAR-115: add join team endpoint

* DEAR-120 add swagger-api to allowed requests

* DEAR-120 add init sqls and testdata

* DEAR-120 adjust timestamp, add entities

* DEAR-120 add all entities

* DEAR-120 add all repos

* DEAR-120 add overall happiness score service & controller

* DEAR-120 remove comment

* DEAR-120 checkstyle

* DEAR-120 adjust table names

* DEAR-120 rename service, controller, add emotionSurveyRepo

* DEAR-120 set userids testdata

* DEAR-120 submit happiness survey

* DEAR-120 set userids testdata

* DEAR-120 get overallhappiness

* DEAR-120 add workkinds

* DEAR-120 add workkinds, add logger

* DEAR-120 add workkind controller

* DEAR-120 refactor

* DEAR-120 add emotion api, checkstyle

* DEAR-120 submit emotion survey

* DEAR-120 update emotion_survey_data

* DEAR-120 improve get dashbaord data

* DEAR-120 add unit tests

* DEAR-120 add exceptions, unit tests

* DEAR-120 add happinessScore most voted, unit tests

* DEAR-120 get happiness average score for workkind

* DEAR-120 fix checkstyle

* DEAR-120 review

* DEAR-120 update query to use dto

* DEAR-120 wip review

* DEAR-120 resolve conflicts

* DEAR-120 resolve conflicts

* DEAR-120 clean up workkinds

---------

Co-authored-by: Nick Baur <79518844+baurnick@users.noreply.github.com>
  • Loading branch information
smuefsmuef and baurnick authored Jul 22, 2024
1 parent 59d1f05 commit 9c6e893
Show file tree
Hide file tree
Showing 35 changed files with 1,088 additions and 15 deletions.
53 changes: 52 additions & 1 deletion database/01_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,55 @@ CREATE TABLE team_config

-- Add constraints to the tables
ALTER TABLE team
ADD CONSTRAINT fk_team_team_config FOREIGN KEY (config_id) REFERENCES team_config (id);
ADD CONSTRAINT fk_team_team_config FOREIGN KEY (config_id) REFERENCES team_config (id);

-- Create tables for DEAR-120-SURVEY DATA
------------------------------------------------------------------------------------------------------------------------

CREATE TABLE work_kind
(
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
team_id INTEGER,

CONSTRAINT fk_team FOREIGN KEY (team_id) REFERENCES team (id)
);

CREATE TABLE emotion
(
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL
);

CREATE TABLE happiness_survey
(
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
submitted TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
score INTEGER NOT NULL,

CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id)
);

CREATE TABLE work_kind_survey
(
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
submitted TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
score INTEGER NOT NULL,
work_kind_id INTEGER NOT NULL,

CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id),
CONSTRAINT fk_work_kind FOREIGN KEY (work_kind_id) REFERENCES work_kind (id)
);

CREATE TABLE emotion_survey
(
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
submitted TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
emotion_id INTEGER NOT NULL,

CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id),
CONSTRAINT fk_emotion FOREIGN KEY (emotion_id) REFERENCES emotion (id)
);
62 changes: 51 additions & 11 deletions database/02_test_data.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
INSERT INTO public.users (id, name, email, "emailVerified", image, username)
VALUES (1, 'Hans Müller', 'hans@test.com', null, null, 'Hansi');
INSERT INTO users (id, name, email, "emailVerified", image, username)
VALUES (100001, 'Hans Müller', 'hans@test.com', null, null, 'Hansi'),
(100002, 'Berta Roberts', 'berti@test.com', null, null, 'Berti');

INSERT INTO public.team (id, name, current_sprint_id, config_id, code, created_by, created_at, active)
VALUES (1, 'Team Alpha', null, null, 'ALF1', 1, '2024-07-13 15:19:11.164000 +00:00', true);
INSERT INTO public.team (id, name, current_sprint_id, config_id, code, created_by, created_at, active)
VALUES (2, 'Team Beta', null, null, 'BET2', 1, '2024-07-13 15:20:22.162000 +00:00', true);
INSERT INTO team (id, name, current_sprint_id, config_id, code, created_by, created_at, active)
VALUES (998, 'Team Alpha', null, null, 'ALF1', 100001, '2024-07-13 15:19:11.164000 +00:00', true),
(999, 'Team Beta', null, null, 'BET2', 100001, '2024-07-13 15:20:22.162000 +00:00', true);

INSERT INTO public.team_member (id, user_id, team_id, role, active)
VALUES (1, 1, 1, 'ADMIN', true);
INSERT INTO public.team_member (id, user_id, team_id, role, active)
VALUES (2, 1, 2, 'MEMBER', true);
INSERT INTO team_member (id, user_id, team_id, role, active)
VALUES (990, 100001, 998, 'ADMIN', true);
INSERT INTO team_member (id, user_id, team_id, role, active)
VALUES (999, 100002, 999, 'MEMBER', true);

INSERT INTO public.team_config (id, work_kinds)
INSERT INTO team_config (id, work_kinds)
VALUES (1, '{CODING,MEETING}');

INSERT INTO work_kind (name)
VALUES ('Coding'),
('Meeting'),
('Daily Standup'),
('Planning'),
('Review'),
('Retrospective');
INSERT INTO work_kind (name, team_id)
VALUES ('Team Huddle', 998),
('Bowling', 999);

INSERT INTO emotion (name)
VALUES ('Angry'),
('Bored'),
('Busy'),
('Disappointed'),
('Energetic'),
('Exhausted'),
('Frustrated'),
('Lonely'),
('Motivated'),
('Nervous'),
('Overwhelmed'),
('Pessimistic'),
('Relaxed'),
('Sick'),
('Stressed');

INSERT INTO happiness_survey (user_id, score)
VALUES (100001, 4),
(100001, 2),
(100001, 3),
(100002, 1);
INSERT INTO work_kind_survey (user_id, score, work_kind_id)
VALUES (100001, 6, 1),
(100002, 7, 2);
INSERT INTO emotion_survey (user_id, emotion_id)
VALUES (100001, 1),
(100002, 2);
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authz -> authz
.requestMatchers("/auth/token").permitAll()
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html").permitAll()
.anyRequest().authenticated())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.formLogin(AbstractHttpConfigurer::disable)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/v1/dashboard")
public class DashboardController {
@Autowired
private DashboardService dashboardService;

// todo ensure only logged in user can post his entries

@GetMapping("/{userId}")
public ResponseEntity<DashboardDTO> getDashboardDataByUserId(@PathVariable Integer userId) {
DashboardDTO dashboardDTO = dashboardService.getDashboardDataByUserId(userId);
return ResponseEntity.ok().body(dashboardDTO);
}

@GetMapping("/happiness/average/{userId}")
public ResponseEntity<Integer> getAverageScoreByUserId(@PathVariable Integer userId) {
Integer averageScore = dashboardService.getAverageScoreByUserId(userId);
return ResponseEntity.ok().body(averageScore);
}

@PostMapping("/survey/happiness")
public ResponseEntity<HappinessSurvey> submitHappinessSurvey(@RequestBody SubmitHappinessSurveyDTO request) {
HappinessSurvey data = dashboardService.saveHappinessSurvey(request);
return ResponseEntity.ok().body(data);
}

@PostMapping("survey/workkind")
public ResponseEntity<WorkKindSurvey> submitWorkKindSurvey(@RequestBody SubmitWorkKindSurveyDTO request) {
WorkKindSurvey data = dashboardService.saveWorkKindSurvey(request);
return ResponseEntity.ok().body(data);
}

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

import ch.fhnw.deardevbackend.entities.Emotion;
import ch.fhnw.deardevbackend.services.EmotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/emotions")
public class EmotionController {

@Autowired
private EmotionService emotionService;

@GetMapping()
public ResponseEntity<List<Emotion>> getAllEmotions() {
List<Emotion> emotions = emotionService.getEmotions();
return ResponseEntity.ok(emotions);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ch.fhnw.deardevbackend.controller;

import ch.fhnw.deardevbackend.entities.WorkKind;
import ch.fhnw.deardevbackend.services.WorkKindService;
import ch.fhnw.deardevbackend.services.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/workkinds")
public class WorkKindController {

@Autowired
private WorkKindService workKindService;

@Autowired
private TeamService teamService;


@GetMapping("/user/{userId}")
public ResponseEntity<List<WorkKind>> getAllWorkKindsByUserAndTeam(@PathVariable Integer userId) {
List<Integer> teamIds = teamService.getTeamIdsForUser(userId);
List<WorkKind> workKinds = workKindService.getWorkKindsForTeams(teamIds);
return ResponseEntity.ok(workKinds);
}
}
16 changes: 16 additions & 0 deletions src/main/java/ch/fhnw/deardevbackend/dto/DashboardDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ch.fhnw.deardevbackend.dto;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DashboardDTO {
private MostVotedWorkKindDTO mostVotedWorkKind;
private Integer averageScore;


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

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MostVotedWorkKindDTO {
private Integer workKindId;
private String workKindName;
private Integer voteCount;
private Integer happinessScore;
}
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 Integer userId;
private Integer emotionId;
}
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 SubmitHappinessSurveyDTO {
private Integer userId;
private Integer score;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ch.fhnw.deardevbackend.dto;

import lombok.Data;

@Data
public class SubmitWorkKindSurveyDTO {
private Integer userId;
private Integer score;
private Integer workKindId;
}
22 changes: 22 additions & 0 deletions src/main/java/ch/fhnw/deardevbackend/entities/Emotion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ch.fhnw.deardevbackend.entities;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "emotion")
@Builder
@Data
public class Emotion {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(name = "name")
private String name;
}
33 changes: 33 additions & 0 deletions src/main/java/ch/fhnw/deardevbackend/entities/EmotionSurvey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ch.fhnw.deardevbackend.entities;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "emotion_survey")
@Builder
@Data
public class EmotionSurvey {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(name = "user_id")
private Integer userId;

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

@Column(name = "emotion_id")
private Integer emotionId;





}
Loading

0 comments on commit 9c6e893

Please sign in to comment.