Skip to content

Commit

Permalink
implement login usecase (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
KathurimaKimathi committed Sep 27, 2021
1 parent 7c5110e commit cf2039a
Show file tree
Hide file tree
Showing 11 changed files with 2,381 additions and 13 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ require (
github.com/google/uuid v1.2.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/imroc/req v0.3.0
github.com/savannahghi/converterandformatter v0.0.9
github.com/savannahghi/enumutils v0.0.3
github.com/savannahghi/feedlib v0.0.4
github.com/savannahghi/firebasetools v0.0.15
github.com/savannahghi/interserviceclient v0.0.13
github.com/savannahghi/onboarding v0.0.21
github.com/savannahghi/onboarding v0.0.22
github.com/savannahghi/profileutils v0.0.17
github.com/savannahghi/scalarutils v0.0.4
github.com/savannahghi/serverutils v0.0.6
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/tj/assert v0.0.3
github.com/vektah/gqlparser/v2 v2.1.0
go.opencensus.io v0.23.0
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.21.0
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,8 @@ github.com/savannahghi/firebasetools v0.0.15 h1:/i/VyddxLmBO1Fn4W1rcj6nKUut2x+mg
github.com/savannahghi/firebasetools v0.0.15/go.mod h1:2Qhj483I+CiKzObf+T3cKhf1YYsEQWz8e+KPE+6LyBk=
github.com/savannahghi/interserviceclient v0.0.13 h1:hKUrWkUQW7mNZLp/wxJNnzORDpNjuQ8wzstI25F6mLQ=
github.com/savannahghi/interserviceclient v0.0.13/go.mod h1:aGGEc+40bBVHVDs1k0CzK5uPb5080vv4fb25T/cuXQk=
github.com/savannahghi/onboarding v0.0.18 h1:eepnWjXLnQdc5hAL6pEq//c1nQrSUHRvmtwB68EBjKs=
github.com/savannahghi/onboarding v0.0.18/go.mod h1:kn+yrdfhjgeCmzs9AfP9+cVJWi3kfmgj/kn7pNor0xY=
github.com/savannahghi/onboarding v0.0.21 h1:FHM18w57WlXud9HibzbcRvfQc7y7sBqQ7tO3uIiKeLM=
github.com/savannahghi/onboarding v0.0.21/go.mod h1:kn+yrdfhjgeCmzs9AfP9+cVJWi3kfmgj/kn7pNor0xY=
github.com/savannahghi/onboarding v0.0.22 h1:s+hWsMUyGA72W/E8DewI6xnNHqgbnOp6rt71fYnQRC4=
github.com/savannahghi/onboarding v0.0.22/go.mod h1:kn+yrdfhjgeCmzs9AfP9+cVJWi3kfmgj/kn7pNor0xY=
github.com/savannahghi/profileutils v0.0.6/go.mod h1:Ct0sjzOW9zjDN58ynT5GTV6M2hHMY3nsFDV08I6gpO4=
github.com/savannahghi/profileutils v0.0.17 h1:Zgk3n+ZtgQjI8vLTde4/c2U/t/Zh+q9jXZqVRL5ptRg=
github.com/savannahghi/profileutils v0.0.17/go.mod h1:Sq/2fK2iVntGqwC0EFe5SED0+AkdOrxp7gra9KmWPQQ=
Expand Down Expand Up @@ -417,6 +415,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 h1:5u+EJUQiosu3JFX0XS0qTf5FznsMOzTjGqavBGuCbo0=
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2/go.mod h1:4kyMkleCiLkgY6z8gK5BkI01ChBtxR0ro3I1ZDcGM3w=
github.com/ttacon/libphonenumber v1.2.1 h1:fzOfY5zUADkCkbIafAed11gL1sW+bJ26p6zWLBMElR4=
Expand Down Expand Up @@ -885,6 +885,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
2 changes: 2 additions & 0 deletions pkg/onboarding/presentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ func Router(ctx context.Context) (*mux.Router, error) {
openSourceUsecases := osusecases.NewUsecasesInteractor(infrastructure, baseExt, pinExt)

var signupUsecase usecases.UseCaseSignUp
var loginUsecase usecases.UseCaseLogin

// Initialize the interactor
i, err := interactor.NewOnboardingInteractor(
infrastructure,
openSourceUsecases,
signupUsecase,
loginUsecase,
)
if err != nil {
return nil, fmt.Errorf("can't instantiate service : %w", err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/onboarding/presentation/interactor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ type Interactor struct {
OpenSourceInfra infrastructure.Infrastructure
OpenSourceUsecases libOnboardingUsecase.Interactor
SignUpUseCase usecases.UseCaseSignUp
LoginUseCase usecases.UseCaseLogin
}

// NewOnboardingInteractor returns a new onboarding interactor
func NewOnboardingInteractor(
openSourceInfra infrastructure.Infrastructure,
openSourceUsecases libOnboardingUsecase.Interactor,
signupUsecase usecases.UseCaseSignUp,
loginUseCase usecases.UseCaseLogin,
) (*Interactor, error) {
return &Interactor{
OpenSourceInfra: openSourceInfra,
OpenSourceUsecases: openSourceUsecases,
SignUpUseCase: signupUsecase,
LoginUseCase: loginUseCase,
}, nil
}
6 changes: 0 additions & 6 deletions pkg/onboarding/usecases/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func TestMain(m *testing.M) {
func CreateOrLoginTestUserByPhone(t *testing.T) (*auth.Token, error) {
ctx := context.Background()
i, err := InitializeTestService(ctx)
fmt.Printf("43: THE ERROR IS: %v\n", err)
if err != nil {
return nil, fmt.Errorf("unable to initialize test service")
}
Expand All @@ -131,8 +130,6 @@ func CreateOrLoginTestUserByPhone(t *testing.T) (*auth.Token, error) {
pin := interserviceclient.TestUserPin
testAppID := uuid.New().String()
otp, err := i.VerifyPhoneNumber(ctx, phone, &testAppID)
fmt.Printf("52: THE OTP IS: %v\n", otp)
fmt.Printf("53: THE ERROR IS: %v\n", err)
if err != nil {
if strings.Contains(err.Error(), exceptions.CheckPhoneNumberExistError().Error()) {
logInCreds, err := i.LoginByPhone(
Expand All @@ -141,7 +138,6 @@ func CreateOrLoginTestUserByPhone(t *testing.T) (*auth.Token, error) {
interserviceclient.TestUserPin,
flavour,
)
fmt.Printf("62: THE ERROR IS: %v\n", err)
if err != nil {
return nil, fmt.Errorf("failed to log in test user: %v", err)
}
Expand All @@ -163,7 +159,6 @@ func CreateOrLoginTestUserByPhone(t *testing.T) (*auth.Token, error) {
OTP: &otp.OTP,
},
)
fmt.Printf("84: THE ERROR IS: %v\n", err)
if err != nil {
return nil, fmt.Errorf("failed to create a test user: %v", err)
}
Expand All @@ -180,7 +175,6 @@ func CreateOrLoginTestUserByPhone(t *testing.T) (*auth.Token, error) {
func GetTestAuthenticatedContext(t *testing.T) (context.Context, *auth.Token, error) {
ctx := context.Background()
auth, err := CreateOrLoginTestUserByPhone(t)
fmt.Printf("99: THE ERROR IS: %v\n", err)
if err != nil {
return nil, nil, err
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/onboarding/usecases/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package usecases

import (
"github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure"
libLoginUsecase "github.com/savannahghi/onboarding/pkg/onboarding/usecases"
)

// UseCaseLogin represents open source login usecases
type UseCaseLogin interface {
libLoginUsecase.LoginUseCases
}

// UseCaseLoginImpl is the login usecase implementation
type UseCaseLoginImpl struct {
infrastructure infrastructure.Interactor
}

// NewUseCaseLogin instantiates login usecases
func NewUseCaseLogin(
infrastructure infrastructure.Interactor,
) *UseCaseLoginImpl {
return &UseCaseLoginImpl{
infrastructure: infrastructure,
}
}

0 comments on commit cf2039a

Please sign in to comment.