Rakamin Mini Project Backend
-
Clone Repository
git clone https://github.com/putuadityabayu/rakamin-mini-project.git
-
Install Mysql >= 8.0
You can use sample data for easy development (optional)
-
Add
.env
file -
Run mod tidy
go mod tidy
-
Run Server
go run main.go
-
Server running on localhost:$PORT
You can use sample data to import in mysql database. SQL data can be seen in this file
-
Name: User 1
Username: user1
Password: user1 -
Name: User 2
Username: user2
Password: user2 -
Name: User 3
Username: user3
Password: user3
You can see the response of this case study using postman here.
Noted: This case study uses sample data contained in this repository
As a user, I want to be able to send message to other user, so that I will be able to share information with others.
-
Login
Send POST request to
/login
endpoint with User data above.Example request body:
{ "username":"user1", "password": "user1" }
Example response:
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJSYWthbWluIE1pbmkgUHJvamVjdCIsInN1YiI6IjEiLCJhdWQiOlsiaHR0cHM6Ly9yYWthbWluLmNvbSJdLCJleHAiOjE2NjI2NjAyMzh9.F9kzLO4Mn8PA8WHJC4IHRcMKfha7_49zvrIuicWvzsE", "user": { "id": 1, "name": "User 1", "username": "user1" } }
-
Authenticated
All access to the
/conversation/**
endpoint must include an authorization header:Authorization: Bearer JWT_TOKEN
-
Send
POST
request to/conversation
To send new messages, send request with json body:
{ "user_id": 2, "message": "Example message" }
-
Scenario 1
Send the message with fill message.
Example response:
{ "id": 30, "read_status": false, "timestamp": "2022-09-09T14:01:04.932+07:00", "message": "Example message", "sender": { "id": 1, "name": "User 1", "username": "user1" }, "conversation": { "id": 11, "unread": 0, "users": [ { "id": 1, "name": "User 1", "username": "user1" }, { "id": 2, "name": "User 2", "username": "user2" } ] } }
-
Scenario 2
Send the message without fill message.
Example response:
{ "error": "Message cannot be empty" }
-
As a user, I want to be able to reply message in existing conversation, so that I will be able to respond previous message.
-
Login with user2 account
-
Authenticated
-
Send message (reply) to conversation
Send
POST
request to/conversation/:id
, whereid
is conversation ID.Example request body:
{ "message":"Example reply message" }
Example response:
{ "id": 31, "read_status": false, "timestamp": "2022-09-09T15:36:49.448+07:00", "message": "Tes reply to user 1 from user 2", "sender": { "id": 2, "name": "User 2", "username": "user2" }, "conversation": { "id": 11, "unread": 0, "users": [ { "id": 1, "name": "User 1", "username": "user1" }, { "id": 2, "name": "User 2", "username": "user2" } ] } }
As a user, I want to be able to list messages from specific user, so that I will be able to read our conversation.
-
Login
-
Authenticated
-
List all messages in specific conversation
Send
GET
request to/conversation/:id
, whereid
is conversation ID.Optional query:
page
: Page you want to request. Default 1page_size
: Size of data in one call requests. Default 15
Example response:
{ "page": 1, // Requested page "page_size": 15, // Size of data in one call requests "total": 2, // Total data "total_page": 1, // Maximum pages that can be requested. Page requests larger than this value, will result in empty data "data": [ { "id": 30, "read_status": true, "timestamp": "2022-09-09T14:01:04.932+07:00", "message": "tes user 2 msg 2", "sender": { "id": 1, "name": "User 1", "username": "user1" } }, ...messages ] }
As a user, I want to be able to list conversations where I involved, so that I will be able to search or find user to chat with.
-
Login
-
Authenticated
-
List all conversation
Send
GET
request to/conversation
.Optional query:
page
: Page you want to request. Default 1page_size
: Size of data in one call requests. Default 15
Example response:
// authorization_user is the user associated with the authorization header token { "page": 1, // Requested page "page_size": 15, // Size of data in one call requests "total": 2, // Total data "total_page": 1, // Maximum pages that can be requested. Page requests larger than this value, will result in empty data "data": [ { "id": 11, "unread": 0, // Unread count. Number of messages (in this conversation) that have not been read by authorization_user "users": [ // Conversation participants information { "id": 1, "name": "User 1", "username": "user1" }, { "id": 2, "name": "User 2", "username": "user2" } ], "message": { "id": 31, "read_status": true, // Status whether the message has been read or not read by the recipient "timestamp": "2022-09-09T15:36:49.448+07:00", "message": "Tes reply to user 1 from user 2", "sender": { "id": 2, "name": "User 2", "username": "user2" } } }, ...conversations ] }
- Added CI
- Added CD