Added completed user. Some fixes and more more more...

This commit is contained in:
KamilM1205 2026-01-02 22:56:25 +04:00
parent b96dd39795
commit ea8ab7c0ed
33 changed files with 576 additions and 212 deletions

View file

@ -2,6 +2,7 @@ package entities
import (
"errors"
"time"
"github.com/google/uuid"
)
@ -9,16 +10,47 @@ import (
const UserTable = "users"
type User struct {
Id uuid.UUID `db:"id"`
UserName string `db:"username"`
Password string `db:"password"`
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) (user User, err error) {
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,
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()
@ -28,14 +60,51 @@ func CreateUser(userName string, password string) (user User, err error) {
func (u *User) Validate() error {
if err := uuid.Validate(u.Id.String()); err != nil {
return errors.New("Invalid user.id")
return errors.New("invalid user.id")
}
if u.UserName == "" {
return errors.New("Empty user.name")
return errors.New("empty user.username")
}
if u.Password == "" {
return errors.New("Empty user.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