Skip to content

Minhquanzz1002/viet-chat-backend-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BACKEND SPRING BOOT FOR VIET CHAT

Viet Chat is a real-time chat application inspired by Zalo.

Demo

link

Tech Stack

Language: Java

Framework: Spring boot

Database: MongoDB

Dependencies: Twilio, Modal Mapper, Spring Security, Spring Validation, Spring Websocket, JJWT, AWS SDK

Features

  • Register/Login
  • View profiles
  • User search
  • Send messages
  • Recall messages
  • Delete messages
  • Delete conversations
  • Send reactions
  • View messages
  • Create and manage groups (add members, remove members, ...)

API Reference

View details API: /api/swagger-ui/index.html

App Screenshot

Chat Controller

Get chat room information

  GET /api/v1/chats/{chat-id}

Mark a chat as read

  PUT /api/v1/chats/{chat-id}

Get messages

  GET /api/v1/chats/{chat-id}/messages

Send messages

  POST /api/v1/chats/{chat-id}/messages

Delete all messages in a chat

  DELETE /api/v1/chats/{chat-id}/messages

Undo sending a message

  PUT /api/v1/chats/{chat-id}/messages/{message-id}

Delete a message

  DELETE /api/v1/chats/{chat-id}/messages/{message-id}

Pin a message

  PUT /api/v1/chats/{chat-id}/messages/{message-id}/pin

Unpin a message

  PUT /api/v1/chats/{chat-id}/messages/{message-id}/unpin

Send reaction to a message

  PUT /api/v1/chats/{chat-id}/messages/{message-id}/reaction

Delete all reactions

  DELETE /api/v1/chats/{chat-id}/messages/{message-id}/reaction

User Controller

Get user information

  GET /api/v1/users/profile

Update user information

  PUT /api/v1/users/profile

Body

{
  "firstName": "string",
  "lastName": "string",
  "bio": "string",
  "thumbnailAvatar": "string",
  "coverImage": "string",
  "gender": true,
  "birthday": "2024-07-01"
}

Get user information by phone

  GET /api/v1/users/profile/{phone}

Get all chat rooms

  GET /api/v1/users/profile/chats

Update chat room

  PUT /api/v1/users/profile/chats/{chat-id}

Body

{
  "status": "DELETED" // DELETED, HIDDEN, PINNED, NORMAL
}

Get all friends

  GET /api/v1/users/profile/friends?type=friend

Send friend request

  PUT /api/v1/users/friends/{friend-id}

Delete friend

  DELETE /api/v1/users/friends/{friend-id}

Accept friend request

  PUT /api/v1/users/friends/{friend-id}/accept

Block friend

  PUT /api/v1/users/friends/{friend-id}/block

Cancel friend request

  PUT /api/v1/users/friends/{friend-id}/cancel

Decline friend request

  PUT /api/v1/users/friends/{friend-id}/decline

Get all groups

  GET /api/v1/users/profile/groups

Leave group

  PUT /api/v1/users/profile/groups/{group-id}/leave

Get all recent searches

  GET /api/v1/users/search/recent

Phone Verification

Send OTP

  POST /api/v1/verification/otp/sms/send 

Body

{
    "phone": "phone",
}

Validate OTP

  POST /api/v1/verification/otp/sms/validate

Body

{
  "phone": "0703290094",
  "otp": "611487"
}

Authentication

Login

  POST /api/v1/auth/login   

Body

{
    "phone": "phone",
    "password": "pwd"
}

Logout

  POST /api/v1/auth/logout   

Body

{
    "token": "token"
}

Logout all

  POST /api/v1/auth/logout/all   

Body

{
  "token": "token"
}

Update password

  POST /api/v1/auth/password/change   

Body

{
  "oldPassword": "pwd",
  "newPassword": "pwd",
}

Forgot password

  POST /api/v1/auth/password/forgot   

Body

{
  "phone": "phone",
}

Validate OTP for password reset

  POST /api/v1/auth/password/reset/validate  

Body

{
  "phone": "XXXX",
  "otp": "XXXXXX"
}

Update password after validating OTP

  POST /api/v1/auth/password/reset 

Body

{
  "token": "token",
  "password": "pwd"
}

Get new access token

  POST /api/v1/auth/refresh-token   

Body

{
  "token": "token"
}

Register

  POST /api/v1/auth/register   

Body

{
  "firstName": "fn",
  "lastName": "ln",
  "gender": true,
  "birthday": "2024-07-01",
  "password": "pwd"
}

Group Controller

Create a group

  POST /api/v1/groups

Get the group information

  GET /api/v1/groups/{group-id}

Update the group information

  PUT /api/v1/groups/{group-id}

Body

{
    "name": "new name",
    "thumbnailAvatar": "url"
}

Disband the group

  DELETE /api/v1/groups/{group-id}

Get all the group members

  GET /api/v1/groups/{group-id}/members

Add the group members

  PUT /api/v1/groups/{group-id}/members

Body

["member id 1", "member id 2"]

Delete a group member

  DELETE /api/v1/groups/{group-id}/members/{member-id}

Change a group member role

  PUT /api/v1/groups/{group-id}/members/{member-id}

Body

{
  "role": "GROUP_LEADER" // Roles: GROUP_LEADER, DEPUTY_GROUP_LEADER, MEMBER
}

File Controller

Get Pre-signed URL to upload file to S3

  POST /api/v1/files

Environment Variables

To run this project, you will need to add the following environment variables to your application-secret.yml file

aws:
  access-key: key
  secret-key: key
  endpoint-url: texts://{bucket-name}.s3.ap-southeast-1.amazonaws.com/
  bucket:
    name: {bucket-name}

twilio:
  accountSID: key
  authToken: key
  phoneNumberTrial: +XXXXXX

Run Locally

Clone the project

  git clone texts://github.com/Minhquanzz1002/viet-chat-backend-v2

Go to the project directory

  cd my-project

Install dependencies

  ./mvnw install

Start the server

  ./mvnw spring-boot:run

Authors

  • @Minhquanzz1002