Skip to content

Commit

Permalink
Merge branch 'dev' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDxYk594 committed Dec 17, 2024
2 parents 762b618 + 6be2d58 commit 63af8c6
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 22 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Production Deployment
on:
push:
branches:
branches:
- staging
pull_request:
branches:
Expand All @@ -19,7 +19,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: '1.23'
-
-
name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
Expand All @@ -28,7 +28,7 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
-
-
name: checkout staging
uses: actions/checkout@v4
-
Expand All @@ -43,22 +43,30 @@ jobs:
-
name: build
run: go build -v ./...
-
-
name: Test
run: go test -v ./...

deploy:
name: deploy
name: deploy
runs-on: ubuntu-latest
steps:
-
name: pull code
- name: pull code
uses: appleboy/ssh-action@master
with:
host: kanban-pumpkin.ru
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: cd /home/ubuntu/back && git pull

- name: build golang
uses: appleboy/ssh-action@master
with:
host: kanban-pumpkin.ru
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: cd /home/ubuntu/back && git checkout staging && git pull
script: cd /home/ubuntu/back && make build_all -j

- name: build containers
uses: appleboy/ssh-action@master
with:
Expand All @@ -68,10 +76,11 @@ jobs:
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: cd /home/ubuntu/back && sudo docker compose build

- name: restart service
uses: appleboy/ssh-action@master
with:
host: kanban-pumpkin.ru
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: cd /home/ubuntu/back && make build_all -j && docker compose up --build
script: cd /home/ubuntu/back && sudo docker compose up
3 changes: 2 additions & 1 deletion internal/pkg/board/repository/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func (r *BoardRepository) GetColumnsForBoard(ctx context.Context, boardID int64)
col_id,
title
FROM kanban_column
WHERE board_id = $1;
WHERE board_id = $1
ORDER BY order_index;
`
rows, err := r.db.Query(ctx, query, boardID)
logging.Debug(ctx, funcName, " query has err: ", err)
Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/board/repository/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func (be *BoardElasticRepository) CreateCard(ctx context.Context, boardID int64,
}

func (be *BoardElasticRepository) UpdateCard(ctx context.Context, boardID int64, cardID int64, cardTitle string) error {
// funcName := "UpdateCard"
funcName := "UpdateCard"

panic(funcName + " not implemented")

return nil
}

Expand Down
23 changes: 18 additions & 5 deletions internal/pkg/board/repository/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,20 +692,33 @@ func (r *BoardRepository) RearrangeCards(ctx context.Context, column1 []models.C

// RearrangeColumns обновляет позиции всех колонок, чтобы сделать порядок, как в слайсе
func (r *BoardRepository) RearrangeColumns(ctx context.Context, columns []models.Column) (err error) {
panic("not implemented")
funcName := "RearrangeColumns"
query := ` WITH`
query := `
UPDATE kanban_column SET order_index=$1 WHERE col_id=$2;
`
tx, err := r.db.Begin(ctx)
if err != nil {
return fmt.Errorf("%s (begin): %w", funcName, err)
}

batch := &pgx.Batch{}
for _, col := range columns {
batch.Queue(query, col.OrderIndex)
for idx, col := range columns {
batch.Queue(query, idx, col.ID)
}

br := r.db.SendBatch(ctx, batch)
br := tx.SendBatch(ctx, batch)
err = br.Close()
logging.Debug(ctx, funcName, " batch query has err: ", err)
if err != nil {
return fmt.Errorf("%s (batch query): %w", funcName, err)
}

tx.Commit(ctx)
logging.Debug(ctx, funcName, " commit has err: ", err)
if err != nil {
return fmt.Errorf("%s (commit): %w", funcName, err)
}

return nil
}

Expand Down
58 changes: 52 additions & 6 deletions internal/pkg/board/usecase/board_uc.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,24 @@ func (uc *BoardUsecase) CreateNewCard(ctx context.Context, userID int64, boardID

// UpdateCard обновляет карточку и возвращает обновлённую версию
func (uc *BoardUsecase) UpdateCard(ctx context.Context, userID int64, cardID int64, data *models.CardPatchRequest) (updatedCard *models.Card, err error) {
funcName := "UpdateCard"
role, boardID, err := uc.boardRepository.GetMemberFromCard(ctx, userID, cardID)
if err != nil {
if errors.Is(err, errs.ErrNotPermitted) {
return nil, fmt.Errorf("UpdateCard (get permissions): %w", err)
return nil, fmt.Errorf("%s (get permissions): %w", funcName, err)
}
if errors.Is(err, errs.ErrNotFound) {
return nil, fmt.Errorf("UpdateCard (get permissions): %w", err)
return nil, fmt.Errorf("%s (get permissions): %w", funcName, err)
}
return nil, fmt.Errorf("UpdateCard (get permissions): %w", err)
return nil, fmt.Errorf("%s (get permissions): %w", funcName, err)
}
if role == "viewer" {
return nil, fmt.Errorf("UpdateCard (check): %w", errs.ErrNotPermitted)
return nil, fmt.Errorf("%s (check): %w", funcName, errs.ErrNotPermitted)
}

updatedCard, err = uc.boardRepository.UpdateCard(ctx, cardID, *data)
if err != nil {
return nil, fmt.Errorf("UpdateCard (update): %w", err)
return nil, fmt.Errorf("%s (update): %w", funcName, err)
}

fmt.Println(boardID)
Expand Down Expand Up @@ -690,7 +691,52 @@ func (uc *BoardUsecase) MoveCard(ctx context.Context, userID int64, cardID int64

// MoveColumn перемещает колонку на доске
func (uc *BoardUsecase) MoveColumn(ctx context.Context, userID int64, columnID int64, moveReq *models.ColumnMoveRequest) (err error) {
panic("not implemented")
funcName := "MoveColumn"
role, boardID, err := uc.boardRepository.GetMemberFromColumn(ctx, userID, columnID)
if err != nil {
return fmt.Errorf("%s (get): %w", funcName, err)
}
if role == "viewer" {
return fmt.Errorf("%s (check): %w", funcName, errs.ErrNotPermitted)
}

columns, err := uc.boardRepository.GetColumnsForMove(ctx, boardID)
if err != nil {
return fmt.Errorf("%s (column): %w", funcName, err)
}

fromIdx := -1
destIdx := -1

for idx, col := range columns {
if col.ID == columnID {
fromIdx = idx
break
}
if col.ID == *moveReq.NextColumnID {
destIdx = idx
}
}

if fromIdx == -1 {
return fmt.Errorf("%s (from idx): not found", funcName)
}

if destIdx == -1 {
destIdx = len(columns) - 1
}

col := columns[fromIdx]
columns = slices.Delete(columns, fromIdx, fromIdx+1)
if fromIdx > destIdx {
columns = slices.Insert(columns, destIdx, col)
} else {
columns = slices.Insert(columns, destIdx-1, col)
}

uc.boardRepository.RearrangeColumns(ctx, columns)

return nil
}

// GetCardDetailsUnauthorized получает подробности карточки даже без авторизации
Expand Down

0 comments on commit 63af8c6

Please sign in to comment.