Files
ktm-booking-bot/backend/internal/user/usermodel.go
Samuel Pua 0ea75f6211
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good
Fix(booking-controller): Fixed fetching of bookings
2022-09-27 20:29:46 +08:00

53 lines
1.4 KiB
Go

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
}