Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyKomarovCoder committed Dec 12, 2023
2 parents b7e6860 + 159fe38 commit 5669a9e
Show file tree
Hide file tree
Showing 19 changed files with 693 additions and 194 deletions.
27 changes: 7 additions & 20 deletions .env
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
SECRET="vzqqEH6o5so_VGJZoLhrfdrH7Y7kvFe-7N2i3I3w314=п"

DB_CONTAINER_NAME=HammyWallet_DB
DB_NAME=HammyWallets
DB_NAME_QUESTION = HammyWallet_QUESTION
DB_USER=hamster
DB_PASSWORD=2003
DB_HOST=hammy-postgres
DB_HOST=0.0.0.0
DB_SSLMODE=disable
DB_PROD_MAIN=5436
DB_PROD_QUESTION = 8300
DB_PORT=5432
DB_PORT=5436

DB_NAME_PROD=HammyWallets
DB_USER_PROD=hamster
DB_PASSWORD_PROD=56748
DB_HOST_PROD=postgres
DB_SSLMODE_PROD=disable
DB_PORT_PROD=5436
AUTH_ADDR=127.0.0.1:8010
ACCOUNT_ADDR=127.0.0.1:8020
CATEGORY_ADDR=127.0.0.1:8030

SERVER_NAME=HammyWallet_API
SERVER_HOST=127.0.0.1
SERVER_PORT=8080

FRONTEND_IP=84.23.52.156
FRONTEND_PORT=8000

REDIS_CONTAINER_NAME=HammyWallet_redis
REDIS_HOST=0.0.0.0
REDIS_PORT=6379

REDIS_HOST=redis
REDIS_PORT=6379
4 changes: 3 additions & 1 deletion .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ env:
AUTH_CONTAINER: "hammywallet-auth"
ACCOUNT_CONTAINER: "hammywallet-account"
CATEGORY_CONTAINER: "hammywallet-category"

AUTH_ADDR: auth:8010
ACCOUNT_ADDR: account:8020
CATEGORY_ADDR: category:8030
on:
push:
branches:
Expand Down
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,28 @@ prod: #lint doc
git commit -m "deploy" ; \
git push ; \
git checkout develop

testDockerUp:
docker-compose -f local-docker-compose.yaml up -d

testUp:
go run ./cmd/auth/main.go & \
go run ./cmd/category/category.go & \
go run ./cmd/account/account.go & \
go run ./cmd/api/main.go \

testDown:
# Остановка Docker Compose
#docker-compose -f local-docker-compose.yaml down

# Остановка приложения auth (если запущено)
pkill -f "go run ./cmd/auth/main.go"

# Остановка приложения category (если запущено)
pkill -f "go run ./cmd/category/category.go"

# Остановка приложения account (если запущено)
pkill -f "go run ./cmd/account/account.go"

# Остановка API (если запущено)
pkill -f "go run ./cmd/api/main.go"
21 changes: 18 additions & 3 deletions build/schema/initdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CREATE TABLE IF NOT EXISTS category (
user_id UUID REFERENCES Users(id) CONSTRAINT fk_user_category NOT NULL,
parent_tag UUID REFERENCES category(id),
"name" VARCHAR(30) NOT NULL,
image_id INT DEFAULT 0 NOT NULL,
show_income BOOLEAN,
show_outcome BOOLEAN,
regular BOOLEAN NOT NULL
Expand All @@ -52,6 +53,7 @@ CREATE TABLE IF NOT EXISTS TransactionCategory (
PRIMARY KEY (transaction_id, category_id)
);

<<<<<<< HEAD
--CREATE TABLE IF NOT EXISTS goal (
-- id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
-- user_id UUID REFERENCES "user"(user_id) NOT NULL,
Expand All @@ -62,6 +64,19 @@ CREATE TABLE IF NOT EXISTS TransactionCategory (
-- created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
-- updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
--);
=======
CREATE TABLE IF NOT EXISTS goal (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
user_id UUID REFERENCES Users(id) NOT NULL,
"name" TEXT CHECK(LENGTH("name") <= 50) NOT NULL,
"description" TEXT DEFAULT '' CHECK(LENGTH("description") <= 255),
"target" NUMERIC(10,2) NOT NULL,
"date" DATE,
"state" TEXT DEFAULT '' CHECK(LENGTH("state") <= 20),
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
);
>>>>>>> 159fe381c65bd448a92e0c9b63cdcaeff611df79

--========================================================================

Expand Down Expand Up @@ -94,7 +109,7 @@ BEGIN
VALUES (NEW.id, NULL, 'Дети', false, true, false),
(NEW.id, NULL, 'Забота о себе', false, true, false),
(NEW.id, NULL, 'Зарплата', true, false, true),
(NEW.id, NULL, 'Здровье и фитнес', false, true, false),
(NEW.id, NULL, 'Здоровье и фитнес', false, true, false),
(NEW.id, NULL, 'Кафе и рестораны', false, true, false),
(NEW.id, NULL, 'Машина', false, true, false),
(NEW.id, NULL, 'Образование', false, true, false),
Expand All @@ -121,11 +136,11 @@ BEGIN

INSERT INTO transaction(user_id, account_income, account_outcome, income, outcome, payer, description)
VALUES (NEW.id, accountCardID,
accountCardID, 0, 100, 'Пятерочка', 'Пошел в магазин за вкусняшками') RETURNING id INTO transaction_idI;
accountCardID, 0, 100, 'Тестовая транзакция1', 'Все хомячьки приветствуют вас, и просят удалить эти транзации)') RETURNING id INTO transaction_idI;

INSERT INTO transaction(user_id, account_income, account_outcome, income, outcome, payer, description)
VALUES (NEW.id, accountCardID,
accountCardID, 100, 0, 'Пятерочка', 'Вернули деньги оплата не прошла') RETURNING id INTO transaction_idO;
accountCardID, 100, 0, 'Тестовая транзакция2', 'Все хомячьки приветствуют вас, и просят удалить эти транзации)') RETURNING id INTO transaction_idO;

