Skip to content

Latest commit

 

History

History
801 lines (592 loc) · 24.3 KB

README.md

File metadata and controls

801 lines (592 loc) · 24.3 KB

Friends Microservice

Table of Contents

Overview

The Friends microservice manages friendships and friend requests between users. It provides APIs for sending, accepting, and rejecting friend requests, as well as retrieving friend lists and mutual friends. This service integrates with the Users microservice to fetch user details and with the Posts microservice to provide friend-related content recommendations.

Features

  • Sending friend requests
  • Accepting friend requests
  • Rejecting friend requests
  • Retrieving friend lists
  • Retrieving mutual friends
  • Friend suggestions
  • Integration with Users microservice for user details
  • Integration with Posts microservice for content recommendations
  • Efficient message propagation using RabbitMQ
  • Secure communication with JWT authentication
  • RESTful API for friend operations

Used Technologies

  • Django
  • Django Restframework
  • Neo4j
  • RabbitMQ
  • Redis

Environment Variables

SECRET_KEY=

NEO4J_AUTH=
NEO4j_HOST=

USERS_SERVICE=http://users:8000

RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
RABBITMQ_HOST=

QUEUE_LIST=friends,posts,users
CURRENT_QUEUE=friends

API Documentation

Authentication

  • HTTP Authentication, scheme: basic

me

Get user request count

Code samples

GET /api/friends/me/ HTTP/1.1

Accept: application/json

GET /me/

Get the number of friend requests received by the user

Example responses

200 Response

{
    "request_count": 0
}

Responses

Status Meaning Description Schema
200 OK none UserRequestCount
401 Unauthorized Unauthorized None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

suggestions

Get friend suggestions

Code samples

GET /api/friends/suggestions/{id}/ HTTP/1.1

Accept: application/json

GET /suggestions/{id}/

Get the friend suggestions for the user

Parameters

Name In Type Required Description
id path string true none

Example responses

200 Response

{
    "next": "http://example.com",
    "results": [
        {
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "full_name": "string",
            "mutual_friends": 0,
            "mutual_friends_name_list": ["string"],
            "is_friend": true,
            "sent_request": true,
            "received_request": true
        }
    ]
}

Responses

Status Meaning Description Schema
200 OK none UserList
401 Unauthorized Unauthorized None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Delete friend suggestion

Code samples

DELETE /api/friends/suggestions/{id}/ HTTP/1.1

DELETE /suggestions/{id}/

Delete a friend suggestion

Parameters

Name In Type Required Description
id path string true none

Responses

Status Meaning Description Schema
204 No Content No Content None
401 Unauthorized Unauthorized None
404 Not Found User not found None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

users

Get friend requests

Code samples

GET /api/friends/users/friends/requests/ HTTP/1.1

Accept: application/json

GET /users/friends/requests/

Get the friend requests received by the user

Example responses

200 Response

{
    "next": "http://example.com",
    "results": [
        {
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
            "full_name": "string",
            "created_at": "2019-08-24T14:15:22Z",
            "sent_request": true,
            "received_request": true,
            "mutual_friends": 0,
            "mutual_friends_name_list": ["string"]
        }
    ]
}

Responses

Status Meaning Description Schema
200 OK none FriendRequestList
401 Unauthorized Unauthorized None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Send friend request

Code samples

POST /api/friends/users/friends/requests/ HTTP/1.1

Content-Type: application/json
Accept: application/json

POST /users/friends/requests/

Send a friend request to another user

Body parameter

{
    "user_to_id": "7380bf92-4931-437e-ac11-314f80255fbd"
}

Parameters

Name In Type Required Description
body body FriendRequest true none

Example responses

201 Response

{
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
    "full_name": "string",
    "created_at": "2019-08-24T14:15:22Z",
    "sent_request": true,
    "received_request": true,
    "mutual_friends": 0,
    "mutual_friends_name_list": ["string"]
}

Responses

Status Meaning Description Schema
201 Created none FriendRequestObject
400 Bad Request Bad Request None
401 Unauthorized Unauthorized None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Accept or reject friend request

Code samples

POST /api/friends/users/friends/requests/action/ HTTP/1.1

Content-Type: application/json

POST /users/friends/requests/action/

Accept or reject a friend request

Body parameter

{
    "action": "accept",
    "request_id": "266ea41d-adf5-480b-af50-15b940c2b846"
}

Parameters

Name In Type Required Description
body body FriendRequestAction true none

Responses

Status Meaning Description Schema
204 No Content No Content None
401 Unauthorized Unauthorized None
404 Not Found Friend request not found None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Get sent friend requests

Code samples

GET /api/friends/users/friends/requests/sent/ HTTP/1.1

Accept: application/json

GET /users/friends/requests/sent/

Get the friend requests sent by the user

Example responses

200 Response

{
    "next": "http://example.com",
    "results": [
        {
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
            "full_name": "string",
            "created_at": "2019-08-24T14:15:22Z",
            "sent_request": true,
            "received_request": true,
            "mutual_friends": 0,
            "mutual_friends_name_list": ["string"]
        }
    ]
}

Responses

Status Meaning Description Schema
200 OK none FriendRequestList
401 Unauthorized Unauthorized None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Get user details

Code samples

GET /api/friends/users/{id}/ HTTP/1.1

Accept: application/json

GET /users/{id}/

Get the user details by user id

Parameters

Name In Type Required Description
id path string true none

Example responses

200 Response

{
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "full_name": "string",
    "is_friend": true,
    "sent_request": true,
    "received_request": true
}

Responses

Status Meaning Description Schema
200 OK none UserRetrieve
401 Unauthorized Unauthorized None
404 Not Found User not found None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Get user friends

Code samples

GET /api/friends/users/{id}/friends/ HTTP/1.1

Accept: application/json

GET /users/{id}/friends/

Get the user friends by user id

Parameters

Name In Type Required Description
page query integer false A page number within the paginated result set.
id path string true none

Example responses

200 Response

{
    "next": "http://example.com",
    "results": [
        {
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "full_name": "string",
            "mutual_friends": 0,
            "mutual_friends_name_list": ["string"],
            "is_friend": true,
            "sent_request": true,
            "received_request": true
        }
    ]
}

Responses

Status Meaning Description Schema
200 OK none UserList
401 Unauthorized Unauthorized None
404 Not Found User not found None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Get mutual friends

Code samples

GET /api/friends/users/{id}/friends/mutual/ HTTP/1.1

Accept: application/json

GET /users/{id}/friends/mutual/

Get the mutual friends between two users

Parameters

Name In Type Required Description
page query integer false A page number within the paginated result set.
id path string true none

Example responses

200 Response

{
    "next": "http://example.com",
    "results": [
        {
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "full_name": "string",
            "mutual_friends": 0,
            "mutual_friends_name_list": ["string"],
            "is_friend": true,
            "sent_request": true,
            "received_request": true
        }
    ]
}

Responses

Status Meaning Description Schema
200 OK none UserList
401 Unauthorized Unauthorized None
404 Not Found User not found None
To perform this operation, you must be authenticated by means of one of the following methods: Basic

Schemas

UserRequestCount

{
    "request_count": 0
}

Properties

Name Type Required Restrictions Description
request_count integer true none none

User

{
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "full_name": "string",
    "mutual_friends": 0,
    "mutual_friends_name_list": ["string"],
    "is_friend": true,
    "sent_request": true,
    "received_request": true
}

Properties

Name Type Required Restrictions Description
id string(uuid) true none none
full_name string true none none
mutual_friends integer true none none
mutual_friends_name_list [string] true none none
is_friend boolean true none none
sent_request boolean true none none
received_request boolean true none none

UserList

{
    "next": "http://example.com",
    "results": [
        {
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "full_name": "string",
            "mutual_friends": 0,
            "mutual_friends_name_list": ["string"],
            "is_friend": true,
            "sent_request": true,
            "received_request": true
        }
    ]
}

Properties

Name Type Required Restrictions Description
next string(uri) true none none
results [User] true none none

FriendRequestObject

{
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
    "full_name": "string",
    "created_at": "2019-08-24T14:15:22Z",
    "sent_request": true,
    "received_request": true,
    "mutual_friends": 0,
    "mutual_friends_name_list": ["string"]
}

Properties

Name Type Required Restrictions Description
id string(uuid) true none none
req_id string(uuid) true none none
full_name string true none none
created_at string(date-time) true none none
sent_request boolean true none none
received_request boolean true none none
mutual_friends integer true none none
mutual_friends_name_list [string] true none none

FriendRequestList

{
    "next": "http://example.com",
    "results": [
        {
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
            "full_name": "string",
            "created_at": "2019-08-24T14:15:22Z",
            "sent_request": true,
            "received_request": true,
            "mutual_friends": 0,
            "mutual_friends_name_list": ["string"]
        }
    ]
}

Properties

Name Type Required Restrictions Description
next string(uri) true none none
results [FriendRequestObject] true none none

FriendRequest

{
    "user_to_id": "7380bf92-4931-437e-ac11-314f80255fbd",
    "req_id": "string",
    "created_at": "2019-08-24T14:15:22Z",
    "mutual_friends_count": 0,
    "mutual_friends_name_list": ["string"]
}

Properties

Name Type Required Restrictions Description
user_to_id string(uuid) true none none
req_id string false read-only none
created_at string(date-time) false read-only none
mutual_friends_count integer false read-only none
mutual_friends_name_list [string] false read-only none

FriendRequestAction

{
    "action": "accept",
    "request_id": "266ea41d-adf5-480b-af50-15b940c2b846"
}

Properties

Name Type Required Restrictions Description
action string true none none
request_id string(uuid) true none none

Enumerated Values

Property Value
action accept
action reject

UserRetrieve

{
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "full_name": "string",
    "is_friend": true,
    "sent_request": true,
    "received_request": true
}

Properties

Name Type Required Restrictions Description
id string(uuid) true none none
full_name string true none none
is_friend boolean true none none
sent_request boolean true none none
received_request boolean true none none

Database Architecture

Database Architecture

License

This project is licensed under the MIT License. See the LICENSE file for details.