From a9dcb09ff158569cc9d738a0ed6661ed48c8c52b Mon Sep 17 00:00:00 2001 From: Bastien Rigaud Date: Sun, 18 Feb 2024 18:48:50 +0100 Subject: [PATCH] feat: work on skeleton --- Makefile | 4 +- src/cmd/main.go | 10 ++- src/go.mod | 13 +++- src/go.sum | 18 +++++ .../{service => }/datastore/interface.go | 0 .../datastore/planetscale/init.go | 2 +- .../datastore/planetscale/user.go | 11 ++- src/internal/handlers/grpc/server.go | 6 +- src/internal/handlers/grpc/user/v1/init.go | 8 +-- src/internal/handlers/grpc/user/v1/user.go | 72 ++++++++++++++++++- .../handlers/grpc/user/v1/user_test.go | 59 +++++++++++++++ src/internal/service/init.go | 13 ---- src/internal/service/v1/init.go | 17 +++++ src/internal/service/{ => v1}/interface.go | 2 +- src/internal/service/{ => v1}/user.go | 2 +- 15 files changed, 204 insertions(+), 33 deletions(-) rename src/internal/{service => }/datastore/interface.go (100%) rename src/internal/{service => }/datastore/planetscale/init.go (73%) rename src/internal/{service => }/datastore/planetscale/user.go (55%) delete mode 100644 src/internal/service/init.go create mode 100644 src/internal/service/v1/init.go rename src/internal/service/{ => v1}/interface.go (92%) rename src/internal/service/{ => v1}/user.go (93%) diff --git a/Makefile b/Makefile index 12cd031..e691a10 100644 --- a/Makefile +++ b/Makefile @@ -4,5 +4,5 @@ run: update: cd src && go mod tidy -test: - cd src/tests/integration && go test -v \ No newline at end of file +unit-test: + cd src && go test -v -cover ./... \ No newline at end of file diff --git a/src/cmd/main.go b/src/cmd/main.go index a90eeba..ae26338 100644 --- a/src/cmd/main.go +++ b/src/cmd/main.go @@ -10,9 +10,9 @@ import ( "github.com/rs/zerolog/log" "github.com/Golerplate/user-store-svc/internal/config" + serviceDatastore "github.com/Golerplate/user-store-svc/internal/datastore/planetscale" handlers_grpc "github.com/Golerplate/user-store-svc/internal/handlers/grpc" - "github.com/Golerplate/user-store-svc/internal/service" - serviceDatastore "github.com/Golerplate/user-store-svc/internal/service/datastore/planetscale" + service "github.com/Golerplate/user-store-svc/internal/service/v1" ) func main() { @@ -28,7 +28,11 @@ func main() { zerolog.SetGlobalLevel(zerolog.InfoLevel) userStoreServiceDatastore := serviceDatastore.NewPlanetScaleDatastore() - userStoreService := service.NewUserStoreService(userStoreServiceDatastore) + userStoreService, err := service.NewUserStoreService(ctx, userStoreServiceDatastore) + if err != nil { + log.Fatal().Err(err). + Msg("main: unable to create user store service") + } grpcServer, err := handlers_grpc.NewServer(ctx, cfg.GRPCServerConfig, userStoreService) if err != nil { diff --git a/src/go.mod b/src/go.mod index 3768dfb..e3d39bf 100644 --- a/src/go.mod +++ b/src/go.mod @@ -3,8 +3,6 @@ module github.com/Golerplate/user-store-svc go 1.21.5 require ( - github.com/Golerplate/contracts v0.0.2 - github.com/Golerplate/pkg v0.0.2 github.com/bufbuild/connect-go v1.10.0 github.com/bufbuild/connect-grpcreflect-go v1.1.0 github.com/caarlos0/env/v8 v8.0.0 @@ -16,9 +14,20 @@ require ( ) require ( + github.com/Golerplate/pkg v0.0.7 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/oklog/ulid/v2 v2.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +require ( + github.com/Golerplate/contracts v0.0.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/stretchr/testify v1.8.4 + go.uber.org/mock v0.4.0 golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect ) diff --git a/src/go.sum b/src/go.sum index 7d752bb..c4880c0 100644 --- a/src/go.sum +++ b/src/go.sum @@ -1,7 +1,11 @@ github.com/Golerplate/contracts v0.0.2 h1:nII6q/QV2QjeTYw4g21G8eT2lzIA6ZXGFHKGQkGiL2k= github.com/Golerplate/contracts v0.0.2/go.mod h1:ALtjMgMcSLE6wGcB2zGIWand81y0HsU+MIvn1mmBP+0= +github.com/Golerplate/contracts v0.0.6 h1:nyi3f+VOe8KBq8tNpesGApxxDn09AU8XVnoSzlc/k5E= +github.com/Golerplate/contracts v0.0.6/go.mod h1:Oe4DvVdK81pPH9sAMmJLw0wd3k8HhmuqHAG1aC3x4Zo= github.com/Golerplate/pkg v0.0.2 h1:b1T2Rky4BaJ5c9bHeh0cVII8M1LWcvKfzDJkGmT/G5w= github.com/Golerplate/pkg v0.0.2/go.mod h1:xj+tuGKV3MtOpy/B6SMBJ0EkbaXMaivufhce/SzwqRk= +github.com/Golerplate/pkg v0.0.7 h1:RBF4dgVcBhKTAWUOQeJZPC7/10UpoFXB9q5F/aYk/oQ= +github.com/Golerplate/pkg v0.0.7/go.mod h1:CGbdv/CDLgQnQJau3oHJHu3cdA4U2yZR1T0zJ4tbyBQ= github.com/bufbuild/connect-go v1.10.0 h1:QAJ3G9A1OYQW2Jbk3DeoJbkCxuKArrvZgDt47mjdTbg= github.com/bufbuild/connect-go v1.10.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8= github.com/bufbuild/connect-grpcreflect-go v1.1.0 h1:T0FKu1y9zZW4cjHuF+Q7jIN6ek8HTpCxOP8ZsORZICg= @@ -9,6 +13,8 @@ github.com/bufbuild/connect-grpcreflect-go v1.1.0/go.mod h1:AxcY2fSAr+oQQuu+K35q github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0= github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -24,11 +30,20 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU= +github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ= +github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -43,3 +58,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/internal/service/datastore/interface.go b/src/internal/datastore/interface.go similarity index 100% rename from src/internal/service/datastore/interface.go rename to src/internal/datastore/interface.go diff --git a/src/internal/service/datastore/planetscale/init.go b/src/internal/datastore/planetscale/init.go similarity index 73% rename from src/internal/service/datastore/planetscale/init.go rename to src/internal/datastore/planetscale/init.go index 6f28e0a..f4c2f07 100644 --- a/src/internal/service/datastore/planetscale/init.go +++ b/src/internal/datastore/planetscale/init.go @@ -1,7 +1,7 @@ package planetscale import ( - "github.com/Golerplate/user-store-svc/internal/service/datastore" + "github.com/Golerplate/user-store-svc/internal/datastore" _ "github.com/go-sql-driver/mysql" ) diff --git a/src/internal/service/datastore/planetscale/user.go b/src/internal/datastore/planetscale/user.go similarity index 55% rename from src/internal/service/datastore/planetscale/user.go rename to src/internal/datastore/planetscale/user.go index 0b300c9..0e6cea1 100644 --- a/src/internal/service/datastore/planetscale/user.go +++ b/src/internal/datastore/planetscale/user.go @@ -2,10 +2,19 @@ package planetscale import ( "context" + "time" entities_user_v1 "github.com/Golerplate/user-store-svc/internal/entities/user/v1" ) func (d *dbClient) CreateUser(ctx context.Context, req *entities_user_v1.CreateUserRequest) (*entities_user_v1.User, error) { - return nil, nil + return &entities_user_v1.User{ + ID: "1", + Username: req.Username, + Email: req.Email, + IsAdmin: false, + IsBanned: false, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + }, nil } diff --git a/src/internal/handlers/grpc/server.go b/src/internal/handlers/grpc/server.go index 66c6a7d..4162c0a 100644 --- a/src/internal/handlers/grpc/server.go +++ b/src/internal/handlers/grpc/server.go @@ -6,13 +6,13 @@ import ( "net/http" "github.com/Golerplate/contracts/generated/services/servicesconnect" - "github.com/Golerplate/contracts/generated/services/user/store/v1/storev1connect" + "github.com/Golerplate/contracts/generated/services/user/store/svc/v1/svcv1connect" "github.com/Golerplate/pkg/grpc" pkghandlers "github.com/Golerplate/pkg/grpc/handlers" sharedmidlewares "github.com/Golerplate/pkg/grpc/interceptors" "github.com/Golerplate/user-store-svc/internal/handlers" handlers_grpc_user_v1 "github.com/Golerplate/user-store-svc/internal/handlers/grpc/user/v1" - "github.com/Golerplate/user-store-svc/internal/service" + service "github.com/Golerplate/user-store-svc/internal/service/v1" connectgo "github.com/bufbuild/connect-go" grpcreflect "github.com/bufbuild/connect-grpcreflect-go" "github.com/rs/zerolog/log" @@ -47,7 +47,7 @@ func (s *grpcServer) Setup(ctx context.Context) error { mux := http.NewServeMux() mux.Handle(servicesconnect.NewHealthServiceHandler(pkghandlers.NewHealthHandler())) - mux.Handle(storev1connect.NewUserStoreSvcHandler(userStoreServiceHandler, interceptors)) + mux.Handle(svcv1connect.NewUserStoreSvcHandler(userStoreServiceHandler, interceptors)) mux.Handle(grpcreflect.NewHandlerV1(reflector)) mux.Handle(grpcreflect.NewHandlerV1Alpha(reflector)) diff --git a/src/internal/handlers/grpc/user/v1/init.go b/src/internal/handlers/grpc/user/v1/init.go index a147ffc..793e542 100644 --- a/src/internal/handlers/grpc/user/v1/init.go +++ b/src/internal/handlers/grpc/user/v1/init.go @@ -1,15 +1,15 @@ package handlers_grpc_user_v1 import ( - "github.com/Golerplate/contracts/generated/services/user/store/v1/storev1connect" - "github.com/Golerplate/user-store-svc/internal/service" + "github.com/Golerplate/contracts/generated/services/user/store/svc/v1/svcv1connect" + service_v1 "github.com/Golerplate/user-store-svc/internal/service/v1" ) type handler struct { - userStoreService service.UserStoreService + userStoreService service_v1.UserStoreService } -func NewUserStoreServiceHandler(userStoreService service.UserStoreService) storev1connect.UserStoreSvcHandler { +func NewUserStoreServiceHandler(userStoreService service_v1.UserStoreService) svcv1connect.UserStoreSvcHandler { return &handler{ userStoreService: userStoreService, } diff --git a/src/internal/handlers/grpc/user/v1/user.go b/src/internal/handlers/grpc/user/v1/user.go index 0bc22c1..c2861a1 100644 --- a/src/internal/handlers/grpc/user/v1/user.go +++ b/src/internal/handlers/grpc/user/v1/user.go @@ -4,7 +4,7 @@ import ( "context" "errors" - userv1 "github.com/Golerplate/contracts/generated/services/user/store/v1" + userv1 "github.com/Golerplate/contracts/generated/services/user/store/svc/v1" "github.com/Golerplate/pkg/grpc" entities_user_v1 "github.com/Golerplate/user-store-svc/internal/entities/user/v1" connectgo "github.com/bufbuild/connect-go" @@ -13,7 +13,6 @@ import ( ) func (h *handler) CreateUser(ctx context.Context, c *connectgo.Request[userv1.CreateUserRequest]) (*connectgo.Response[userv1.CreateUserResponse], error) { - if c.Msg.GetUsername() == nil || c.Msg.GetUsername().GetValue() == "" { return nil, connectgo.NewError(connectgo.CodeInvalidArgument, errors.New("invalid username")) } @@ -45,3 +44,72 @@ func (h *handler) CreateUser(ctx context.Context, c *connectgo.Request[userv1.Cr }, }), nil } + +func (h *handler) GetUserByEmail(ctx context.Context, c *connectgo.Request[userv1.GetUserByEmailRequest]) (*connectgo.Response[userv1.GetUserByEmailResponse], error) { + if c.Msg.GetEmail() == nil || c.Msg.GetEmail().GetValue() == "" { + return nil, connectgo.NewError(connectgo.CodeInvalidArgument, errors.New("invalid email")) + } + + user, err := h.userStoreService.GetUserByEmail(ctx, c.Msg.GetEmail().GetValue()) + if err != nil { + return nil, grpc.TranslateToGRPCError(ctx, err) + } + + return connectgo.NewResponse(&userv1.GetUserByEmailResponse{ + User: &userv1.User{ + Id: &wrappers.StringValue{Value: user.ID}, + Username: &wrappers.StringValue{Value: user.Username}, + Email: &wrappers.StringValue{Value: user.Email}, + IsAdmin: &wrappers.BoolValue{Value: user.IsAdmin}, + IsBanned: &wrappers.BoolValue{Value: user.IsBanned}, + CreatedAt: ×tamppb.Timestamp{Seconds: int64(user.CreatedAt.Second()), Nanos: int32(user.CreatedAt.Nanosecond())}, + UpdatedAt: ×tamppb.Timestamp{Seconds: int64(user.UpdatedAt.Second()), Nanos: int32(user.UpdatedAt.Nanosecond())}, + }, + }), nil +} + +func (h *handler) GetUserByID(ctx context.Context, c *connectgo.Request[userv1.GetUserByIDRequest]) (*connectgo.Response[userv1.GetUserByIDResponse], error) { + if c.Msg.GetId() == nil || c.Msg.GetId().GetValue() == "" { + return nil, connectgo.NewError(connectgo.CodeInvalidArgument, errors.New("invalid id")) + } + + user, err := h.userStoreService.GetUserByID(ctx, c.Msg.GetId().GetValue()) + if err != nil { + return nil, grpc.TranslateToGRPCError(ctx, err) + } + + return connectgo.NewResponse(&userv1.GetUserByIDResponse{ + User: &userv1.User{ + Id: &wrappers.StringValue{Value: user.ID}, + Username: &wrappers.StringValue{Value: user.Username}, + Email: &wrappers.StringValue{Value: user.Email}, + IsAdmin: &wrappers.BoolValue{Value: user.IsAdmin}, + IsBanned: &wrappers.BoolValue{Value: user.IsBanned}, + CreatedAt: ×tamppb.Timestamp{Seconds: int64(user.CreatedAt.Second()), Nanos: int32(user.CreatedAt.Nanosecond())}, + UpdatedAt: ×tamppb.Timestamp{Seconds: int64(user.UpdatedAt.Second()), Nanos: int32(user.UpdatedAt.Nanosecond())}, + }, + }), nil +} + +func (h *handler) GetUserByUsername(ctx context.Context, c *connectgo.Request[userv1.GetUserByUsernameRequest]) (*connectgo.Response[userv1.GetUserByUsernameResponse], error) { + if c.Msg.GetUsername() == nil || c.Msg.GetUsername().GetValue() == "" { + return nil, connectgo.NewError(connectgo.CodeInvalidArgument, errors.New("invalid username")) + } + + user, err := h.userStoreService.GetUserByUsername(ctx, c.Msg.GetUsername().GetValue()) + if err != nil { + return nil, grpc.TranslateToGRPCError(ctx, err) + } + + return connectgo.NewResponse(&userv1.GetUserByUsernameResponse{ + User: &userv1.User{ + Id: &wrappers.StringValue{Value: user.ID}, + Username: &wrappers.StringValue{Value: user.Username}, + Email: &wrappers.StringValue{Value: user.Email}, + IsAdmin: &wrappers.BoolValue{Value: user.IsAdmin}, + IsBanned: &wrappers.BoolValue{Value: user.IsBanned}, + CreatedAt: ×tamppb.Timestamp{Seconds: int64(user.CreatedAt.Second()), Nanos: int32(user.CreatedAt.Nanosecond())}, + UpdatedAt: ×tamppb.Timestamp{Seconds: int64(user.UpdatedAt.Second()), Nanos: int32(user.UpdatedAt.Nanosecond())}, + }, + }), nil +} diff --git a/src/internal/handlers/grpc/user/v1/user_test.go b/src/internal/handlers/grpc/user/v1/user_test.go index cb62226..792c755 100644 --- a/src/internal/handlers/grpc/user/v1/user_test.go +++ b/src/internal/handlers/grpc/user/v1/user_test.go @@ -1 +1,60 @@ package handlers_grpc_user_v1 + +import ( + "context" + "testing" + "time" + + user_store_svc_v1_entities "github.com/Golerplate/contracts/clients/user-store-svc/v1/entities" + user_store_svc_v1_mocks "github.com/Golerplate/contracts/clients/user-store-svc/v1/mocks" + "github.com/Golerplate/pkg/constants" + "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" + + entities_user_v1 "github.com/Golerplate/user-store-svc/internal/entities/user/v1" + service_v1 "github.com/Golerplate/user-store-svc/internal/service/v1" +) + +func Test_CreateUser(t *testing.T) { + t.Run("ok - username", func(t *testing.T) { + ctrl := gomock.NewController(t) + m := user_store_svc_v1_mocks.NewMockUserStoreSvc(ctrl) + + userid := constants.GenerateDataPrefixWithULID(constants.User) + created := time.Now() + + m.EXPECT().CreateUser(gomock.Any(), &entities_user_v1.CreateUserRequest{ + Username: "testuser", + Email: "testuser@test.com", + Password: "123", + }).Return(&user_store_svc_v1_entities.User{ + ID: userid, + Username: "testuser", + Email: "testuser@test.com", + IsAdmin: false, + IsBanned: false, + CreatedAt: created, + UpdatedAt: created, + }, nil) + + s, err := service_v1.NewUserStoreService(context.Background(), m) + assert.NotNil(t, s) + assert.NoError(t, err) + + user, err := s.CreateUser(context.Background(), &entities_user_v1.CreateUserRequest{ + Username: "testuser", + Email: "testuser@test.com", + Password: "123", + }) + assert.NotNil(t, user) + assert.NoError(t, err) + + assert.EqualValues(t, &entities_user_v1.User{ + ID: userid, + Username: "testuser", + Email: "testuser@test.com", + CreatedAt: created, + UpdatedAt: created, + }, user) + }) +} diff --git a/src/internal/service/init.go b/src/internal/service/init.go deleted file mode 100644 index d3588e8..0000000 --- a/src/internal/service/init.go +++ /dev/null @@ -1,13 +0,0 @@ -package service - -import "github.com/Golerplate/user-store-svc/internal/service/datastore" - -type service struct { - store datastore.UserStoreServiceDatastore -} - -func NewUserStoreService(store datastore.UserStoreServiceDatastore) UserStoreService { - return &service{ - store: store, - } -} diff --git a/src/internal/service/v1/init.go b/src/internal/service/v1/init.go new file mode 100644 index 0000000..c5baa4c --- /dev/null +++ b/src/internal/service/v1/init.go @@ -0,0 +1,17 @@ +package service_v1 + +import ( + "context" + + "github.com/Golerplate/user-store-svc/internal/datastore" +) + +type service struct { + store datastore.UserStoreServiceDatastore +} + +func NewUserStoreService(ctx context.Context, store datastore.UserStoreServiceDatastore) (*service, error) { + return &service{ + store: store, + }, nil +} diff --git a/src/internal/service/interface.go b/src/internal/service/v1/interface.go similarity index 92% rename from src/internal/service/interface.go rename to src/internal/service/v1/interface.go index 3a8c720..ebe494b 100644 --- a/src/internal/service/interface.go +++ b/src/internal/service/v1/interface.go @@ -1,4 +1,4 @@ -package service +package service_v1 import ( "context" diff --git a/src/internal/service/user.go b/src/internal/service/v1/user.go similarity index 93% rename from src/internal/service/user.go rename to src/internal/service/v1/user.go index 9f11b1e..11686b4 100644 --- a/src/internal/service/user.go +++ b/src/internal/service/v1/user.go @@ -1,4 +1,4 @@ -package service +package service_v1 import ( "context"