You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
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"`
|
|
Password string `json:"password" validate:"required,min=6,max=100"`
|
|
}
|
|
|
|
type UserLoginRequest struct {
|
|
Username string `json:"username" validate:"required,min=2,max=100"`
|
|
Password string `json:"password" validate:"required"`
|
|
}
|
|
|
|
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
|
|
}
|