Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bagashiz committed Aug 19, 2023
0 parents commit f82fb46
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./cmd/http/main.go"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = ["cmd", "internal", "pkg"]
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = true

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
36 changes: 36 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# exclude any development-specific files
.vscode/
.idea/

# exclude any dependency directories
node_modules/
vendor/

# exclude build artifacts
build/
dist/
bin/
tmp/

# exclude any version control files
.git/

# exclude CI files
.github/
.gitlab-ci.yml

# exclude Docker files
Dockerfile*
docker-compose*.yml

# exclude any development-specific files
.*ignore
*.env
*.log
*.md
*.out
*.toml
*.test
**/*_test.go
*.yml
Makefile
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
APP_NAME=go-pos
APP_ENV=local
APP_DEBUG=true
APP_URL=127.0.0.1
APP_PORT=8080

DB_CONNECTION=postgres
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=gopos
DB_USERNAME=root
DB_PASSWORD=
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Continuous Integration

on:
push:
branches: ["main", "stable"]
pull_request:
branches: ["main", "stable"]

jobs:
lint:
name: Lint Code
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
cache: false

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: "v1.53"

test:
name: Run Tests
runs-on: ubuntu-latest
needs: lint

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"

- name: Build
run: go build -v ./...

# - name: Test
# run: go run github.com/onsi/ginkgo/v2/ginkgo -v -r --randomize-all --randomize-suites --fail-on-pending --keep-going --cover --race --trace
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# exclude any development-specific files
.vscode/
.idea/

# exclude any dependency directories
node_modules/
vendor/

# exclude build artifacts
bin/
tmp/

# exclude any development-specific files
*.env
*.log
*.out
*.test
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing

## **⚠️WIP⚠️**
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Bagas Hizbullah

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Go POS

## **⚠️WIP⚠️**
60 changes: 60 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# https://taskfile.dev

version: "3"

vars:
DBML_FILE: "./schema.dbml"

dotenv:
- ".env"

tasks:
default:
desc: "Gettings started"
cmds:
- task: install
- task: db:start
- task: dev

db:docs:
desc: "Generate database documentation from DBML file"
cmd: dbdocs build {{.DBML_FILE}}
requires:
vars:
- DBML_FILE

db:start:
desc: "Start database container"
cmd: podman-compose up -d

db:stop:
desc: "Stop database container"
cmd: podman-compose down

dev:
desc: "Start development server"
cmd: air

build:
desc: "Build binary"
cmd: go build -o ./bin/{{.APP_NAME}} ./cmd/http/main.go

start:
desc: "Start binary"
cmd: ./bin/{{.APP_NAME}}

# docs:
# desc: "Generate swagger documentation"
# cmds:
# - swag fmt
# - swag init --dir ./cmd/http

# test:
# desc: "Run tests"
# cmd: ginkgo -v -r --cover --race --keep-going --timeout=30s

install:
desc: "Install dependencies"
cmds:
- go install github.com/go-task/task/v3/cmd/task@latest
- go install github.com/cosmtrek/air@latest
5 changes: 5 additions & 0 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
//
}
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'

services:
postgres_gopos:
image: postgres:15.4-alpine3.18
container_name: postgres_gopos
env_file:
- .env
ports:
- 5432:5432
volumes:
- data:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE}

volumes:
data:
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/bagashiz/go-pos

go 1.21.0
112 changes: 112 additions & 0 deletions schema.dbml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Project "Go POS" {
database_type: 'PostgreSQL'
Note: '''
# Point of Sale System
'''
}

Enum "users_role_enum" {
"admin"
"cashier"
}

Table "payments" {
"id" bigserial [pk, increment]
"name" varchar [not null]
"type" varchar [not null]
"logo" varchar
"created_at" timestamptz [not null, default: `now()`]
"updated_at" timestamptz [not null, default: `now()`]

Indexes {
name [unique, name: "payment_name"]
}
}

Table "users" {
"id" bigserial [pk, increment]
"name" varchar [not null]
"email" varchar [not null]
"password" varchar [not null]
"role" users_role_enum [default: "cashier"]
"created_at" timestamptz [not null, default: `now()`]
"updated_at" timestamptz [not null, default: `now()`]

Indexes {
email [unique, name: "email"]
}
}

Table "orders" {
"id" bigserial [pk, increment]
"user_id" bigint [not null]
"payment_id" bigint [not null]
"customer_name" varchar [not null]
"total_price" decimal(18,2) [not null]
"total_paid" decimal(18,2) [not null]
"total_return" decimal(18,2) [not null]
"receipt_code" uuid [not null, default: `gen_random_uuid()`]
"created_at" timestamptz [not null, default: `now()`]
"updated_at" timestamptz [not null, default: `now()`]

Indexes {
customer_name [name: "orders_customer_name"]
payment_id [name: "orders_payment_id"]
user_id [name: "orders_user_id"]
receipt_code [unique, name: "receipt_code"]
}
}

Table "categories" {
"id" bigserial [pk, increment]
"updated_at" timestamptz [not null, default: `now()`]
"created_at" timestamptz [not null, default: `now()`]
"name" varchar [not null]

Indexes {
name [unique, name: "category_name"]
}
}

Table "products" {
"id" bigserial [pk, increment]
"category_id" bigint [not null]
"sku" varchar [not null]
"name" varchar [not null]
"stock" bigint [not null]
"price" decimal(18,2) [not null]
"image" varchar
"created_at" timestamptz [not null, default: `now()`]
"updated_at" timestamptz [not null, default: `now()`]

Indexes {
category_id [name: "products_category_id"]
name [name: "products_name"]
sku [unique, name: "sku"]
}
}

Table "order_products" {
"id" bigserial [pk, increment]
"order_id" bigint [not null]
"product_id" bigint [not null]
"quantity" bigint [not null]
"total_price" decimal(18,2) [not null]
"created_at" timestamptz [not null, default: `now()`]
"updated_at" timestamptz [not null, default: `now()`]

Indexes {
order_id [name: "order_product_order_id"]
product_id [name: "order_product_product_id"]
}
}

Ref "fk_payments_orders":"payments"."id" < "orders"."payment_id" [update: no action, delete: no action]

Ref "fk_users_orders":"users"."id" < "orders"."user_id" [update: no action, delete: no action]

Ref "fk_categories_products":"categories"."id" < "products"."category_id" [update: no action, delete: no action]

Ref "fk_orders_order_products":"orders"."id" < "order_products"."order_id" [update: no action, delete: no action]

Ref "fk_products_order_products":"products"."id" < "order_products"."product_id" [update: no action, delete: no action]

0 comments on commit f82fb46

Please sign in to comment.