Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step_2_update_service #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/rs/zerolog/log"

"github.com/golerplate/user-store-svc/internal/config"
database_v1_pgx "github.com/golerplate/user-store-svc/internal/database/v1/pgx"
database_pgx_v2 "github.com/golerplate/user-store-svc/internal/database/v2/pgx"
handlers_grpc "github.com/golerplate/user-store-svc/internal/handlers/grpc"
service "github.com/golerplate/user-store-svc/internal/service/v1"
service_v1 "github.com/golerplate/user-store-svc/internal/service/v2"
)

func main() {
Expand All @@ -40,9 +40,9 @@ func main() {
log.Fatal().Err(err).
Msg("main: unable to create database connection")
}
databaseClient := database_v1_pgx.NewClient(ctx, databaseConnection)
databaseClient := database_pgx_v2.NewClient(ctx, databaseConnection)

userStoreService, err := service.NewUserStoreService(ctx, databaseClient, cacheRedis)
userStoreService, err := service_v1.NewUserStoreService(ctx, databaseClient, cacheRedis)
if err != nil {
log.Fatal().Err(err).
Msg("main: unable to create user store service")
Expand Down
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/bufbuild/connect-go v1.10.0
github.com/bufbuild/connect-grpcreflect-go v1.1.0
github.com/golang/protobuf v1.5.3
github.com/golerplate/contracts v0.0.21
github.com/golerplate/contracts v0.0.24
github.com/golerplate/pkg v0.0.16
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.9
Expand Down
2 changes: 2 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golerplate/contracts v0.0.21 h1:2jXAyledEYG+a7cDspcVfgXlhtaxmaOO4PRchnNSNOA=
github.com/golerplate/contracts v0.0.21/go.mod h1:ngmB/qx1WQFkGMS4TNGvHkWR1RxAtedI8cz7ig/EYP8=
github.com/golerplate/contracts v0.0.24 h1:bobnjQ0xRry6zEZ1BG0D3Vf04L90cyosMzUhYp38FDM=
github.com/golerplate/contracts v0.0.24/go.mod h1:ngmB/qx1WQFkGMS4TNGvHkWR1RxAtedI8cz7ig/EYP8=
github.com/golerplate/pkg v0.0.16 h1:Thb8Hdj5gK1AmtRNGti7UZPSLNvc7noiyQKd1a71pzM=
github.com/golerplate/pkg v0.0.16/go.mod h1:q3ou/jgtgNnQ35qrlRKOqsMVhnPpbno0SQ3EAM3pO6Q=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE users ADD COLUMN is_banned BOOLEAN DEFAULT FALSE;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
ALTER TABLE users DROP COLUMN is_banned;
-- +goose StatementEnd
17 changes: 17 additions & 0 deletions src/internal/database/v2/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package database_v2

import (
"context"

entities_user_v2 "github.com/golerplate/user-store-svc/internal/entities/user/v2"
)

//go:generate mockgen -source interface.go -destination mocks/mock_database.go -package database_mocks
type Database interface {
CreateUser(ctx context.Context, req *entities_user_v2.CreateUserRequest) (*entities_user_v2.User, error)
GetUserByEmail(ctx context.Context, email string) (*entities_user_v2.User, error)
GetUserByID(ctx context.Context, id string) (*entities_user_v2.User, error)
GetUserByUsername(ctx context.Context, username string) (*entities_user_v2.User, error)

UpdateUsername(ctx context.Context, userID, username string) (*entities_user_v2.User, error)
}
116 changes: 116 additions & 0 deletions src/internal/database/v2/mocks/mock_database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/internal/database/v2/pgx/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package database_pgx_v2

import (
"context"

"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"

database_v2 "github.com/golerplate/user-store-svc/internal/database/v2"
)

type dbClient struct {
connection *sqlx.DB
}

func NewClient(ctx context.Context, db *sqlx.DB) database_v2.Database {
return &dbClient{
connection: db,
}
}
Loading
Loading