Skip to content

Commit

Permalink
major fixes on homepatient page and servlet minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDrag0 committed Jan 7, 2024
1 parent 0fc5318 commit 1d3de12
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 105 deletions.
5 changes: 4 additions & 1 deletion src/main/java/controller/ExerciseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public class ExerciseController extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
ExerciseManager em = new ExerciseManager();
String id = request.getParameter("exerciseID");
//TODO: Aggiungi alla sessione insertion date @michele
String insertiondate = request.getParameter("insertionDate");
request.getSession().setAttribute("insertionDate", insertiondate);
request.getSession().setAttribute("exerciseId", id);

ExerciseGlossary ex = em.getExercise(Integer.parseInt(id));
request.getSession().setAttribute("exercise", ex);
response.sendRedirect(request.getContextPath() + "/JSP/exercise.jsp");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/controller/ExerciseLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private boolean saveInDB(HttpServletRequest request, Blob execution){
int userId = Integer.parseInt((String) session.getAttribute("userId"));
int exerciseId = Integer.parseInt((String) session.getAttribute("exerciseId"));
Date insertDate = Date.valueOf((String) session.getAttribute("insertDate"));
//TODO: pulisci la sessione @michele
session.removeAttribute("exerciseId");
session.removeAttribute("insertDate");
return em.saveExecution(userId, exerciseId, insertDate, execution);
}
}
104 changes: 103 additions & 1 deletion src/main/java/model/DAO/DAOExercise.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package model.DAO;

import model.entity.Exercise;
import model.entity.Schedule;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
* The DAOExercise class provides methods for retrieving Exercise information from a database.
Expand Down Expand Up @@ -52,7 +55,7 @@ private static Exercise extractExerciseFromResultSet(ResultSet resultSet) throws
* @return the Exercise if it is found, else null.
*/
public Exercise getExerciseByPk(int userID, int exerciseID, Date insertDate) {
String query = "SELECT * FROM exercise WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?";
String query = "SELECT * FROM exercise WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?;";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;

Expand Down Expand Up @@ -84,6 +87,105 @@ public Exercise getExerciseByPk(int userID, int exerciseID, Date insertDate) {
return null;
}

public List<Exercise> retrieveAllNewPatientExercise(int userID) {
String query = "SELECT * FROM exercise WHERE ID_user = ? ORDER BY InsertionDate DESC;";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
List<Exercise> exercises = new ArrayList<>();

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, userID);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Exercise exercise = extractExerciseFromResultSet(resultSet);
exercises.add(exercise);
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}
}

return exercises;
}

public List<Exercise> retrieveAllNewPatientExerciseNotDone(int userID) {
String query = "SELECT * FROM exercise WHERE ID_user = ? AND CompletionDate IS NULL ORDER BY InsertionDate DESC;";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
List<Exercise> exercises = new ArrayList<>();

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, userID);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Exercise exercise = extractExerciseFromResultSet(resultSet);
exercises.add(exercise);
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}
}

return exercises;
}

public List<Exercise> retrieveAllPatientExerciseDone(int userID) {
String query = "SELECT * FROM exercise WHERE ID_user = ? AND CompletionDate IS NOT NULL ORDER BY InsertionDate DESC;";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
List<Exercise> exercises = new ArrayList<>();

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, userID);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Exercise exercise = extractExerciseFromResultSet(resultSet);
exercises.add(exercise);
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}
}

return exercises;
}

public boolean setExerciseExecution(int userID, int exerciseID, Date insertDate, Blob execution) {
String query = "UPDATE exercise SET Execution = ? WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?;";
PreparedStatement preparedStatement = null;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/model/entity/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,17 @@ public int getFeedback() {
public void setFeedback(int feedback) {
this.feedback = feedback;
}
@Override
public String toString() {
return "Exercise{" +
"idUser=" + idUser +
", idExercise=" + idExercise +
", insertionDate=" + insertionDate +
", completionDate=" + completionDate +
", evaluation=" + evaluation +
", recommended=" + recommended +
", feedback=" + feedback +
'}';
}
}

14 changes: 14 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import model.DAO.DAOExercise;
import model.DAO.DAOExerciseGlossary;
import model.entity.Exercise;
import model.entity.ExerciseGlossary;

import java.sql.Blob;
import java.sql.Date;
import java.util.List;

public class ExerciseManager implements ExerciseManagerInterface {
private final DAOExerciseGlossary daoEG = new DAOExerciseGlossary();
Expand All @@ -22,4 +24,16 @@ public boolean saveExecution(int userID, int exerciseId, Date insertDate, Blob e

return daoE.setExerciseExecution(userID, exerciseId, insertDate, execution);
}

public List<Exercise> retrieveAllNewPatientExercise(int userID){
return daoE.retrieveAllNewPatientExercise(userID);
}

public List<Exercise> retrieveAllPatientExerciseDone(int userID){
return daoE.retrieveAllPatientExerciseDone(userID);
}

public List<Exercise> retrieveAllNewPatientExerciseNotDone(int userID){
return daoE.retrieveAllNewPatientExerciseNotDone(userID);
}
}
88 changes: 88 additions & 0 deletions src/main/webapp/CSS/homepagepatient.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,35 @@
margin-right: 20px; /* Spazio tra i div */
}

.divbar{
background-color: #199a8e;
width: 100%;
border-collapse: collapse;
margin-top: 1.3em;
margin-bottom: 1.3em;
border-radius: 50px;
overflow-x: auto;
white-space: nowrap;
height: 1.3em;
}

.cards {
margin-top: 20px;
margin-bottom: 20px;
display: flex;
overflow-x: auto;
white-space: nowrap;
}
.acards {
margin-top: 20px;
margin-bottom: 20px;
display: flex;
justify-content: center;
flex-wrap: wrap;
overflow-x: auto;
white-space: nowrap;
}


.card2 {
display: flex;
Expand All @@ -47,6 +69,12 @@
display: flex;
overflow-x: scroll;
}

.challenges .acards {
display: flex;
overflow-x: scroll;
}

.card .img {
position: absolute;
width: 105px;
Expand All @@ -57,6 +85,50 @@



.errorcard {
display: flex;
flex-direction: column;
align-items: flex-direction;
gap: 16px;
padding: 20px;
position: relative;
flex: 0 0 auto;
background-color: #ffffff;
border-radius: 32px;
margin-right: 20px; /* Spazio tra i div */
}
.errorcard .img {
position: absolute;
width: 105px;
height: 115px;
top: 4px;
left: 600px;
}
.errorcard .chapter {
position: relative;
width: fit-content;
margin-top: -1px;
font-family: Georgia, serif;
font-size: 1.5em;
white-space: nowrap;
}

.card .eimg {
position: absolute;
top: 4px;
left: 600px;
}

.eillustration-wrapper {
display: flex;
align-items: center;
justify-content: center;
padding: 8px;
position: relative;
flex: 0 0 auto;
border-radius: 900px;
margin-bottom:2em;
}



Expand Down Expand Up @@ -227,3 +299,19 @@
height: 1.3em;
}



.circle_animation {
stroke-dasharray: 440; /* this value is the pixel circumference of the circle */
stroke-dashoffset: 440;
}

.html .circle_animation {
animation: html 1s ease-out forwards;
}

@keyframes html {
to {
stroke-dashoffset: 80; /* 50% would be 220 (half the initial value specified above) */
}
}
1 change: 0 additions & 1 deletion src/main/webapp/JSP/exercise.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<head>
<%
ExerciseGlossary exercise = (ExerciseGlossary) session.getAttribute("exercise");
//session.removeAttribute("exercise"); TODO: @michele fallo nella homepage questa cosa, ovviamente controlla se prima esiste poi nel caso elimini
%>

<title>Esercizio <%= exercise.getIdExercise()%></title>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/JSP/exerciseTest.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<body>
<form action="${pageContext.request.contextPath}/exerciseController" method="post">
<input type="number" name="exerciseID" value="">
<!-- <input type="hidden" name="insertionDate" value=""> TODO: @michele -->
<input type="hidden" name="insertionDate" value="">
<input type="submit">
</form>
</body>
Expand Down
Loading

0 comments on commit 1d3de12

Please sign in to comment.