Giter Site home page Giter Site logo

sp_friendmanagement_api_hungtran's Introduction

SP_FriendManagement_API_HungTran

A simple application RESTful API with Golang.

Required

  • Mysql database mysql connection
  • Golang installed

Technical Stack

This Friends Management API service is a RESTful web API built on Golang, HTTP, GORM, Mysql and Unit Test with 90% statement coverage.

Project Structure

Project have 5 packages:

  • main.go: Start server and routing.
  • configs: Define constant.
  • controllers: Handle request from client.
  • models: Define structures models related to database table schema.
  • repositories: Process logic business and actions query, update database.
  • utils: Common functions: Db connect, Response json.

Install

Application config in the src/configs/Config.example. Copy it to Config.go. There are some constants:

// Application Database
const DB_NAME = "friend_managerment"
// Testing only Database name
const DB_NAME_TEST = "friend_managerment_test"

const DB_USER = "root"
const DB_PASSWORD = "123456"
const DB_HOST = "localhost"
const DB_DRIVER = "mysql"

// Application port
const APP_PORT = "8000"

At the root of this project and run the following command:

go get -u github.com/go-sql-driver/mysql
go get -u github.com/jinzhu/gorm
go get gopkg.in/go-playground/validator.v9

To Start project:

cd /path/to/project
# Run run full test
go run main.go

To run unitest:

cd /path/to/project/src/repositories
# Run run full test
go test

# Run test with coverage
go test -cover

API Details

1. As a user, I need an API to create a friend connection between two email addresses.

Uri:

/api/user/create_friend

Method: POST

The API should receive the following JSON request:

{
    "friends":
    [
        "[email protected]",
        "[email protected]"
    ]
}

The Api response: On success: HttpStatus = 200

{
    "success": true
}

On error: HttpStatus = 400

{
    "message": "Target [email protected] Blocked Requestor [email protected]",
    "success": false
}

2. As a user, I need an API to retrieve the friends list for an email address.

Uri:

/api/user/get_friend

The API should receive the following JSON request:

{
    "email": "[email protected]"
}

The Api response: On success: HttpStatus = 200

{
    "count": 2,
    "friends": [
        "[email protected]",
        "[email protected]"
    ],
    "success": true
}

On error: HttpStatus = 400

{
    "message": "User [email protected] not exits",
    "success": false
}

3. As a user, I need an API to retrieve the common friends list between two email addresses.

Uri:

/api/user/get_friend_common

The API should receive the following JSON request:

{
    "count": 2,
    "friends": [
        "[email protected]",
        "[email protected]"
    ],
    "success": true
}

The Api response: On success: HttpStatus = 200

{
    "success": true,
    "friends" :
    [
        "[email protected]"
    ],
    "count" : 1
}

On error: HttpStatus = 400

{
    "message": "User [email protected] not exits",
    "success": false
}

4. As a user, I need an API to subscribe to updates from an email address.

Uri:

/api/user/subscribe

The API should receive the following JSON request:

{
    "requestor": "[email protected]",
    "target": "[email protected]"
}

On success: HttpStatus = 200

{
    "success": true
}

On error: HttpStatus = 400

{
    "message": "User [email protected] not exits",
    "success": false
}

5. As a user, I need an API to block updates from an email address.

Uri:

/api/user/block

Suppose "[email protected]" blocks "[email protected]": The API should receive the following JSON request:

{
    "requestor": "[email protected]",
    "target": "[email protected]"
}

On success: HttpStatus = 200

{
    "success": true
}

On error: HttpStatus = 400

{
    "message": "User [email protected] not exits",
    "success": false
}

6. As a user, I need an API to retrieve all email addresses that can receive updates from an email address.

Uri:

/api/post/create

The API should receive the following JSON request:

{
    "sender": "[email protected]",
    "text": "Hello World! [email protected]"
}

On success: HttpStatus = 200

{
    "success": true,
    "recipients":
    [
        "[email protected]",
        "[email protected]"
    ]
}

On error: HttpStatus = 400

{
    "message": "User [email protected] not exits",
    "success": false
}

7. As a user, I need an API to register my email account to the application Friend Management.

Uri:

/api/user/register

The API should receive the following JSON request:

{
    "email": "[email protected]"
}

On success: HttpStatus = 200

{
    "success": true
}

On error: HttpStatus = 400

{
    "message": "Email [email protected] is exits, please use other email",
    "success": false
}

sp_friendmanagement_api_hungtran's People

Contributors

blog360space avatar s3corp-github avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.