INSERT INTO TransactionCategory(transaction_id, category_id)
VALUES (transaction_idI, categoryID),
Expand Down
18 changes: 15 additions & 3 deletions cmd/api/init/app/init.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package app

import (
"os"

"github.com/go-park-mail-ru/2023_2_Hamster/cmd/api/init/router"
"github.com/go-park-mail-ru/2023_2_Hamster/internal/common/logger"
"github.com/go-park-mail-ru/2023_2_Hamster/internal/middleware"
"github.com/joho/godotenv"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand Down Expand Up @@ -37,26 +40,35 @@ import (
)

func Init(db *pgxpool.Pool, redis *redis.Client, log *logger.Logger) *mux.Router {
err := godotenv.Load()
if err != nil {
log.Fatalf("Erorr loading .env file %v\n", err)
}

authAddr := os.Getenv("AUTH_ADDR")
accountAddr := os.Getenv("ACCOUNT_ADDR")
categoryAddr := os.Getenv("CATEGORY_ADDR")

opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.FailOnNonTempDialError(true),
}

authConn, err := grpc.Dial("auth:8010", opts...)
authConn, err := grpc.Dial(authAddr, opts...)
if err != nil {
log.Fatalf("Connection refused auth: %v\n", err)
}

authClient := generatedAuth.NewAuthServiceClient(authConn)

accountConn, err := grpc.Dial("account:8020", opts...)
accountConn, err := grpc.Dial(accountAddr, opts...)

if err != nil {
log.Fatalf("Connection refused account %v\n", err)
}

categoryConn, err := grpc.Dial("category:8030", opts...)
categoryConn, err := grpc.Dial(categoryAddr, opts...)

if err != nil {
log.Fatalf("Connection refused category %v\n", err)
Expand Down
4 changes: 4 additions & 0 deletions internal/microservices/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Usecase interface {
Login(ctx context.Context, login, plainPassword string) (uuid.UUID, string, string, error)
CheckLoginUnique(ctx context.Context, login string) (bool, error)

ChangePassword(ctx context.Context, input ChangePasswordInput) error

GetByID(ctx context.Context, userID uuid.UUID) (*models.User, error)
}

Expand All @@ -26,6 +28,8 @@ type Repository interface {
GetUserByLogin(ctx context.Context, login string) (*models.User, error)
GetByID(ctx context.Context, userID uuid.UUID) (*models.User, error)

ChangePassword(ctx context.Context, userID uuid.UUID, newPassword string) error

// Validation
// CheckCorrectPassword(ctx context.Context, password string) error
// CheckExistUsername(ctx context.Context, username string) error
Expand Down
19 changes: 19 additions & 0 deletions internal/microservices/auth/auth_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type (
UniqCheckInput struct {
Login string `json:"login" valid:"required"`
}

ChangePasswordInput struct {
Id uuid.UUID
OldPassword string `json:"old_password" valid:"required,length(4|20)"`
NewPassword string `json:"new_password" valid:"required,length(4|20)"`
}
)

func (li *LoginInput) CheckValid() error {
Expand All @@ -60,6 +66,19 @@ func (si *SignUpInput) CheckValid() error {
return err
}

func (ui *UniqCheckInput) CheckValid() error {
ui.Login = html.EscapeString(ui.Login)
_, err := valid.ValidateStruct(*ui)
return err
}

func (ci *ChangePasswordInput) CheckValid() error {
ci.OldPassword = html.EscapeString(ci.OldPassword)
ci.NewPassword = html.EscapeString(ci.NewPassword)
_, err := valid.ValidateStruct(*ci)
return err
}

// Errors

const (
Expand Down
Loading

0 comments on commit 5669a9e

Please sign in to comment.