From c44aeb3d222b9c6b5ac8840dddf63bf7878bd1c9 Mon Sep 17 00:00:00 2001 From: DeDxYk594 Date: Tue, 17 Dec 2024 21:55:21 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9A=D0=B0=D0=BA=D0=B8=D0=B5-=D1=82=D0=BE?= =?UTF-8?q?=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pkg/board/interfaces.go | 2 +- internal/pkg/board/repository/columns.go | 3 +- internal/pkg/board/repository/members.go | 23 +++++++++--- internal/pkg/board/usecase/board_uc.go | 47 +++++++++++++++++++++++- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/internal/pkg/board/interfaces.go b/internal/pkg/board/interfaces.go index 7cc1f21..7504137 100644 --- a/internal/pkg/board/interfaces.go +++ b/internal/pkg/board/interfaces.go @@ -19,7 +19,7 @@ type BoardUsecase interface { CreateNewCard(ctx context.Context, userID int64, boardID int64, data *models.CardPostRequest) (newCard *models.Card, err error) UpdateCard(ctx context.Context, userID int64, cardID int64, data *models.CardPatchRequest) (updatedCard *models.Card, err error) DeleteCard(ctx context.Context, userID int64, cardID int64) (err error) - SearchCards(ctx context.Context, userID int64, query string) (cards []models.Card, err error) + SearchCards(ctx context.Context, userID int64, query string) (cards []models.ElasticCard, err error) CreateColumn(ctx context.Context, userID int64, boardID int64, data *models.ColumnRequest) (newCol *models.Column, err error) UpdateColumn(ctx context.Context, userID int64, columnID int64, data *models.ColumnRequest) (updatedCol *models.Column, err error) DeleteColumn(ctx context.Context, userID int64, columnID int64) (err error) diff --git a/internal/pkg/board/repository/columns.go b/internal/pkg/board/repository/columns.go index 9f4b262..9b5d773 100644 --- a/internal/pkg/board/repository/columns.go +++ b/internal/pkg/board/repository/columns.go @@ -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) diff --git a/internal/pkg/board/repository/members.go b/internal/pkg/board/repository/members.go index 924dbcf..841272b 100644 --- a/internal/pkg/board/repository/members.go +++ b/internal/pkg/board/repository/members.go @@ -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 } diff --git a/internal/pkg/board/usecase/board_uc.go b/internal/pkg/board/usecase/board_uc.go index ff05748..550f182 100644 --- a/internal/pkg/board/usecase/board_uc.go +++ b/internal/pkg/board/usecase/board_uc.go @@ -685,7 +685,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 получает подробности карточки даже без авторизации From e7ecb973ed493d18ef059f5097cc3f8da2d25ad7 Mon Sep 17 00:00:00 2001 From: DeDxYk594 Date: Tue, 17 Dec 2024 22:02:07 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20CI/CD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 25 +++++++++++++++------- internal/pkg/board/interfaces.go | 1 - internal/pkg/board/repository/elastic.go | 2 ++ internal/pkg/board/usecase/board_uc.go | 27 ++++++++++++------------ 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1f6b3e7..9364e3f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,7 +1,7 @@ name: Production Deployment on: push: - branches: + branches: - staging pull_request: branches: @@ -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: @@ -29,7 +29,7 @@ jobs: needs: linter runs-on: ubuntu-latest steps: - - + - name: checkout staging uses: actions/checkout@v4 - @@ -44,23 +44,31 @@ jobs: - name: build run: go build -v ./... - - + - name: Test run: go test -v ./... deploy: - name: deploy + name: deploy needs: tests 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 && make build_all -j + - name: build containers uses: appleboy/ssh-action@master with: @@ -70,10 +78,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 diff --git a/internal/pkg/board/interfaces.go b/internal/pkg/board/interfaces.go index 78dd563..6077c32 100644 --- a/internal/pkg/board/interfaces.go +++ b/internal/pkg/board/interfaces.go @@ -105,7 +105,6 @@ type BoardRepo interface { } type BoardElasticRepo interface { - PutCard(ctx context.Context, boardID int64, cardID int64, cardTitle string) error Search(ctx context.Context, boards []models.Board, searchValue string) (foundCards []int64, err error) DeleteCard(ctx context.Context, cardID int64) (err error) } diff --git a/internal/pkg/board/repository/elastic.go b/internal/pkg/board/repository/elastic.go index 40ebf4d..ffea381 100644 --- a/internal/pkg/board/repository/elastic.go +++ b/internal/pkg/board/repository/elastic.go @@ -49,6 +49,8 @@ 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" + panic(funcName + " not implemented") + return nil } diff --git a/internal/pkg/board/usecase/board_uc.go b/internal/pkg/board/usecase/board_uc.go index df66c6f..b168c6c 100644 --- a/internal/pkg/board/usecase/board_uc.go +++ b/internal/pkg/board/usecase/board_uc.go @@ -205,10 +205,10 @@ func (uc *BoardUsecase) CreateNewCard(ctx context.Context, userID int64, boardID return nil, fmt.Errorf("CreateNewCard (create): %w", err) } - err = uc.boardElasticRepository.PutCard(ctx, boardID, card.ID, card.Title) - if err != nil { - return nil, fmt.Errorf("CreateNewCard (elastic put): %w", err) - } + // err = uc.boardElasticRepository.PutCard(ctx, boardID, card.ID, card.Title) + // if err != nil { + // return nil, fmt.Errorf("CreateNewCard (elastic put): %w", err) + // } return &models.Card{ ID: card.ID, @@ -221,31 +221,32 @@ 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) - err = uc.boardElasticRepository.PutCard(ctx, boardID, updatedCard.ID, updatedCard.Title) - if err != nil { - return nil, fmt.Errorf("UpdateCard (elastic update): %w", err) - } + // err = uc.boardElasticRepository.PutCard(ctx, boardID, updatedCard.ID, updatedCard.Title) + // if err != nil { + // return nil, fmt.Errorf("UpdateCard (elastic update): %w", err) + // } return &models.Card{ ID: updatedCard.ID, From 6be2d589d12478ef3b70199d68d03c1be6fa7e22 Mon Sep 17 00:00:00 2001 From: DeDxYk594 Date: Tue, 17 Dec 2024 22:04:01 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BE=D1=82=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9364e3f..655247f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -50,7 +50,6 @@ jobs: deploy: name: deploy - needs: tests runs-on: ubuntu-latest steps: - name: pull code