Skip to content

Farhanramadhana/tdd-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About This Project

This project is example of REST API project build with Go language (especially gin-gonic framework).

Implementation

This Project implement:

  1. Gin gonic framework
  2. Repository-Service Pattern.
  3. unit testing using testify.
  4. Basic auth for authentication
  5. Validation for validate user input

Project Structure

  1. Config (this folder/package used as configuration such as server, database, etc)
  2. Entity (this folder/package used to describe data type such as payload or database entity)
  3. Service (this folder/package contain all business logic)
  4. Repository (this folder/package is used to store data or communicate to database)

Project Dependencies

    github.com/gin-gonic/gin 
	github.com/go-playground/validator/v10 
	github.com/stretchr/testify
	golang.org/x/crypto 

Setup

  1. Clone/Download this project
  2. go run .

Testing

cd services/user
go test -v

Usage

Create User (Admin only)

  • URL
    • /user
  • Method
    • POST
  • Auth use basic auth, can use predefined admin data (if other admin doesn't register yet):
    • username: super.admin
    • password: admin12345
  • Body / Parameter
    •  {
           "fullname": "farhan ramadhana",
       	"email": "[email protected]",
       	"password": "pass1234567890", // minimal 10 characters
       	"role": "user" // role: user/admin
       }
  • Success Response
    •  "data": {
           "ID": "MT4NSqn3jLHc",
           "FirstName": "farhan",
           "MiddleName": "",
           "LastName": "ramadhana",
           "Username": "farhan.ramadhana",
           "Role": "user",
           "InitialName": "FR",
           "Email": "[email protected]",
           "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u",
           "UpdatedAt": "2021-04-30T07:55:31+07:00"
       },
       "status": "ok"
  • Error Response
    •  {
           "message": "",
           "status": "error"
       }
  • Notes
    • ID, FirstName, MiddleName, LastName, UserName, InitialName, and Updated Fields auto generated by System
    • Password encrypted with Bcrypt

Get All User

  • URL
    • /user
  • Method
    • GET
  • Auth use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
    • username: super.admin
    • password: admin12345
  • Success Response
    •  "data": [{
           "ID": "MT4NSqn3jLHc",
           "FirstName": "farhan",
           "MiddleName": "",
           "LastName": "ramadhana",
           "Username": "farhan.ramadhana",
           "Role": "user",
           "InitialName": "FR",
           "Email": "[email protected]",
           "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u",
           "UpdatedAt": "2021-04-30T07:55:31+07:00"
       }],
       "status": "ok"
  • Error Response
    •  {
           "message": "",
           "status": "error"
       }

Get User By ID

  • URL
    • /user/id/:id
  • Method
    • GET
  • Auth use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
    • username: super.admin
    • password: admin12345
  • Success Response
    •  "data": {
           "ID": "MT4NSqn3jLHc",
           "FirstName": "farhan",
           "MiddleName": "",
           "LastName": "ramadhana",
           "Username": "farhan.ramadhana",
           "Role": "user",
           "InitialName": "FR",
           "Email": "[email protected]",
           "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u",
           "UpdatedAt": "2021-04-30T07:55:31+07:00"
       },
       "status": "ok"
  • Error Response
    •  {
           "message": "",
           "status": "error"
       }

Get User By Email

  • URL
    • /user/email/:email
  • Method
    • GET
  • Auth use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
    • username: super.admin
    • password: admin12345
  • Success Response
    •  "data": {
           "ID": "MT4NSqn3jLHc",
           "FirstName": "farhan",
           "MiddleName": "",
           "LastName": "ramadhana",
           "Username": "farhan.ramadhana",
           "Role": "user",
           "InitialName": "FR",
           "Email": "[email protected]",
           "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u",
           "UpdatedAt": "2021-04-30T07:55:31+07:00"
       },
       "status": "ok"
  • Error Response
    •  {
           "message": "",
           "status": "error"
       }

Get User By UserName

  • URL
    • /user/usernam/:username
  • Method
    • GET
  • Auth use basic auth, can use predefined admin data (if other admin/user doesn't register yet):
    • username: super.admin
    • password: admin12345
  • Success Response
    •  "data": {
           "ID": "MT4NSqn3jLHc",
           "FirstName": "farhan",
           "MiddleName": "",
           "LastName": "ramadhana",
           "Username": "farhan.ramadhana",
           "Role": "user",
           "InitialName": "FR",
           "Email": "[email protected]",
           "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u",
           "UpdatedAt": "2021-04-30T07:55:31+07:00"
       },
       "status": "ok"
  • Error Response
    •  {
           "message": "",
           "status": "error"
       }

Delete User By ID (Admin only)

  • URL
    • /user/:id
  • Method
    • DELETE
  • Auth use basic auth, can use predefined admin data (if other admin doesn't register yet):
    • username: super.admin
    • password: admin12345
  • Success Response
    •  "status": "ok"
  • Error Response
    •  {
           "message": "",
           "status": "error"
       }

Update User By ID (Admin only)

  • URL
    • /user/:id
  • Method
    • PATCH
  • Auth use basic auth, can use predefined admin data (if other admin doesn't register yet):
    • username: super.admin
    • password: admin12345
  • Body / Parameter
    •  {
           "fullname": "farhan ramadhana",
       	"email": "[email protected]",
       	"password": "pass1234567890", // minimal 10 characters
       	"role": "user" // role: user/admin
       }
  • Success Response
    •  "data": {
           "ID": "MT4NSqn3jLHc",
           "FirstName": "farhan",
           "MiddleName": "",
           "LastName": "ramadhana",
           "Username": "farhan.ramadhana",
           "Role": "user",
           "InitialName": "FR",
           "Email": "[email protected]",
           "Password": "$2a$04$i8Yy5Hk2UNkOrocccqbYh.dkWqLge2EkxekBq2t4dY88tMmhQJJ8u",
           "UpdatedAt": "2021-04-30T07:55:31+07:00"
       },
       "status": "ok"
  • Error Response
    •  {
           "message": "",
           "status": "error"
       }
  • Notes
    • ID, FirstName, MiddleName, LastName, UserName, InitialName, and Updated Fields auto generated by System
    • Password encrypted with Bcrypt

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages