Skip to content

quochungphp/go-test-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup database

  1. Pull & run docker iamge
docker run -it -d -p 5432:5432 --name postgres-local -e POSTGRES_PASSWORD=password postgres
  1. Go into docker container
docker exec -it postgres-local bash
  1. Login pg
psql -h localhost -U postgres
  1. Create user
CREATE USER "user_login" WITH PASSWORD 'password';
ALTER ROLE "user_login" WITH SUPERUSER;
  1. Create Database
CREATE DATABASE dbtest;
  1. Export ENV
export PG_HOST=127.0.0.1
export PG_PORT=5432
export PG_USER=user_login
export PG_PASS=password
export PG_DB=dbtest
export PORT=9090
  1. Insert test data, please take a look for db.sql

Install go packages & run app

  1. Install go packages
go get -u ./...
  1. Init go vendor for go modules management
go mod vendor
  1. Run app
go run main.go

Explaining project

  1. No one uses http GET for login.
  • Instead of GET to POST.
  1. Change NoSQL Live to Postgres

3.Update columns.

  • No one uses ID of column with TEXT type, expect ony NoSQL using uuid -> Change to bigserialize
  • Change created_date from TEXT to timestamp and set default and create INDEX for it
  • Change user_id of task to INT8 and update INDEX for it
  • Add a username into Users table and check UNIQUE
  • No one exposes raw password, which is very risk. I applied bcrypt hash to encrypt password.
  1. DDD architecture
  • Currently, I applied DDD (3 layers) and used self-container components, which helps me narrow down business logic in a single directory
  • Domain contains endpoints and logic core
  • Infrastructure contains drivers, services, providers, middleware...etc
  • Pkgs contains utils, common, re-useable codes
  1. Apply unit test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages