Skip to content

Commit ff7b6e8

Browse files
committed
add SurveyStatus enum, fix tests, fix typos, add filters and mappings to dashboards
1 parent e8010c0 commit ff7b6e8

File tree

8 files changed

+111
-47
lines changed

8 files changed

+111
-47
lines changed

src/main/java/com/pwr/students/domain/Survey.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.pwr.students.domain;
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.pwr.students.repository.SurveyStatus;
45
import jakarta.persistence.*;
56
import jakarta.validation.constraints.*;
67
import java.io.Serializable;
@@ -40,7 +41,8 @@ public class Survey implements Serializable {
4041
private LocalDate deadline;
4142

4243
@Column(name = "status")
43-
private String status;
44+
@Enumerated(EnumType.STRING)
45+
private SurveyStatus status;
4446

4547
@OneToMany(fetch = FetchType.EAGER, mappedBy = "survey")
4648
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@@ -106,16 +108,16 @@ public void setDeadline(LocalDate deadline) {
106108
this.deadline = deadline;
107109
}
108110

109-
public String getStatus() {
111+
public SurveyStatus getStatus() {
110112
return this.status;
111113
}
112114

113-
public Survey status(String status) {
115+
public Survey status(SurveyStatus status) {
114116
this.setStatus(status);
115117
return this;
116118
}
117119

118-
public void setStatus(String status) {
120+
public void setStatus(SurveyStatus status) {
119121
this.status = status;
120122
}
121123

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.pwr.students.repository;
2+
3+
public enum SurveyStatus {
4+
DRAFT,
5+
ACTIVE,
6+
EXPIRED,
7+
}

src/main/java/com/pwr/students/web/rest/SurveyAssigmentResource.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ public SurveyAssigmentResource(SurveyAssigmentRepository surveyAssigmentReposito
3939
}
4040

4141
/**
42-
* {@code POST /survey-assigments} : Create a new surveyAssigment.
42+
* {@code POST /survey-assignments} : Create a new surveyAssigment.
4343
*
4444
* @param surveyAssigment the surveyAssigment to create.
4545
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new surveyAssigment, or with status {@code 400 (Bad Request)} if the surveyAssigment has already an ID.
4646
* @throws URISyntaxException if the Location URI syntax is incorrect.
4747
*/
48-
@PostMapping("/survey-assigments")
48+
@PostMapping("/survey-assignments")
4949
public ResponseEntity<SurveyAssigment> createSurveyAssigment(@RequestBody SurveyAssigment surveyAssigment) throws URISyntaxException {
5050
log.debug("REST request to save SurveyAssigment : {}", surveyAssigment);
5151
if (surveyAssigment.getId() != null) {
5252
throw new BadRequestAlertException("A new surveyAssigment cannot already have an ID", ENTITY_NAME, "idexists");
5353
}
5454
SurveyAssigment result = surveyAssigmentRepository.save(surveyAssigment);
5555
return ResponseEntity
56-
.created(new URI("/api/survey-assigments/" + result.getId()))
56+
.created(new URI("/api/survey-assignments/" + result.getId()))
5757
.headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, result.getId().toString()))
5858
.body(result);
5959
}
6060

6161
/**
62-
* {@code PUT /survey-assigments/:id} : Updates an existing surveyAssigment.
62+
* {@code PUT /survey-assignments/:id} : Updates an existing surveyAssigment.
6363
*
6464
* @param id the id of the surveyAssigment to save.
6565
* @param surveyAssigment the surveyAssigment to update.
@@ -68,7 +68,7 @@ public ResponseEntity<SurveyAssigment> createSurveyAssigment(@RequestBody Survey
6868
* or with status {@code 500 (Internal Server Error)} if the surveyAssigment couldn't be updated.
6969
* @throws URISyntaxException if the Location URI syntax is incorrect.
7070
*/
71-
@PutMapping("/survey-assigments/{id}")
71+
@PutMapping("/survey-assignments/{id}")
7272
public ResponseEntity<SurveyAssigment> updateSurveyAssigment(
7373
@PathVariable(value = "id", required = false) final Long id,
7474
@RequestBody SurveyAssigment surveyAssigment
@@ -93,7 +93,7 @@ public ResponseEntity<SurveyAssigment> updateSurveyAssigment(
9393
}
9494

9595
/**
96-
* {@code PATCH /survey-assigments/:id} : Partial updates given fields of an existing surveyAssigment, field will ignore if it is null
96+
* {@code PATCH /survey-assignments/:id} : Partial updates given fields of an existing surveyAssigment, field will ignore if it is null
9797
*
9898
* @param id the id of the surveyAssigment to save.
9999
* @param surveyAssigment the surveyAssigment to update.
@@ -103,7 +103,7 @@ public ResponseEntity<SurveyAssigment> updateSurveyAssigment(
103103
* or with status {@code 500 (Internal Server Error)} if the surveyAssigment couldn't be updated.
104104
* @throws URISyntaxException if the Location URI syntax is incorrect.
105105
*/
106-
@PatchMapping(value = "/survey-assigments/{id}", consumes = { "application/json", "application/merge-patch+json" })
106+
@PatchMapping(value = "/survey-assignments/{id}", consumes = { "application/json", "application/merge-patch+json" })
107107
public ResponseEntity<SurveyAssigment> partialUpdateSurveyAssigment(
108108
@PathVariable(value = "id", required = false) final Long id,
109109
@RequestBody SurveyAssigment surveyAssigment
@@ -138,12 +138,12 @@ public ResponseEntity<SurveyAssigment> partialUpdateSurveyAssigment(
138138
}
139139

140140
/**
141-
* {@code GET /survey-assigments} : get all the surveyAssigments.
141+
* {@code GET /survey-assignments} : get all the surveyAssigments.
142142
*
143143
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
144144
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of surveyAssigments in body.
145145
*/
146-
@GetMapping("/survey-assigments")
146+
@GetMapping("/survey-assignments")
147147
public List<SurveyAssigment> getAllSurveyAssigments(@RequestParam(required = false, defaultValue = "false") boolean eagerload) {
148148
log.debug("REST request to get all SurveyAssigments");
149149
if (eagerload) {
@@ -154,25 +154,25 @@ public List<SurveyAssigment> getAllSurveyAssigments(@RequestParam(required = fal
154154
}
155155

156156
/**
157-
* {@code GET /survey-assigments/:id} : get the "id" surveyAssigment.
157+
* {@code GET /survey-assignments/:id} : get the "id" surveyAssigment.
158158
*
159159
* @param id the id of the surveyAssigment to retrieve.
160160
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the surveyAssigment, or with status {@code 404 (Not Found)}.
161161
*/
162-
@GetMapping("/survey-assigments/{id}")
162+
@GetMapping("/survey-assignments/{id}")
163163
public ResponseEntity<SurveyAssigment> getSurveyAssigment(@PathVariable Long id) {
164164
log.debug("REST request to get SurveyAssigment : {}", id);
165165
Optional<SurveyAssigment> surveyAssigment = surveyAssigmentRepository.findOneWithEagerRelationships(id);
166166
return ResponseUtil.wrapOrNotFound(surveyAssigment);
167167
}
168168

169169
/**
170-
* {@code DELETE /survey-assigments/:id} : delete the "id" surveyAssigment.
170+
* {@code DELETE /survey-assignments/:id} : delete the "id" surveyAssigment.
171171
*
172172
* @param id the id of the surveyAssigment to delete.
173173
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
174174
*/
175-
@DeleteMapping("/survey-assigments/{id}")
175+
@DeleteMapping("/survey-assignments/{id}")
176176
public ResponseEntity<Void> deleteSurveyAssigment(@PathVariable Long id) {
177177
log.debug("REST request to delete SurveyAssigment : {}", id);
178178
surveyAssigmentRepository.deleteById(id);

src/main/webapp/app/entities/survey-assigment/survey-assigment.reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const initialState: EntityState<ISurveyAssigment> = {
1414
updateSuccess: false,
1515
};
1616

17-
const apiUrl = 'api/survey-assigments';
17+
const apiUrl = 'api/survey-assignments';
1818

1919
// Actions
2020

src/main/webapp/app/modules/managerSurveysDashboard/managerSurveysDashboard.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import './managerSurveysDashboard.css';
55
import { BsThreeDots, BsGear } from 'react-icons/bs';
66
import { FiSend, FiTrash2 } from 'react-icons/fi';
77
import { GrStatusInfo } from 'react-icons/gr';
8-
import { Link, useNavigate } from 'react-router-dom';
8+
import { Link } from 'react-router-dom';
99
import { deleteEntity } from 'app/entities/survey/survey.reducer';
1010
import { useAppDispatch } from 'app/config/store';
1111

@@ -32,8 +32,7 @@ const ManagerSurveysDashboard = () => {
3232
}, [refreshSurveys]);
3333

3434
function ActiveSurveysSection() {
35-
// const activeSurveys = surveys.filter((survey) => survey.status === 'active'); // TODO uncomment it after column status is added to survey table
36-
const activeSurveys = surveys.filter(survey => survey.id !== 0); // TODO remove it after column status is added to survey table
35+
const activeSurveys = surveys.filter(survey => survey.status === 'ACTIVE');
3736

3837
return (
3938
<div>
@@ -49,28 +48,32 @@ const ManagerSurveysDashboard = () => {
4948

5049
// Component for the expired surveys section
5150
function NotPublishedSurveysSection() {
52-
const notPublishedSurveys = surveys.filter(survey => survey.status === 'inactive');
51+
const notPublishedSurveys = surveys.filter(survey => survey.status === 'DRAFT');
5352

5453
return (
5554
<div>
5655
<h2>Not published</h2>
57-
{notPublishedSurveys.map(survey => (
58-
<SurveyBox key={survey.id} survey={survey} />
59-
))}
56+
<div className={'survey-container'}>
57+
{notPublishedSurveys.map(survey => (
58+
<SurveyBox key={survey.id} survey={survey} />
59+
))}
60+
</div>
6061
</div>
6162
);
6263
}
6364

6465
// Component for the expired surveys section
6566
function ExpiredSurveysSection() {
66-
const expiredSurveys = surveys.filter(survey => survey.status === 'expired');
67+
const expiredSurveys = surveys.filter(survey => survey.status === 'EXPIRED');
6768

6869
return (
6970
<div>
7071
<h2>Expired</h2>
71-
{expiredSurveys.map(survey => (
72-
<SurveyBox key={survey.id} survey={survey} />
73-
))}
72+
<div className={'survey-container'}>
73+
{expiredSurveys.map(survey => (
74+
<SurveyBox key={survey.id} survey={survey} />
75+
))}
76+
</div>
7477
</div>
7578
);
7679
}

src/main/webapp/app/modules/userSurveysDashboard/userSurveysDashboard.tsx

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { useEffect, useState } from 'react';
22
import axios from 'axios';
33
import './userSurveysDashboard.css';
4-
import { useNavigate } from 'react-router-dom';
4+
import { Link, useNavigate } from 'react-router-dom';
55
import { Button, Modal } from 'react-bootstrap';
66

77
const UserSurveysDashboard = () => {
88
const [surveys, setSurveys] = useState([]);
9+
const [surveyAssignments, setSurveyAssignments] = useState([]);
910

1011
// TODO this code will look different bacause we will have to fetch the surveys assigned for this user (for now it fetches everything, waiting for backend to be ready)
1112
useEffect(() => {
@@ -19,18 +20,54 @@ const UserSurveysDashboard = () => {
1920
.catch(error => {
2021
console.error('Error fetching survey data:', error);
2122
});
23+
axios
24+
.get('/api/survey-assignments') // Replace '/api/survey-assignments' with the appropriate endpoint URL
25+
.then(response => {
26+
// Update the surveyAssignments state with the fetched data
27+
setSurveyAssignments(response.data);
28+
})
29+
.catch(error => {
30+
console.error('Error fetching survey assignment data:', error);
31+
});
2232
}, []);
2333

2434
function ActiveSurveysSection() {
25-
// const activeSurveys = surveys.filter((survey) => survey.status === 'active'); // TODO uncomment it after column status is added to survey table
26-
const activeSurveys = surveys.filter(survey => survey.id !== 0); // TODO remove it after column status is added to survey table
35+
const activeSurveys = surveyAssignments
36+
.filter(assignment => assignment.is_finished === false)
37+
.map(assignment => {
38+
const survey = surveys.find(survey => survey.id === assignment.survey.id && survey.status === 'ACTIVE');
39+
return survey || null;
40+
})
41+
.filter(survey => survey !== null);
2742

2843
return (
2944
<div>
3045
<h2>Active</h2>
3146
<div className={'survey-container'}>
3247
{activeSurveys.map(survey => (
33-
<SurveyBox key={survey.id} survey={survey} />
48+
<SurveyBox key={survey.id} survey={survey} openLinkTo={null} isSurveyActive={true} />
49+
))}
50+
</div>
51+
</div>
52+
);
53+
}
54+
55+
function CompletedSurveysSection() {
56+
const completedSurveys = surveyAssignments
57+
.filter(assignment => assignment.is_finished === true)
58+
.map(assignment => {
59+
const survey = surveys.find(survey => survey.id === assignment.survey.id && survey.status === 'ACTIVE');
60+
return survey || null;
61+
})
62+
.filter(survey => survey !== null);
63+
64+
return (
65+
<div>
66+
<h2>Completed</h2>
67+
<div className={'survey-container'}>
68+
{completedSurveys.map(survey => (
69+
<SurveyBox key={survey.id} survey={survey} openLinkTo="history-test" isSurveyActive={false} />
70+
// TODO openLinkTo="history-test" is a placeholder for the link to the survey history page
3471
))}
3572
</div>
3673
</div>
@@ -39,20 +76,22 @@ const UserSurveysDashboard = () => {
3976

4077
// Component for the expired surveys section
4178
function ExpiredSurveysSection() {
42-
const expiredSurveys = surveys.filter(survey => survey.status === 'expired');
79+
const expiredSurveys = surveys.filter(survey => survey.status === 'EXPIRED');
4380

4481
return (
4582
<div>
4683
<h2>Expired</h2>
47-
{expiredSurveys.map(survey => (
48-
<SurveyBox key={survey.id} survey={survey} />
49-
))}
84+
<div className={'survey-container'}>
85+
{expiredSurveys.map(survey => (
86+
<SurveyBox key={survey.id} survey={survey} openLinkTo={null} isSurveyActive={false} />
87+
))}
88+
</div>
5089
</div>
5190
);
5291
}
5392

5493
// Component for a survey box
55-
function SurveyBox({ survey }) {
94+
function SurveyBox({ survey, openLinkTo, isSurveyActive }) {
5695
const [modalOpen, setModalOpen] = useState(false);
5796

5897
const navigate = useNavigate();
@@ -72,9 +111,19 @@ const UserSurveysDashboard = () => {
72111
return (
73112
<div className={'survey'}>
74113
<div className={'survey-inside'}></div>
75-
<div className={'name-row'} onClick={openModal}>
76-
<p className={'wrap-text'}>{survey.name}</p>
77-
</div>
114+
{isSurveyActive ? (
115+
<Link to={null} onClick={openModal}>
116+
<div className={'name-row'}>
117+
<p className={'wrap-text'}>{survey.name}</p>
118+
</div>
119+
</Link>
120+
) : (
121+
<Link to={openLinkTo}>
122+
<div className={'name-row'}>
123+
<p className={'wrap-text'}>{survey.name}</p>
124+
</div>
125+
</Link>
126+
)}
78127

79128
<Modal show={modalOpen} onHide={closeModal} dialogClassName="rounded-modal">
80129
<Modal.Header closeButton>
@@ -85,8 +134,9 @@ const UserSurveysDashboard = () => {
85134
<p>Number of questions: {survey.questions.length}</p>
86135
{/*TODO add approximate completion time column to survey table or find another way to calculate it*/}
87136
<p>Completion time: placeholder</p>
88-
{/*TODO add author column to survey table*/}
89-
<p>Author: placeholder</p>
137+
<p>
138+
Author: {survey.users[0].firstName} {survey.users[0].lastName}
139+
</p>
90140
</Modal.Body>
91141
<Modal.Footer>
92142
<Button variant="secondary" onClick={closeModal}>
@@ -103,8 +153,9 @@ const UserSurveysDashboard = () => {
103153

104154
return (
105155
<div>
106-
<h1>Survey Dashboard</h1>
156+
<h1>Assigned Surveys Dashboard</h1>
107157
<ActiveSurveysSection />
158+
<CompletedSurveysSection />
108159
<ExpiredSurveysSection />
109160
</div>
110161
);

src/test/java/com/pwr/students/web/rest/SurveyAssigmentResourceIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SurveyAssigmentResourceIT {
4242
private static final Boolean DEFAULT_IS_FINISHED = false;
4343
private static final Boolean UPDATED_IS_FINISHED = true;
4444

45-
private static final String ENTITY_API_URL = "/api/survey-assigments";
45+
private static final String ENTITY_API_URL = "/api/survey-assignments";
4646
private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";
4747

4848
private static Random random = new Random();

src/test/java/com/pwr/students/web/rest/SurveyResourceIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.pwr.students.IntegrationTest;
1111
import com.pwr.students.domain.Survey;
1212
import com.pwr.students.repository.SurveyRepository;
13+
import com.pwr.students.repository.SurveyStatus;
1314
import jakarta.persistence.EntityManager;
1415
import java.time.LocalDate;
1516
import java.time.ZoneId;
@@ -50,8 +51,8 @@ class SurveyResourceIT {
5051
private static final LocalDate DEFAULT_DEADLINE = LocalDate.ofEpochDay(0L);
5152
private static final LocalDate UPDATED_DEADLINE = LocalDate.now(ZoneId.systemDefault());
5253

53-
private static final String DEFAULT_STATUS = "AAAAAAAAAA";
54-
private static final String UPDATED_STATUS = "BBBBBBBBBB";
54+
private static final SurveyStatus DEFAULT_STATUS = SurveyStatus.ACTIVE;
55+
private static final SurveyStatus UPDATED_STATUS = SurveyStatus.EXPIRED;
5556

5657
private static final String ENTITY_API_URL = "/api/surveys";
5758
private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

0 commit comments

Comments
 (0)