package entities import ( "errors" "time" "github.com/google/uuid" ) const UserTable = "users" type User struct { Id uuid.UUID `db:"id"` UserName string `db:"username"` Password string `db:"password"` Name string `db:"name"` Role string `db:"role"` Speciality string `db:"speciality"` Description string `db:"description"` Skills string `db:"skills"` Avatar string `db:"avatar"` JoinDate time.Time `db:"joindate"` Projects string `db:"projects"` Motto string `db:"motto"` } func CreateUser( userName string, password string, name string, role string, speciality string, description string, skills string, avatar string, joinDate time.Time, projects string, motto string, ) (user User, err error) { user = User{ Id: uuid.New(), UserName: userName, Password: password, Name: name, Role: role, Speciality: speciality, Description: description, Skills: skills, Avatar: avatar, JoinDate: joinDate, Projects: projects, Motto: motto, } err = user.Validate() return } func (u *User) Validate() error { if err := uuid.Validate(u.Id.String()); err != nil { return errors.New("invalid user.id") } if u.UserName == "" { return errors.New("empty user.username") } if u.Password == "" { return errors.New("empty user.password") } if u.Role == "" { return errors.New("empty user.role") } if u.Name == "" { return errors.New("empty user.name") } if u.Speciality == "" { return errors.New("empty user.speciality") } if u.Description == "" { return errors.New("empty user.description") } if u.Skills == "" { return errors.New("empty user.skills") } if u.Avatar == "" { return errors.New("empty user.avatar") } if u.Projects == "" { return errors.New("empty user.projects") } if u.Motto == "" { return errors.New("empty user.motto") } if u.JoinDate.IsZero() { return errors.New("empty user.joinDate") } return nil }