Skip to content

Commit

Permalink
Пофиксил что-то
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDxYk594 committed Dec 18, 2024
1 parent 1f3d5be commit f8aa129
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 213 deletions.
30 changes: 11 additions & 19 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,32 @@ jobs:
name: linters
runs-on: ubuntu-latest
steps:
-
name: checkout staging
- name: checkout staging
uses: actions/checkout@v4
-
name: install Go

- name: install Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
-
name: golangci-lint

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.62.2

tests:
runs-on: ubuntu-latest
needs: linter
steps:
-
name: checkout staging
- name: checkout staging
uses: actions/checkout@v4
-
name: install Go

- name: install Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
-
run: |
sudo apt-get -y update
sudo apt-get install -y libwebp-dev wkhtmltopdf
-
name: build
run: go build -v ./...
-
name: Test

- name: Test
run: go test -v ./...

deploy:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build_all: build_auth build_user build_poll build_board

run_tests:
@echo "==> Running tests..."
@go test $(GOFLAGS) -coverprofile ../coverage_raw.out -v ./...
@go test $(GOFLAGS) -coverprofile coverage_raw.out -v ./...

test: run_tests
@echo "==> Calculating coverage..."
Expand Down
24 changes: 18 additions & 6 deletions database/elastic/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"

"github.com/elastic/go-elasticsearch/v8"
Expand Down Expand Up @@ -110,7 +110,7 @@ func deleteIndex(index string, es *elasticsearch.Client) {

func createIndexWithMapping(index, mappingFile string, es *elasticsearch.Client) {
// Read mapping JSON from file
mapping, err := ioutil.ReadFile(mappingFile)
mapping, err := os.ReadFile(mappingFile)
if err != nil {
log.Fatalf("Error reading mapping file: %s", err)
}
Expand Down Expand Up @@ -189,10 +189,22 @@ func loadDataToElasticsearch(ctx context.Context, cfg Configuration, es *elastic
}

// Write to buffer
writer.Write(metaLine)
writer.WriteByte('\n')
writer.Write(dataLine)
writer.WriteByte('\n')
_, err = writer.Write(metaLine)
if err != nil {
return fmt.Errorf("elastic: %w", err)
}
err = writer.WriteByte('\n')
if err != nil {
return fmt.Errorf("elastic: %w", err)
}
_, err = writer.Write(dataLine)
if err != nil {
return fmt.Errorf("elastic: %w", err)
}
err = writer.WriteByte('\n')
if err != nil {
return fmt.Errorf("elastic: %w", err)
}

count++
if count%batchSize == 0 {
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/board/repository/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +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"
if 1 == 1 {
panic(funcName + " not implemented")
}
// funcName := "UpdateCard"
// if 1 == 1 {
// panic(funcName + " not implemented")
// }

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/board/repository/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func (r *BoardRepository) RearrangeCards(ctx context.Context, column1 []models.C
return fmt.Errorf("%s (batch query): %w", funcName, err)
}

tx.Commit(ctx)
err = tx.Commit(ctx)
logging.Debug(ctx, funcName, " commit has err: ", err)
if err != nil {
return fmt.Errorf("%s (commit): %w", funcName, err)
Expand Down Expand Up @@ -713,7 +713,7 @@ func (r *BoardRepository) RearrangeColumns(ctx context.Context, columns []models
return fmt.Errorf("%s (batch query): %w", funcName, err)
}

tx.Commit(ctx)
err = tx.Commit(ctx)
logging.Debug(ctx, funcName, " commit has err: ", err)
if err != nil {
return fmt.Errorf("%s (commit): %w", funcName, err)
Expand Down
8 changes: 7 additions & 1 deletion internal/pkg/board/usecase/board_uc.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,10 @@ func (uc *BoardUsecase) MoveColumn(ctx context.Context, userID int64, columnID i
columns = slices.Insert(columns, destIdx-1, col)
}

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

return nil
}
Expand Down Expand Up @@ -805,6 +808,9 @@ func (uc *BoardUsecase) GetSharedCard(ctx context.Context, userID int64, cardUUI
}

board, err := uc.boardRepository.GetBoard(ctx, boardID, -1)
if err != nil {
return nil, nil, err
}

return nil, &models.SharedCardDummyResponse{
Card: cardDetails,
Expand Down
7 changes: 2 additions & 5 deletions internal/pkg/middleware/logging_middleware/middleware.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package logging_middleware

import (
"RPO_back/internal/pkg/utils/logging"
"context"
"net/http"
"sync"

log "github.com/sirupsen/logrus"
)

type contextKey string

const rIDKey = contextKey("requestID")

var (
rIDCounter uint64 = 1
mu sync.Mutex
Expand All @@ -24,7 +21,7 @@ func LoggingMiddleware(next http.Handler) http.Handler {
rID := rIDCounter
mu.Unlock()

ctx := context.WithValue(r.Context(), rIDKey, rID)
ctx := context.WithValue(r.Context(), logging.RequestIDkey, rID)
log.Infof("Запрос: %s %s, RequestID: %d", r.Method, r.RequestURI, rID)

next.ServeHTTP(w, r.WithContext(ctx))
Expand Down
24 changes: 12 additions & 12 deletions internal/pkg/middleware/logging_middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func TestLoggingMiddleware(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

type testWriter struct {
content []byte
}

func (tw *testWriter) Write(p []byte) (n int, err error) {
tw.content = append(tw.content, p...)
return len(p), nil
}

func (tw *testWriter) String() string {
return string(tw.content)
}
// type testWriter struct {
// content []byte
// }

// func (tw *testWriter) Write(p []byte) (n int, err error) {
// tw.content = append(tw.content, p...)
// return len(p), nil
// }

// func (tw *testWriter) String() string {
// return string(tw.content)
// }
3 changes: 3 additions & 0 deletions internal/pkg/user/usecase/user_uc.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (uc *UserUsecase) SetMyAvatar(ctx context.Context, userID int64, file *mode
}

err = uc.userRepo.SetUserAvatar(ctx, userID, fileID)
if err != nil {
return nil, fmt.Errorf("%s: %w", funcName, err)
}

return uc.userRepo.GetUserProfile(ctx, userID)
}
Expand Down
59 changes: 0 additions & 59 deletions internal/pkg/utils/logging/logging_test.go

This file was deleted.

Loading

0 comments on commit f8aa129

Please sign in to comment.