Skip to content

w79j28/go_friends_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

在线访问地址

 Friends Management

开发框架说明

项目背景

For any application with a need to build its own social network, "Friends Management" is a common requirement which ussually starts off simple but can grow in complexity depending on the application's use case. Usually, applications would start with features like "Friend", "Unfriend", "Block", "Receive Updates" etc.

项目说明

  • Swagger 注释说明
  • swagger/main.go 生成Swagger文档
  • 配置文件config/app_config.ini,首次运行时创建或自行创建

app_config.ini

  #数据库连接
  dburl            = postgres://user:password@ip:port/dbname?sslmode=disable
  #端口 predix时为cloud
  port             = port
  #Swagger Basepath
  swagger_basepath = http://ip:port

API说明

https://wangjingzhu.run.aws-jp01-pr.ice.predix.io/swagger-ui/

1 /user/friends    [POST]

Create a friend connection between two email addresses.

JSON request:

  {
    "friends":[
        "andy@example.com",
        "john@example.com"
     ]
  }

JSON response on success:

  {
    "success": true
  }

2 /user/friends/list    [POST]

Retrieve the friends list for an email address.

JSON request:

  {
    "email": "andy@example.com"
  }

JSON response on success:

  {
     "success": true,
     "friends" : [
         "john@example.com"
     ],
     "count" : 1
  }

3 /user/friends/common    [POST]

Retrieve the common friends list between two email addresses.

JSON request:

  {
     "friends":[
         "andy@example.com",
         "john@example.com"
     ]
  }

JSON response on success:

  {
     "success": true,
     "friends":[
         "common@example.com"
     ],
     "count" : 1
  }

4 /user/friend/subscribe    [POST]

Subscribe to updates from an email address.

That "subscribing to updates" is NOT equivalent to "adding a friend connection".

JSON request:

  {
      "requestor": "lisa@example.com",
      "target": "john@example.com"
  }

JSON response on success:

  {
      "success": true
  }

5 /user/friend/block    [POST]

Block updates from an email address.

Suppose "andy@example.com" blocks "john@example.com":

  • if they are connected as friends, then "andy" will no longer receive notifications from "john"
  • if they are not connected as friends, then no new friends connection can be added

JSON request:

  {
      "requestor": "andy@example.com",
      "target": "john@example.com"
  }

JSON response on success:

  {
      "success": true
  }

6 /user/friends/sender    [POST]

Retrieve all email addresses that can receive updates from an email address.

Eligibility for receiving updates from i.e. "john@example.com":

JSON request:

  {
     "sender": "john@example.com",
     "text": "Hello World! kate@example.com"
  }

JSON response on success:

  {
     "success": true,
     "recipients" : [
        "lisa@example.com",
        "kate@example.com"
     ]
  }
  • Demo.