Skip to content

Commit

Permalink
add docker-file, add initdb.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyKomarovCoder committed Oct 1, 2023
1 parent 7e84ca5 commit f65fe5c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# Environment
.env

# Logs
*.log

# Static
img2
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'

services:

db:
image: postgres:latest
restart: always
env_file:
- .env
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
ports:
- 5433:5433
volumes:
- ./internal/common/postgresql/schema/:/docker-entrypoint-initdb.ds
16 changes: 16 additions & 0 deletions internal/common/postgresql/schema/initdb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS Users
(
id SERIAL PRIMARY KEY,
username VARCHAR(20) UNIQUE NOT NULL,
password_hash VARCHAR(256) NOT NULL,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
avatar_url TEXT
);

CREATE TABLE IF NOT EXISTS Accounts (
id UUID PRIMARY KEY,
user_id INT,
balance NUMERIC,
mean_payment TEXT
);
8 changes: 4 additions & 4 deletions internal/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package models
import "github.com/google/uuid"

type Accounts struct {
ID uuid.UUID `json:"id"`
UserID uint `json:"user_id"`
Balance float64 `json:"balance"`
MeanPayment string `json:"mean_payment"`
ID uuid.UUID `json:"id" db:"id"`
UserID uint `json:"user_id" db:"user_id"`
Balance float64 `json:"balance" db:"balance"`
MeanPayment string `json:"mean_payment" db:"mean_payment"`
}
21 changes: 7 additions & 14 deletions internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@ import (

type Sex string

const (
Male Sex = "M"
Female Sex = "F"
Other Sex = "O" // :-)
)

type User struct {
ID uuid.UUID `json:"id" valid:"-"`
Username string `json:"name" valid:"-"`
Email string `json:"email" valid:"required,email"`
FirstName string `json:"firstName" valid:"required,runelength(2|20)"`
LastName string `json:"lastName" valid:"required,runelength(2|20)"`
Password string `json:"password" valid:"required,runelength(7|30),passwordcheck"`
Sex Sex `json:"sex" valid:"required,in(F|M|O)"`
AvatarURL string `json:"avatar_url" vaild:"-"`
ID uuid.UUID `json:"id" valid:"-"`
Username string `json:"name" valid:"-"`
// Email string `json:"email" valid:"required,email" db:"email"`
FirstName string `json:"firstName" valid:"required,runelength(2|20)"`
LastName string `json:"lastName" valid:"required,runelength(2|20)"`
Password string `json:"password" valid:"required,runelength(7|30),passwordcheck"`
AvatarURL string `json:"avatar_url" vaild:"-"`
}

func (u *User) UserValidate() error {
Expand Down

0 comments on commit f65fe5c

Please sign in to comment.