Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
S4a021 Web Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Charlie Darques
S4a021 Web Backend
Commits
cd44b1a1
Commit
cd44b1a1
authored
1 month ago
by
Charlie Darques
Browse files
Options
Downloads
Patches
Plain Diff
refacto et corrections non testées pour like/unlike un message
parent
81e94aa3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
WEB-INF/src/controleurs/Account.java
+1
-1
1 addition, 1 deletion
WEB-INF/src/controleurs/Account.java
WEB-INF/src/controleurs/LikeMessage.java
+68
-53
68 additions, 53 deletions
WEB-INF/src/controleurs/LikeMessage.java
WEB-INF/src/dao/UserDAO.java
+15
-3
15 additions, 3 deletions
WEB-INF/src/dao/UserDAO.java
with
84 additions
and
57 deletions
WEB-INF/src/controleurs/Account.java
+
1
−
1
View file @
cd44b1a1
...
...
@@ -65,7 +65,7 @@ public class Account extends HttpServlet {
// out.println("</form>");
out
.
println
(
"<h2>DELETE YOUR ACCOUNT</h2>"
);
out
.
println
(
"<form class=\"delForm\" action=\"/s4a021-web-backend/deletedAccount\">"
);
out
.
println
(
"<form class=\"delForm\" action=\"/s4a021-web-backend/deletedAccount\"
method=\"post\"
>"
);
out
.
println
(
"<button type=\"submit\">Delete Account</button>"
);
out
.
println
(
"</form>"
);
...
...
This diff is collapsed.
Click to expand it.
WEB-INF/src/controleurs/LikeMessage.java
+
68
−
53
View file @
cd44b1a1
//package controleurs;
//
//import java.io.IOException;
//import java.sql.SQLException;
//
//import dao.ThreadDAO;
//import dao.UserDAO;
//import dto.Message;
//import dto.User;
//import jakarta.servlet.annotation.WebServlet;
//import jakarta.servlet.http.HttpServlet;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//
//@WebServlet("/LikeMessage")
//public class LikeMessage extends HttpServlet {
// public void service (HttpServletRequest req, HttpServletResponse res) throws IOException {
// if (req.getSession().getAttribute("user") != null) {
// User user = (User) req.getSession().getAttribute("user");
//
// UserDAO userDao = new UserDAO();
// ThreadDAO threadDao = new ThreadDAO();
//
// Message msg = req.getParameter("messageid");
//
// // à modifier
// boolean messageLiked = false;
//
// if (!messageLiked) {
// try {
// userDao.reactToMsg(user, msg);
// }
// catch (SQLException sqle) {
// sqle.getStackTrace();
// }
// }
// else {
// try {
// userDao.unreactToMsg(user, msg); // méthode à créer
// }
// catch (SQLException sqle) {
// sqle.getStackTrace();
// }
// }
// res.sendRedirect("http://localhost:8080/s4a021-web-backend/Welcome");
// }
// else {
// res.sendRedirect("http://localhost:8080/s4a021-web-backend/index.html");
// }
// }
//}
// TODO : à décommenter
\ No newline at end of file
package
controleurs
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
dao.MessageDAO
;
import
dao.ThreadDAO
;
import
dao.UserDAO
;
import
dto.Message
;
import
dto.User
;
import
jakarta.servlet.annotation.WebServlet
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
@WebServlet
(
"/LikeMessage"
)
public
class
LikeMessage
extends
HttpServlet
{
public
void
service
(
HttpServletRequest
req
,
HttpServletResponse
res
)
throws
IOException
{
if
(
req
.
getSession
().
getAttribute
(
"user"
)
!=
null
)
{
User
user
=
(
User
)
req
.
getSession
().
getAttribute
(
"user"
);
UserDAO
userDao
=
new
UserDAO
();
ThreadDAO
threadDao
=
new
ThreadDAO
();
MessageDAO
messageDao
=
new
MessageDAO
();
Message
msg
=
null
;
try
{
messageDao
.
getMessageByID
(
Integer
.
parseInt
(
req
.
getParameter
(
"messageid"
)));
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
boolean
messageLiked
=
false
;
try
{
messageLiked
=
messageDao
.
isMessageLikedByUser
(
msg
,
user
);
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
if
(!
messageLiked
)
{
try
{
userDao
.
reactToMsg
(
user
,
msg
);
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
}
else
{
try
{
userDao
.
unreactToMsg
(
user
,
msg
);
// méthode à créer
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
}
res
.
sendRedirect
(
"http://localhost:8080/s4a021-web-backend/Welcome"
);
}
else
{
res
.
sendRedirect
(
"http://localhost:8080/s4a021-web-backend/index.html"
);
}
}
}
TODO
:
à
décommenter
\ No newline at end of file
This diff is collapsed.
Click to expand it.
WEB-INF/src/dao/UserDAO.java
+
15
−
3
View file @
cd44b1a1
...
...
@@ -359,8 +359,20 @@ public class UserDAO {
return
messages
;
}
public
void
unreactToMsg
(
User
user
,
Message
msg
)
{
// TODO Auto-generated method stub
throw
new
UnsupportedOperationException
(
"Unimplemented method 'unreactToMsg'"
);
public
void
unreactToMsg
(
User
user
,
Message
msg
)
throws
SQLException
{
PreparedStatement
ps
=
this
.
con
.
prepareStatement
(
"""
UPDATE reactions
SET reaction = false
WHERE userID_reactions = ?
AND msgID_reactions = ?
"""
);
try
{
ps
.
setInt
(
1
,
user
.
getId
());
ps
.
setInt
(
2
,
msg
.
getMsgId
());
ps
.
executeUpdate
();
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment