Feat(ktm-booking): Initial commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
52
backend/internal/user/usermodel.go
Normal file
52
backend/internal/user/usermodel.go
Normal file
@@ -0,0 +1,52 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user