Compare commits

..
Author SHA1 Message Date
phoenix 3ccc1a9a6d UserProfile (#1)
Go Release / build-and-release (push) Successful in 5s
Go CI / Test and Lint (push) Successful in 6s
Reviewed-on: phoenix/textsender-models#1
2026-05-27 22:59:45 -04:00
4 changed files with 35 additions and 21 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ jobs:
run: | run: |
echo "Creating version" echo "Creating version"
VERSION="0.2.2" VERSION="0.2.3"
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10) PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
BRANCH_REF="${{ gitea.ref }}" BRANCH_REF="${{ gitea.ref }}"
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3) BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
+10 -8
View File
@@ -7,12 +7,14 @@ import (
) )
type User struct { type User struct {
Id uuid.UUID `json:"id"` Id uuid.UUID `json:"id"`
PhoneNumber string `json:"phone_number"` PhoneNumber string `json:"phone_number"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
Firstname *string `json:"first_name,omitempty"` // Firstname is a pointer
Lastname *string `json:"last_name,omitempty"` Firstname *string `json:"first_name,omitempty"`
Created time.Time `json:"created"` // Lastname is a pointer
LastLogin *time.Time `json:"last_login,omitempty"` Lastname *string `json:"last_name,omitempty"`
Created time.Time `json:"created"`
LastLogin *time.Time `json:"last_login,omitempty"`
} }
+24 -10
View File
@@ -2,11 +2,19 @@ package user
import ( import (
"fmt" "fmt"
"time"
"github.com/google/uuid"
) )
// TODO: Replace Usr with all the fields from User, except Password and other sensitive fields
type UserProfile struct { type UserProfile struct {
Usr *User `json:"user"` UserId uuid.UUID `json:"user_id"`
PhoneNumber string `json:"phone_number"`
Username string `json:"username"`
Firstname *string `json:"firstname,omitempty"`
Lastname *string `json:"lastname,omitempty"`
Created time.Time `json:"created"`
LastLogin *time.Time `json:"last_login,omitempty"`
} }
func InitUserProfile(usr *User) (usrProfile *UserProfile, err error) { func InitUserProfile(usr *User) (usrProfile *UserProfile, err error) {
@@ -14,14 +22,20 @@ func InitUserProfile(usr *User) (usrProfile *UserProfile, err error) {
return nil, fmt.Errorf("User is empty") return nil, fmt.Errorf("User is empty")
} else { } else {
usrProfile = new(UserProfile) usrProfile = new(UserProfile)
if len(usr.Password) > 0 { usrProfile.UserId = usr.Id
newUsr := User{Id: usr.Id, PhoneNumber: usr.PhoneNumber, Username: usr.Username, Firstname: usr.Firstname, Lastname: usr.Lastname, Created: usr.Created, LastLogin: usr.LastLogin} usrProfile.PhoneNumber = usr.PhoneNumber
usrProfile.Usr = &newUsr usrProfile.Username = usr.Username
if usr.Firstname != nil {
return usrProfile, nil usrProfile.Firstname = usr.Firstname
} else {
usrProfile.Usr = usr
return usrProfile, nil
} }
if usr.Lastname != nil {
usrProfile.Lastname = usr.Lastname
}
usrProfile.Created = usr.Created
if usr.LastLogin != nil {
usrProfile.LastLogin = usr.LastLogin
}
return usrProfile, nil
} }
} }
-2
View File
@@ -13,6 +13,4 @@ func TestInitUserProfile(t *testing.T) {
assert.NoError(t, err, "Error %v", err) assert.NoError(t, err, "Error %v", err)
assert.NotEmpty(t, profile, "UserProfile is empty") assert.NotEmpty(t, profile, "UserProfile is empty")
assert.Empty(t, profile.Usr.Password, "Password should be empty")
} }