Skip to content

Commit

Permalink
fix(profile): exported GetProfileData
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi committed Apr 29, 2024
1 parent d32d55b commit bbfd007
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions auth_login_with_otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (a *Auth) LoginWithOTP(ctx context.Context, email, otp string) (Session, er
return noSession, ErrEmailNotFound
}

pd, err := a.getProfileData(ctx, a.db.On(u.ID), u.ID.Int64)
pd, err := a.GetProfileData(ctx, a.db.On(u.ID), u.ID.Int64)
if err != nil {
return noSession, err
}
Expand All @@ -36,7 +36,7 @@ func (a *Auth) LoginMobileWithOTP(ctx context.Context, mobile, otp string) (Sess
return noSession, ErrMobileNotFound
}

pd, err := a.getProfileData(ctx, a.db.On(u.ID), u.ID.Int64)
pd, err := a.GetProfileData(ctx, a.db.On(u.ID), u.ID.Int64)
if err != nil {
return noSession, err
}
Expand Down
4 changes: 2 additions & 2 deletions auth_login_with_otp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestLoginWithOTP(t *testing.T) {
u, err := authTest.CreateUser(context.Background(), UserStatusWaiting, "otp@sign_in_with_otp.com", "", "abc123", "", "")
r.NoError(err)

pd, err := authTest.getProfileData(context.Background(), authTest.db.On(u.ID), u.ID.Int64)
pd, err := authTest.GetProfileData(context.Background(), authTest.db.On(u.ID), u.ID.Int64)
r.NoError(err)

code, err := totp.GenerateCode(pd.TKey, time.Now())
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestLoginMobileWithOTP(t *testing.T) {
u, err := authTest.CreateUser(context.Background(), UserStatusActivated, "", "1+333444555", "abc123", "", "")
r.NoError(err)

pd, err := authTest.getProfileData(context.Background(), authTest.db.On(u.ID), u.ID.Int64)
pd, err := authTest.GetProfileData(context.Background(), authTest.db.On(u.ID), u.ID.Int64)
r.NoError(err)

code, err := totp.GenerateCode(pd.TKey, time.Now())
Expand Down
6 changes: 3 additions & 3 deletions auth_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (a *Auth) UpdateProfile(ctx context.Context, id int64, email, mobile string
uid := shardid.Parse(id)
dbUser := a.db.On(uid)

pd, err := a.getProfileData(ctx, dbUser, id)
pd, err := a.GetProfileData(ctx, dbUser, id)
if err != nil {
return err
}
Expand Down Expand Up @@ -241,14 +241,14 @@ func (a *Auth) deleteProfile(ctx context.Context, conn sqle.Connector, userID sh
return nil
}

// getProfileData retrieves the profile data for a given user ID.
// GetProfileData retrieves the profile data for a given user ID.
// It takes a context, a database connector, and the user ID as parameters.
// It returns the profile data as a ProfileData struct and an error if any.
// If the profile data is not found, it returns a default profile data and ErrProfileNotFound error.
// If there is an error accessing the database, it returns a default profile data and ErrBadDatabase error.
// If there is an error decrypting the profile data, it returns a default profile data and ErrUnknown error.
// If there is an error unmarshaling the profile data, it returns a default profile data and ErrUnknown error.
func (a *Auth) getProfileData(ctx context.Context, conn sqle.Connector, id int64) (ProfileData, error) {
func (a *Auth) GetProfileData(ctx context.Context, conn sqle.Connector, id int64) (ProfileData, error) {
var data string
err := conn.
QueryRowBuilder(ctx, a.createBuilder().
Expand Down
2 changes: 1 addition & 1 deletion auth_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (a *Auth) DeleteUser(ctx context.Context, id int64) error {

uid := shardid.Parse(id)
dbUser := a.db.On(uid)
pd, err := a.getProfileData(ctx, dbUser, id)
pd, err := a.GetProfileData(ctx, dbUser, id)
if err != nil {
return err
}
Expand Down

0 comments on commit bbfd007

Please sign in to comment.