Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
446583d705
|
||
|
|
8544a69eb1
|
||
|
|
894e1387de
|
||
|
|
6f90428975
|
||
|
|
c3ec0731b2
|
||
|
|
413d9baffd
|
||
|
|
87a437311b
|
@@ -11,7 +11,9 @@ type User struct {
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
// Firstname is a pointer
|
||||
Firstname *string `json:"first_name,omitempty"`
|
||||
// Lastname is a pointer
|
||||
Lastname *string `json:"last_name,omitempty"`
|
||||
Created time.Time `json:"created"`
|
||||
LastLogin *time.Time `json:"last_login,omitempty"`
|
||||
|
||||
+10
-13
@@ -7,13 +7,13 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TODO: Replace Usr with all the fields from User, except Password and other sensitive fields
|
||||
|
||||
type UserProfile struct {
|
||||
UserId uuid.UUID `json:"user_id"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
Username string `json:"username"`
|
||||
Firstname string `json:"firstname"`
|
||||
Lastname string `json:"lastname"`
|
||||
Firstname *string `json:"firstname,omitempty"`
|
||||
Lastname *string `json:"lastname,omitempty"`
|
||||
Created time.Time `json:"created"`
|
||||
LastLogin *time.Time `json:"last_login,omitempty"`
|
||||
}
|
||||
@@ -22,24 +22,21 @@ func InitUserProfile(usr *User) (usrProfile *UserProfile, err error) {
|
||||
if usr == nil {
|
||||
return nil, fmt.Errorf("User is empty")
|
||||
} else {
|
||||
usrProfile = new(UserProfile)
|
||||
if len(usr.Password) > 0 {
|
||||
// newUsr := User{Id: usr.Id, PhoneNumber: usr.PhoneNumber, Username: usr.Username, Firstname: usr.Firstname, Lastname: usr.Lastname, Created: usr.Created, LastLogin: usr.LastLogin}
|
||||
// usrProfile.Usr = &newUsr
|
||||
usrProfile = new(UserProfile)
|
||||
usrProfile.UserId = usr.Id
|
||||
usrProfile.PhoneNumber = usr.PhoneNumber
|
||||
usrProfile.Username = usr.Username
|
||||
usrProfile.Firstname = *usr.Firstname
|
||||
usrProfile.Lastname = *usr.Lastname
|
||||
if usr.Firstname != nil {
|
||||
usrProfile.Firstname = usr.Firstname
|
||||
}
|
||||
if usr.Lastname != nil {
|
||||
usrProfile.Lastname = usr.Lastname
|
||||
}
|
||||
usrProfile.Created = usr.Created
|
||||
if usr.LastLogin != nil {
|
||||
usrProfile.LastLogin = usr.LastLogin
|
||||
}
|
||||
|
||||
return usrProfile, nil
|
||||
} else {
|
||||
usrProfile.Usr = usr
|
||||
return usrProfile, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,4 @@ func TestInitUserProfile(t *testing.T) {
|
||||
|
||||
assert.NoError(t, err, "Error %v", err)
|
||||
assert.NotEmpty(t, profile, "UserProfile is empty")
|
||||
|
||||
assert.Empty(t, profile.Usr.Password, "Password should be empty")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user