Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
devops-workshop
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
Container 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
Oda Alida Fønstelien Hjelljord
devops-workshop
Commits
6f4e2a0d
Commit
6f4e2a0d
authored
4 years ago
by
Alida
Browse files
Options
Downloads
Patches
Plain Diff
final
parent
58bbdaab
No related branches found
No related tags found
No related merge requests found
Pipeline
#115379
passed
4 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/resources/GroupChatResource.java
+46
-24
46 additions, 24 deletions
src/main/java/resources/GroupChatResource.java
with
46 additions
and
24 deletions
src/main/java/resources/GroupChatResource.java
+
46
−
24
View file @
6f4e2a0d
package
resources
;
import
dao.GroupChatDAO
;
import
data.GroupChat
;
import
data.Message
;
import
data.User
;
import
java.util.ArrayList
;
import
javax.ws.rs.*
;
import
javax.ws.rs.core.MediaType
;
import
dao.GroupChatDAO
;
import
java.util.ArrayList
;
/**
* GroupChat resource exposed at "/groupchat" path
...
...
@@ -24,50 +24,72 @@ public class GroupChatResource {
@Path
(
"{groupChatId}"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
GroupChat
getGroupChat
(
@PathParam
(
"groupChatId"
)
int
groupChatId
){
GroupChat
groupChat
;
GroupChatDAO
groupChatDAO
=
new
GroupChatDAO
();
GroupChat
groupChat
=
groupChatDAO
.
getGroupChat
(
groupChatId
);
groupChat
=
groupChatDAO
.
getGroupChat
(
groupChatId
);
ArrayList
<
Message
>
messages
=
groupChatDAO
.
getGroupChatMessages
(
groupChatId
);
groupChat
.
setMessageList
(
messages
);
ArrayList
<
User
>
users
=
groupChatDAO
.
getGroupChatUsers
(
groupChatId
);
groupChat
.
setUserList
(
users
);
return
groupChat
;
}
/**
* GET method to get all GroupChats for one user
* @param userId of one user
* @return ArrayList of GroupChat objects
*/
@GET
@Path
(
"{userId}"
)
@Path
(
"
user/
{userId}"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
ArrayList
<
GroupChat
>
getGroupChat
s
ByUserId
(
@PathParam
(
"userId"
)
int
userId
)
{
public
ArrayList
<
GroupChat
>
getGroupChatByUserId
(
@PathParam
(
"userId"
)
int
userId
){
GroupChatDAO
groupChatDAO
=
new
GroupChatDAO
();
return
groupChatDAO
.
getGroupChatByUserId
(
userId
);
}
/**
* POST method to add new GroupChat
* @param groupChat The GroupChat to be added
* @return the newly created GroupChat
*/
@POST
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
GroupChat
postGroupChat
(
@PathParam
(
"groupChat"
)
GroupChat
groupChat
)
{
public
GroupChat
postGroupChat
(
GroupChat
groupChat
){
GroupChatDAO
groupChatDAO
=
new
GroupChatDAO
();
return
groupChatDAO
.
addGroupChat
(
groupChat
);
}
/**
* GET method to get all Messages for a GroupChat
* @param groupChatId Id of the GroupChat
* @return Arraylist of Messages
*/
@GET
@Path
(
"{groupChatId}"
)
@Path
(
"
/
{groupChatId}
/message
"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
ArrayList
<
Message
>
get
GroupChat
Messages
(
@PathParam
(
"groupChatId"
)
int
groupChatId
)
{
public
ArrayList
<
Message
>
getMessages
(
@PathParam
(
"groupChatId"
)
int
groupChatId
){
GroupChatDAO
groupChatDAO
=
new
GroupChatDAO
();
return
groupChatDAO
.
getGroupChatMessages
(
groupChatId
);
}
/**
* POST method to add new message to a GroupChat
* @param groupChatId id of the chat to add it to
* @param message the Message to add
* @return the newly created Message
*/
@POST
@Path
(
"{groupChatId}"
)
@Path
(
"
/
{groupChatId}
/message
"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Message
postMessage
(
@PathParam
(
"groupChatId"
)
int
groupChatId
,
Message
message
){
GroupChatDAO
groupChatDAO
=
new
GroupChatDAO
();
return
groupChatDAO
.
addMessage
(
groupChatId
,
message
);
}
}
\ 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