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
81e94aa3
Commit
81e94aa3
authored
1 month ago
by
Charlie Darques
Browse files
Options
Downloads
Patches
Plain Diff
création dao de message
parent
56c98c45
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
WEB-INF/src/dao/MessageDAO.java
+60
-0
60 additions, 0 deletions
WEB-INF/src/dao/MessageDAO.java
with
60 additions
and
0 deletions
WEB-INF/src/dao/MessageDAO.java
0 → 100644
+
60
−
0
View file @
81e94aa3
package
dao
;
import
dto.Message
;
import
dto.User
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
MessageDAO
{
private
Connection
con
;
public
MessageDAO
(){
this
.
con
=
new
BDConnection
().
getConnection
();
}
public
Message
getMessageByID
(
int
id
)
throws
SQLException
{
Message
message
=
null
;
PreparedStatement
stmt
=
this
.
con
.
prepareStatement
(
"SELECT * FROM msg WHERE msgID = ?;"
);
try
{
stmt
.
setInt
(
1
,
id
);
ResultSet
rs
=
stmt
.
executeQuery
();
while
(
rs
.
next
()){
int
msgId
=
rs
.
getInt
(
1
);
int
userIdMsg
=
rs
.
getInt
(
2
);
int
threadId
=
rs
.
getInt
(
3
);
String
msg
=
rs
.
getString
(
4
);
message
=
new
Message
(
msgId
,
userIdMsg
,
threadId
,
msg
);
}
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
return
message
;
}
public
boolean
isMessageLikedByUser
(
Message
message
,
User
user
)
throws
SQLException
{
PreparedStatement
ps
=
this
.
con
.
prepareStatement
(
"""
SELECT reaction FROM reactions
WHERE userID_reactions = ?
AND msgID_reactions = ?
"""
);
try
{
ps
.
setInt
(
1
,
user
.
getId
());
ps
.
setInt
(
2
,
message
.
getMsgId
());
ResultSet
rs
=
ps
.
executeQuery
();
while
(
rs
.
next
())
{
if
(
rs
.
getBoolean
(
"reaction"
))
{
return
true
;
}
else
return
false
;
}
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
return
false
;
}
}
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