Skip to content

Commit

Permalink
Merge pull request #65 from L1nkWave/feature/LWB-43_get-duochat-id
Browse files Browse the repository at this point in the history
feature/LWB-43_get-duochat-id
  • Loading branch information
borjom1 committed May 5, 2024
2 parents bd7036d + 28a46a9 commit 5fbc0ac
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public List<String> getUserChats() {
return chatService.getUserChats(userDetails().id());
}

@GetMapping("/{recipientId}")
public String getDuoChatId(@PathVariable Long recipientId) {
return chatService.findChat(userDetails().id(), recipientId).getId();
}

@PostMapping
@ResponseStatus(CREATED)
@JsonView(New.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public interface ChatService {
*/
Chat findChat(String id) throws ChatNotFoundException;

/**
* Returns duo chat for both users. The users' order does not matter.
*
* @param userId id of the 1st user
* @param userId2 id of the 2nd user
* @return chat object
* @throws ChatNotFoundException when chat for both users not found
*/
Chat findChat(Long userId, Long userId2) throws ChatNotFoundException;

/**
* Inter-service method to find a group chat by specified ID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public Chat findChat(String id) {
return chatRepository.findById(id).orElseThrow(ChatNotFoundException::new);
}

@Override
public Chat findChat(Long userId, Long userId2) {
return chatRepository.findChatWithPair(userId, userId2).orElseThrow(ChatNotFoundException::new);
}

@Override
public GroupChat findGroupChat(String id) {
return chatRepository.findGroupChatById(id).orElseThrow(ChatNotFoundException::new);
Expand Down
131 changes: 111 additions & 20 deletions backend/chat-service/src/main/resources/static/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"paths": {
"/v1/chats": {
"get": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Retrieve a portion of user chats",
"security": [
{
Expand Down Expand Up @@ -78,7 +80,9 @@
}
},
"post": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Create duo chat",
"security": [
{
Expand Down Expand Up @@ -124,6 +128,50 @@
}
}
},
"/v1/chats/{recipientId}": {
"parameters": [
{
"$ref": "#/components/parameters/recipientIdInPath"
}
],
"get": {
"tags": [
"Chat"
],
"summary": "Returns ID of duo chat for pair of users",
"security": [
{
"BearerAuth": []
}
],
"responses": {
"200": {
"description": "ID of duo chat between both users",
"content": {
"text/plain": {
"example": "66365000f05ddd21579d2b45"
}
}
},
"404": {
"description": "Duo chat does not exist",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiError"
},
"example": {
"path": "/api/v1/chats/12",
"message": "Requested chat not found",
"status": 404,
"timestamp": 1711102257.635504100
}
}
}
}
}
}
},
"/v1/chats/{id}/exists": {
"parameters": [
{
Expand All @@ -134,7 +182,9 @@
}
],
"get": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Check if duo chat exists between request initiator and recipient",
"security": [
{
Expand Down Expand Up @@ -178,7 +228,9 @@
},
"/v1/chats/ids": {
"get": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Get ids of all user chats",
"security": [
{
Expand Down Expand Up @@ -214,7 +266,9 @@
},
"/v1/chats/group": {
"post": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Create group chat",
"security": [
{
Expand Down Expand Up @@ -251,7 +305,9 @@
}
],
"get": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Get group chat details by ID",
"security": [
{
Expand Down Expand Up @@ -279,7 +335,9 @@
}
],
"get": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Check if request initiator is a member of group chat",
"security": [
{
Expand Down Expand Up @@ -328,7 +386,9 @@
}
],
"post": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Add request initiator to members of the group chat",
"security": [
{
Expand Down Expand Up @@ -365,7 +425,9 @@
}
},
"delete": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Remove request initiator from group chat members",
"security": [
{
Expand Down Expand Up @@ -402,7 +464,9 @@
}
],
"get": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Retrieve the group chat avatar",
"security": [
{
Expand Down Expand Up @@ -439,7 +503,9 @@
}
},
"post": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Multipart request to upload group chat avatar",
"security": [
{
Expand Down Expand Up @@ -512,7 +578,9 @@
}
},
"delete": {
"tags": ["Chat"],
"tags": [
"Chat"
],
"summary": "Delete uploaded group chat avatar",
"security": [
{
Expand Down Expand Up @@ -549,7 +617,9 @@
}
],
"get": {
"tags": ["Message"],
"tags": [
"Message"
],
"summary": "Get all chat messages",
"security": [
{
Expand Down Expand Up @@ -591,7 +661,9 @@
}
},
"post": {
"tags": ["Message"],
"tags": [
"Message"
],
"summary": "Save a message that only consists of action as content",
"security": [
{
Expand Down Expand Up @@ -656,7 +728,9 @@
}
],
"post": {
"tags": ["Message"],
"tags": [
"Message"
],
"summary": "Save a text message to the chat",
"security": [
{
Expand Down Expand Up @@ -709,7 +783,9 @@
}
],
"post": {
"tags": ["Message"],
"tags": [
"Message"
],
"summary": "Upload a file as message to the chat",
"security": [
{
Expand Down Expand Up @@ -752,7 +828,7 @@
"$ref": "#/components/schemas/ApiError"
},
"examples": {
"File is missing" : {
"File is missing": {
"value": {
"path": "/api/v1/chats/662ce8cc905e8b2151fca5e2/messages/file",
"message": "Uploaded file can not be empty",
Expand Down Expand Up @@ -790,7 +866,9 @@
}
],
"get": {
"tags": ["Message"],
"tags": [
"Message"
],
"summary": "Get file from the message",
"security": [
{
Expand Down Expand Up @@ -835,7 +913,9 @@
}
],
"get": {
"tags": ["Message"],
"tags": [
"Message"
],
"summary": "Check if file message was initiated by request initiator",
"security": [
{
Expand Down Expand Up @@ -908,7 +988,9 @@
}
],
"post": {
"tags": ["Message"],
"tags": [
"Message"
],
"summary": "Read a range of chat messages",
"security": [
{
Expand Down Expand Up @@ -1621,6 +1703,15 @@
},
"description": "User ID",
"example": 26
},
"recipientIdInPath": {
"in": "path",
"name": "recipient ID",
"schema": {
"type": "integer"
},
"description": "User ID",
"example": 26
}
}
}
Expand Down

0 comments on commit 5fbc0ac

Please sign in to comment.