fix: remove duplicate fields in User model
This commit is contained in:
parent
948858eca0
commit
ff17eb2e4c
1 changed files with 105 additions and 109 deletions
|
|
@ -1,109 +1,105 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// User represents a system user (SuperAdmin, CompanyAdmin, Recruiter, or JobSeeker)
|
// User represents a system user (SuperAdmin, CompanyAdmin, Recruiter, or JobSeeker)
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string `json:"id" db:"id"`
|
ID string `json:"id" db:"id"`
|
||||||
Identifier string `json:"identifier" db:"identifier"`
|
Identifier string `json:"identifier" db:"identifier"`
|
||||||
PasswordHash string `json:"-" db:"password_hash"` // Never expose password hash in JSON
|
PasswordHash string `json:"-" db:"password_hash"` // Never expose password hash in JSON
|
||||||
Role string `json:"role" db:"role"` // superadmin, admin, recruiter, candidate
|
Role string `json:"role" db:"role"` // superadmin, admin, recruiter, candidate
|
||||||
|
|
||||||
// Personal Info
|
// Personal Info
|
||||||
FullName string `json:"fullName" db:"full_name"`
|
FullName string `json:"fullName" db:"full_name"`
|
||||||
Phone *string `json:"phone,omitempty" db:"phone"`
|
Phone *string `json:"phone,omitempty" db:"phone"`
|
||||||
LineID *string `json:"lineId,omitempty" db:"line_id"`
|
LineID *string `json:"lineId,omitempty" db:"line_id"`
|
||||||
WhatsApp *string `json:"whatsapp,omitempty" db:"whatsapp"`
|
WhatsApp *string `json:"whatsapp,omitempty" db:"whatsapp"`
|
||||||
Instagram *string `json:"instagram,omitempty" db:"instagram"`
|
Instagram *string `json:"instagram,omitempty" db:"instagram"`
|
||||||
|
|
||||||
// Candidate Profile Info
|
// Candidate Profile Info
|
||||||
BirthDate *time.Time `json:"birthDate,omitempty" db:"birth_date"`
|
BirthDate *time.Time `json:"birthDate,omitempty" db:"birth_date"`
|
||||||
Address *string `json:"address,omitempty" db:"address"`
|
Address *string `json:"address,omitempty" db:"address"`
|
||||||
City *string `json:"city,omitempty" db:"city"`
|
City *string `json:"city,omitempty" db:"city"`
|
||||||
State *string `json:"state,omitempty" db:"state"`
|
State *string `json:"state,omitempty" db:"state"`
|
||||||
ZipCode *string `json:"zipCode,omitempty" db:"zip_code"`
|
ZipCode *string `json:"zipCode,omitempty" db:"zip_code"`
|
||||||
Education *string `json:"education,omitempty" db:"education"`
|
Objective *string `json:"objective,omitempty" db:"objective"`
|
||||||
Experience *string `json:"experience,omitempty" db:"experience"`
|
Title *string `json:"title,omitempty" db:"title"`
|
||||||
Skills []string `json:"skills,omitempty" db:"skills"`
|
AvatarURL *string `json:"avatarUrl,omitempty" db:"avatar_url"`
|
||||||
Objective *string `json:"objective,omitempty" db:"objective"`
|
|
||||||
Title *string `json:"title,omitempty" db:"title"`
|
// Profile (JSONB fields)
|
||||||
Bio *string `json:"bio,omitempty" db:"bio"`
|
Bio *string `json:"bio,omitempty" db:"bio"`
|
||||||
AvatarURL *string `json:"avatarUrl,omitempty" db:"avatar_url"`
|
ProfilePictureURL *string `json:"profilePictureUrl,omitempty" db:"profile_picture_url"`
|
||||||
|
Skills []byte `json:"skills,omitempty" db:"skills"` // JSONB
|
||||||
// Settings
|
Experience []byte `json:"experience,omitempty" db:"experience"` // JSONB
|
||||||
Language string `json:"language" db:"language"` // pt, en, es, ja
|
Education []byte `json:"education,omitempty" db:"education"` // JSONB
|
||||||
Active bool `json:"active" db:"active"`
|
|
||||||
|
// Settings
|
||||||
// Metadata
|
Language string `json:"language" db:"language"` // pt, en, es, ja
|
||||||
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
Active bool `json:"active" db:"active"`
|
||||||
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
|
||||||
LastLoginAt *time.Time `json:"lastLoginAt,omitempty" db:"last_login_at"`
|
// Metadata
|
||||||
|
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
||||||
// Profile Profile
|
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
||||||
Bio *string `json:"bio,omitempty" db:"bio"`
|
LastLoginAt *time.Time `json:"lastLoginAt,omitempty" db:"last_login_at"`
|
||||||
ProfilePictureURL *string `json:"profilePictureUrl,omitempty" db:"profile_picture_url"`
|
}
|
||||||
Skills []byte `json:"skills,omitempty" db:"skills"` // JSONB
|
|
||||||
Experience []byte `json:"experience,omitempty" db:"experience"` // JSONB
|
// UserResponse is the public representation of a user (without sensitive data)
|
||||||
Education []byte `json:"education,omitempty" db:"education"` // JSONB
|
type UserResponse struct {
|
||||||
}
|
ID string `json:"id"`
|
||||||
|
Identifier string `json:"identifier"`
|
||||||
// UserResponse is the public representation of a user (without sensitive data)
|
Role string `json:"role"`
|
||||||
type UserResponse struct {
|
FullName string `json:"fullName"`
|
||||||
ID string `json:"id"`
|
Phone *string `json:"phone,omitempty"`
|
||||||
Identifier string `json:"identifier"`
|
LineID *string `json:"lineId,omitempty"`
|
||||||
Role string `json:"role"`
|
WhatsApp *string `json:"whatsapp,omitempty"`
|
||||||
FullName string `json:"fullName"`
|
Instagram *string `json:"instagram,omitempty"`
|
||||||
Phone *string `json:"phone,omitempty"`
|
Language string `json:"language"`
|
||||||
LineID *string `json:"lineId,omitempty"`
|
Active bool `json:"active"`
|
||||||
WhatsApp *string `json:"whatsapp,omitempty"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
Instagram *string `json:"instagram,omitempty"`
|
LastLoginAt *time.Time `json:"lastLoginAt,omitempty"`
|
||||||
Language string `json:"language"`
|
Bio *string `json:"bio,omitempty"`
|
||||||
Active bool `json:"active"`
|
ProfilePictureURL *string `json:"profilePictureUrl,omitempty"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
Skills []string `json:"skills,omitempty"`
|
||||||
LastLoginAt *time.Time `json:"lastLoginAt,omitempty"`
|
Experience []any `json:"experience,omitempty"`
|
||||||
Bio *string `json:"bio,omitempty"`
|
Education []any `json:"education,omitempty"`
|
||||||
ProfilePictureURL *string `json:"profilePictureUrl,omitempty"`
|
}
|
||||||
Skills []string `json:"skills,omitempty"`
|
|
||||||
Experience []any `json:"experience,omitempty"`
|
// ToResponse converts User to UserResponse
|
||||||
Education []any `json:"education,omitempty"`
|
func (u *User) ToResponse() UserResponse {
|
||||||
}
|
// Helper to unmarshal JSONB
|
||||||
|
var skills []string
|
||||||
// ToResponse converts User to UserResponse
|
if len(u.Skills) > 0 {
|
||||||
func (u *User) ToResponse() UserResponse {
|
_ = json.Unmarshal(u.Skills, &skills)
|
||||||
// Helper to unmarshal JSONB
|
}
|
||||||
var skills []string
|
var experience []any
|
||||||
if len(u.Skills) > 0 {
|
if len(u.Experience) > 0 {
|
||||||
_ = json.Unmarshal(u.Skills, &skills)
|
_ = json.Unmarshal(u.Experience, &experience)
|
||||||
}
|
}
|
||||||
var experience []any
|
var education []any
|
||||||
if len(u.Experience) > 0 {
|
if len(u.Education) > 0 {
|
||||||
_ = json.Unmarshal(u.Experience, &experience)
|
_ = json.Unmarshal(u.Education, &education)
|
||||||
}
|
}
|
||||||
var education []any
|
|
||||||
if len(u.Education) > 0 {
|
return UserResponse{
|
||||||
_ = json.Unmarshal(u.Education, &education)
|
ID: u.ID,
|
||||||
}
|
Identifier: u.Identifier,
|
||||||
|
Role: u.Role,
|
||||||
return UserResponse{
|
FullName: u.FullName,
|
||||||
ID: u.ID,
|
Phone: u.Phone,
|
||||||
Identifier: u.Identifier,
|
LineID: u.LineID,
|
||||||
Role: u.Role,
|
WhatsApp: u.WhatsApp,
|
||||||
FullName: u.FullName,
|
Instagram: u.Instagram,
|
||||||
Phone: u.Phone,
|
Language: u.Language,
|
||||||
LineID: u.LineID,
|
Active: u.Active,
|
||||||
WhatsApp: u.WhatsApp,
|
CreatedAt: u.CreatedAt,
|
||||||
Instagram: u.Instagram,
|
LastLoginAt: u.LastLoginAt,
|
||||||
Language: u.Language,
|
Bio: u.Bio,
|
||||||
Active: u.Active,
|
ProfilePictureURL: u.ProfilePictureURL,
|
||||||
CreatedAt: u.CreatedAt,
|
Skills: skills,
|
||||||
LastLoginAt: u.LastLoginAt,
|
Experience: experience,
|
||||||
Bio: u.Bio,
|
Education: education,
|
||||||
ProfilePictureURL: u.ProfilePictureURL,
|
}
|
||||||
Skills: skills,
|
}
|
||||||
Experience: experience,
|
|
||||||
Education: education,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue