@@ -3,20 +3,40 @@ package models
33import (
44 "time"
55
6+ "github.com/lib/pq"
67 "gorm.io/gorm"
78)
89
910type User struct {
10- ID uint `json:"id" gorm:"primaryKey"`
11- Username string `json:"username" gorm:"uniqueIndex;not null" validate:"required,min=3,max=50"`
12- Email string `json:"email" gorm:"uniqueIndex;not null" validate:"required,email"`
11+ ID uint `json:"id" gorm:"primaryKey"`
12+ Username string `json:"username" gorm:"uniqueIndex;not null" validate:"required,min=3,max=50"`
13+ Email string `json:"email" gorm:"uniqueIndex;not null" validate:"required,email"`
1314 PasswordHash string `json:"-" gorm:"not null"`
14- FirstName string `json:"first_name" validate:"min=2,max=50"`
15- LastName string `json:"last_name" validate:"min=2,max=50"`
16- IsActive bool `json:"is_active" gorm:"default:true"`
17- Role string `json:"role" validate:"required,oneof=admin user moderator support superuser" gorm:"default:'user'"`
18- CreatedAt time.Time `json:"created_at"`
19- UpdatedAt time.Time `json:"updated_at"`
15+ FirstName string `json:"first_name" validate:"min=2,max=50"`
16+ LastName string `json:"last_name" validate:"min=2,max=50"`
17+ IsActive bool `json:"is_active" gorm:"default:true"`
18+ Role string `json:"role" validate:"required,oneof=admin user moderator support superuser" gorm:"default:'user'"`
19+
20+ AvatarURL * string `json:"avatar_url" gorm:"type:text"`
21+ Location * string `json:"location" gorm:"size:255"`
22+ FavoriteGenres pq.StringArray `json:"favorite_genres" gorm:"type:text[]"`
23+ BooksRead int `json:"books_read" gorm:"default:0"`
24+ Bio * string `json:"bio" gorm:"type:text"`
25+ ReadingGoal int `json:"reading_goal" gorm:"default:0"`
26+ Badges pq.StringArray `json:"badges" gorm:"type:text[]"`
27+ IsOnline bool `json:"is_online" gorm:"default:false"`
28+ LastSeen * time.Time `json:"last_seen"`
29+
30+ OwnedClubs []Club `json:"owned_clubs,omitempty" gorm:"foreignKey:OwnerID"`
31+ ClubMemberships []ClubMembership `json:"club_memberships,omitempty" gorm:"foreignKey:UserID"`
32+ Posts []Post `json:"posts,omitempty" gorm:"foreignKey:AuthorID"`
33+ Comments []Comment `json:"comments,omitempty" gorm:"foreignKey:AuthorID"`
34+ Annotations []Annotation `json:"annotations,omitempty" gorm:"foreignKey:UserID"`
35+ PostLikes []PostLike `json:"post_likes,omitempty" gorm:"foreignKey:UserID"`
36+ CommentLikes []CommentLike `json:"comment_likes,omitempty" gorm:"foreignKey:UserID"`
37+
38+ CreatedAt time.Time `json:"created_at"`
39+ UpdatedAt time.Time `json:"updated_at"`
2040 DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
2141}
2242
@@ -27,7 +47,7 @@ type UserResponse struct {
2747 FirstName string `json:"first_name"`
2848 LastName string `json:"last_name"`
2949 IsActive bool `json:"is_active"`
30- Role string `json:"role"`
50+ Role string `json:"role"`
3151 CreatedAt time.Time `json:"created_at"`
3252}
3353
@@ -43,6 +63,26 @@ type RegisterRequest struct {
4363 FirstName string `json:"first_name" validate:"required,min=2,max=50"`
4464 LastName string `json:"last_name" validate:"required,min=2,max=50"`
4565 Role string `json:"role" validate:"omitempty,oneof=admin user moderator support superuser" gorm:"default:'user'"`
66+
67+ Location string `json:"location"`
68+ FavoriteGenres []string `json:"favorite_genres"`
69+ Bio string `json:"bio"`
70+ ReadingGoal int `json:"reading_goal"`
71+ }
72+
73+ type UpdateUserRequest struct {
74+ Username * string `json:"username" validate:"omitempty,min=3,max=50"`
75+ Email * string `json:"email" validate:"omitempty,email"`
76+ Password * string `json:"password" validate:"omitempty,min=6"`
77+ FirstName * string `json:"first_name" validate:"omitempty,min=2,max=50"`
78+ LastName * string `json:"last_name" validate:"omitempty,min=2,max=50"`
79+ AvatarURL * string `json:"avatar_url" validate:"omitempty,url"`
80+ Location * string `json:"location" validate:"omitempty,max=255"`
81+ FavoriteGenres * []string `json:"favorite_genres"`
82+ Bio * string `json:"bio" validate:"omitempty"`
83+ ReadingGoal * int `json:"reading_goal" validate:"omitempty,gte=0"`
84+ Role * string `json:"role" validate:"omitempty,oneof=admin user moderator support superuser"`
85+ IsActive * bool `json:"is_active"`
4686}
4787
4888func (u * User ) ToResponse () UserResponse {
@@ -56,4 +96,4 @@ func (u *User) ToResponse() UserResponse {
5696 Role : u .Role ,
5797 CreatedAt : u .CreatedAt ,
5898 }
59- }
99+ }
0 commit comments