From afe6f4e9a6c60ab1cd77e25d7159656514a48446 Mon Sep 17 00:00:00 2001 From: ericprd Date: Mon, 3 Mar 2025 10:39:01 +0800 Subject: [PATCH] fix: change username to name and add profile pic to staff --- database/staff_model.go | 13 +++++++------ internal/domain/auth/login.go | 7 ++++--- internal/domain/auth/register.go | 18 ++++++++++-------- internal/services/auth/get_staff.go | 7 ++++--- internal/services/auth/register_staff.go | 9 +++++---- openapi.yml | 10 +++++++--- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/database/staff_model.go b/database/staff_model.go index cf8a8a2..cedc068 100644 --- a/database/staff_model.go +++ b/database/staff_model.go @@ -5,10 +5,11 @@ import ( ) type Staff struct { - ID string `gorm:"primaryKey" json:"id"` - Username string `gorm:"default:null;unique" json:"username"` - Email string `gorm:"unique;not null" json:"email"` - Password string `gorm:"not null" json:"password"` - CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"` - UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"` + ID string `gorm:"primaryKey" json:"id"` + Name string `gorm:"default:null;unique" json:"name"` + ProfilePicture string `gorm:"default:null" json:"profile_picture"` + Email string `gorm:"unique;not null" json:"email"` + Password string `gorm:"not null" json:"password"` + CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"` + UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"` } diff --git a/internal/domain/auth/login.go b/internal/domain/auth/login.go index d78ad40..4a01c0f 100644 --- a/internal/domain/auth/login.go +++ b/internal/domain/auth/login.go @@ -17,9 +17,10 @@ type LoginRepoResponse struct { } type StaffProfile struct { - ID string `json:"id"` - Email string `json:"email"` - Username string `json:"username"` + ID string `json:"id"` + Email string `json:"email"` + Name string `json:"name"` + ProfilePicture string `json:"profile_picture"` } type UserProfile struct { diff --git a/internal/domain/auth/register.go b/internal/domain/auth/register.go index 6306bfb..3bff804 100644 --- a/internal/domain/auth/register.go +++ b/internal/domain/auth/register.go @@ -16,20 +16,22 @@ type User struct { } type RegisterStaffReq struct { - Email string `json:"email" validate:"required"` - Password string `json:"password" validate:"required"` - Username string `json:"username" validate:"required"` + Email string `json:"email" validate:"required"` + Password string `json:"password" validate:"required"` + Name string `json:"name" validate:"required"` + ProfilePicture string `json:"profile_picture"` } type UpdateStaffReq struct { Email string `json:"email"` Password string `json:"password"` - Username string `json:"username"` + Name string `json:"name"` } type Staff struct { - ID string `json:"id"` - Email string `json:"email"` - Password string `json:"password"` - Username string `json:"username"` + ID string `json:"id"` + Email string `json:"email"` + Password string `json:"password"` + Name string `json:"name"` + ProfilePicture string `json:"profile_picture"` } diff --git a/internal/services/auth/get_staff.go b/internal/services/auth/get_staff.go index 5d0d58a..621a513 100644 --- a/internal/services/auth/get_staff.go +++ b/internal/services/auth/get_staff.go @@ -9,9 +9,10 @@ func (as *AuthSvc) GetStaffProfile(email string) (*authdomain.StaffProfile, erro } profile := &authdomain.StaffProfile{ - ID: staff.ID, - Username: staff.Username, - Email: staff.Email, + ID: staff.ID, + Name: staff.Name, + Email: staff.Email, + ProfilePicture: staff.ProfilePicture, } return profile, nil diff --git a/internal/services/auth/register_staff.go b/internal/services/auth/register_staff.go index 48380cc..b10757e 100644 --- a/internal/services/auth/register_staff.go +++ b/internal/services/auth/register_staff.go @@ -20,10 +20,11 @@ func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error } staff := authdomain.Staff{ - ID: uuid.NewString(), - Email: spec.Email, - Password: hashedPwd, - Username: spec.Username, + ID: uuid.NewString(), + Email: spec.Email, + Password: hashedPwd, + Name: spec.Name, + ProfilePicture: spec.ProfilePicture, } _, err = a.staffRepo.Create(&staff) diff --git a/openapi.yml b/openapi.yml index 0d159de..ae9ece5 100644 --- a/openapi.yml +++ b/openapi.yml @@ -25,7 +25,9 @@ paths: type: string email: type: string - username: + name: + type: string + profile_picture: type: string "400": description: Bad request @@ -108,12 +110,14 @@ paths: format: email password: type: string - username: + name: + type: string + profile_picture: type: string required: - email - password - - username + - name responses: "201": description: Staff member created