package user import ( "net/http" "time" "github.com/google/uuid" "gorm.io/gorm" ) type User struct { ID uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` Username string PasswordBcrypt string Profile Profile Sessions []Session } type UserResponse struct { ID uuid.UUID `json:"id"` Username string `json:"username"` Profile *ProfileResponse `json:"profile"` } type UserRegisterRequest struct { Username string `json:"username" validate:"required,min=2,max=100" swaggertype:"string" example:"user"` Password string `json:"password" validate:"required,min=6,max=100" swaggertype:"string" example:"password"` } type UserLoginRequest struct { Username string `json:"username" validate:"required,min=2,max=100" swaggertype:"string" example:"user"` Password string `json:"password" validate:"required" swaggertype:"string" example:"password"` } func (userResponse *UserResponse) Render(w http.ResponseWriter, r *http.Request) error { // Pre-processing before a response is marshalled and sent across the wire return nil } func (env *Env) NewUserResponse(user *User) *UserResponse { profileResponse := env.NewProfileResponse(&user.Profile) userResponse := &UserResponse{ ID: user.ID, Username: user.Username, Profile: profileResponse, } return userResponse }