diff --git a/Makefile b/Makefile index d28a469..d7a1858 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ sparkit-down: .PHONY: sparkit-test sparkit-test: go test -json ./... -coverprofile coverprofile_.tmp -coverpkg=./... ; \ - grep -v -e '/mocks' -e 'mock_repository.go' -e 'mock.go' -e 'docs.go' -e '_easyjson.go' -e '.pb.go' -e 'gen.go' coverprofile_.tmp > coverprofile.tmp ; \ + grep -v -e '/mocks' -e 'mock_repository.go' -e 'mock.go' -e 'docs.go' -e '_easyjson.go' -e '.pb.go' -e 'gen.go' -e 'main.go' coverprofile_.tmp > coverprofile.tmp ; \ rm coverprofile_.tmp ; \ go tool cover -html coverprofile.tmp -o ../heatmap.html; \ go tool cover -func coverprofile.tmp diff --git a/docker/.env b/docker/.env index 6f1ff23..f9c4b47 100644 --- a/docker/.env +++ b/docker/.env @@ -10,10 +10,10 @@ DB_USER=app_user DB_PASSWORD=test DB_NAME=sparkitDB DB_SSLMODE=disable -SERVER_CERT_PATH=/etc/letsencrypt/live/spark-it.site/fullchain.pem -SERVER_KEY_PATH=/etc/letsencrypt/live/spark-it.site/privkey.pem +# SERVER_CERT_PATH=/etc/letsencrypt/live/spark-it.site/fullchain.pem +# SERVER_KEY_PATH=/etc/letsencrypt/live/spark-it.site/privkey.pem SHOP_ID=999343 SECRET_SHOP_KEY=test_tg4qykklfcjLeOx-oMnv0jBUTKu6Cr7-FVqkG1-O1IY -# SERVER_CERT_PATH=../server.crt -# SERVER_KEY_PATH=../server.key +SERVER_CERT_PATH=../server.crt +SERVER_KEY_PATH=../server.key diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 2ee4e7a..26e6b00 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -18,6 +18,7 @@ services: - SparkIt-network volumes: - ~/imagedata:/home/${OS_USER}/imagedata + - ./resources/:/home/${OS_USER}/imageproduct - ${SERVER_CERT_PATH}:/etc/ssl/certs/server.crt - ${SERVER_KEY_PATH}:/etc/ssl/private/server.key diff --git a/docker/resources/likes100.png b/docker/resources/likes100.png new file mode 100644 index 0000000..1b8d6f4 Binary files /dev/null and b/docker/resources/likes100.png differ diff --git a/docker/resources/likes150.png b/docker/resources/likes150.png new file mode 100644 index 0000000..7efa738 Binary files /dev/null and b/docker/resources/likes150.png differ diff --git a/docker/resources/likes50.png b/docker/resources/likes50.png new file mode 100644 index 0000000..19d1070 Binary files /dev/null and b/docker/resources/likes50.png differ diff --git a/internal/pkg/payments/usecase/usecase.go b/internal/pkg/payments/usecase/usecase.go index 0ef6b93..20acecf 100644 --- a/internal/pkg/payments/usecase/usecase.go +++ b/internal/pkg/payments/usecase/usecase.go @@ -163,7 +163,7 @@ func (u *UseCase) CreateProduct(ctx context.Context, product models.Product) (in u.logger.Error("usecase create product bad price", zap.Int("price", product.Price)) return -1, fmt.Errorf("invalid price") } - product.ImageLink = "" + product.ImageLink = product.Title + ".png" id, err := u.repo.CreateProduct(ctx, product) if err != nil { u.logger.Error("usecase create product error", zap.Error(err)) diff --git a/internal/pkg/payments/usecase/usecase_test.go b/internal/pkg/payments/usecase/usecase_test.go index 26e5bfc..4379dfb 100644 --- a/internal/pkg/payments/usecase/usecase_test.go +++ b/internal/pkg/payments/usecase/usecase_test.go @@ -300,7 +300,7 @@ func TestUseCase(t *testing.T) { args: args{ctx: ctx, product: models.Product{Title: "prod", Price: 100}}, mockSetup: func(repo *mocks.MockRepository) { repo.EXPECT().CreateProduct(ctx, gomock.Any()).DoAndReturn(func(ctx context.Context, p models.Product) (int, error) { - if p.Title != "prod" || p.Price != 100 || p.ImageLink != "" { + if p.Title != "prod" || p.Price != 100 || p.ImageLink != p.Title+".png" { return -1, fmt.Errorf("unexpected product") } return 1, nil diff --git a/internal/pkg/personalities/delivery/grpc/handlers.go b/internal/pkg/personalities/delivery/grpc/handlers.go index 7627656..8b1031e 100644 --- a/internal/pkg/personalities/delivery/grpc/handlers.go +++ b/internal/pkg/personalities/delivery/grpc/handlers.go @@ -229,7 +229,8 @@ func (h *GrpcPersonalitiesHandler) DeleteProfile(ctx context.Context, return res, nil } -func (h *GrpcPersonalitiesHandler) ChangePassword(ctx context.Context, in *generatedPersonalities.ChangePasswordRequest) (*generatedPersonalities.ChangePasswordResponse, error) { +func (h *GrpcPersonalitiesHandler) ChangePassword(ctx context.Context, + in *generatedPersonalities.ChangePasswordRequest) (*generatedPersonalities.ChangePasswordResponse, error) { err := h.userUC.ChangePassword(ctx, int(in.UserID), in.Password) if err != nil { return nil, fmt.Errorf("Grpc change password error : %w", err) diff --git a/internal/pkg/personalities/repo/user/postgresql.go b/internal/pkg/personalities/repo/user/postgresql.go index f6c4314..68439fe 100644 --- a/internal/pkg/personalities/repo/user/postgresql.go +++ b/internal/pkg/personalities/repo/user/postgresql.go @@ -96,7 +96,14 @@ func (repo *Storage) GetUsernameByUserId(ctx context.Context, userId int) (strin } func (repo *Storage) GetFeedList(ctx context.Context, userId int, receivers []int) ([]models.User, error) { - rows, err := repo.DB.Query("SELECT id, username FROM users WHERE id != $1 AND id NOT IN (SELECT receiver FROM reaction WHERE author = $2)", userId, userId) + + query := `SELECT u.id, u.username + FROM users u + JOIN profile p ON p.id = u.profile + WHERE u.id != $1 AND + u.id NOT IN (SELECT receiver FROM reaction WHERE author = $1) AND + p.gender != (SELECT gender FROM profile WHERE id = (SELECT profile FROM users WHERE id = $1))` + rows, err := repo.DB.Query(query, userId) if err != nil { return []models.User{}, fmt.Errorf("GetFeedList err: %w", err) } diff --git a/internal/pkg/personalities/repo/user/postgresql_test.go b/internal/pkg/personalities/repo/user/postgresql_test.go index 321d930..bb97051 100644 --- a/internal/pkg/personalities/repo/user/postgresql_test.go +++ b/internal/pkg/personalities/repo/user/postgresql_test.go @@ -419,12 +419,12 @@ func TestGetFeedList(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if tt.queryError == nil { - mock.ExpectQuery("SELECT id, username FROM users"). - WithArgs(tt.userID, tt.userID). + mock.ExpectQuery(`SELECT`). + WithArgs(tt.userID). WillReturnRows(tt.queryRows) } else { - mock.ExpectQuery("SELECT id, username FROM users"). - WithArgs(tt.userID, tt.userID). + mock.ExpectQuery(`SELECT`). + WithArgs(tt.userID). WillReturnError(tt.queryError) } list, err := repo.GetFeedList(ctx, tt.userID, tt.receivers) diff --git a/internal/pkg/personalities/usecase/profile/usecase.go b/internal/pkg/personalities/usecase/profile/usecase.go index 1431e1a..1eefcda 100644 --- a/internal/pkg/personalities/usecase/profile/usecase.go +++ b/internal/pkg/personalities/usecase/profile/usecase.go @@ -112,7 +112,7 @@ func checkAge(age int) error { if age < 18 { return sparkiterrors.ErrSmallAge } - if age > 100 { + if age > 120 { return sparkiterrors.ErrBigAge } return nil diff --git a/internal/pkg/personalities/usecase/profile/usecase_test.go b/internal/pkg/personalities/usecase/profile/usecase_test.go index c30888c..4789b89 100644 --- a/internal/pkg/personalities/usecase/profile/usecase_test.go +++ b/internal/pkg/personalities/usecase/profile/usecase_test.go @@ -352,7 +352,7 @@ func TestCheckAge(t *testing.T) { }, { name: "big age", - age: 101, + age: 121, wantErr: sparkiterrors.ErrBigAge, }, }