76 lines
2.5 KiB
Go
76 lines
2.5 KiB
Go
package model
|
|
|
|
import (
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
type User struct {
|
|
ID int64 `db:"id" json:"id"`
|
|
Email string `db:"email" json:"email"`
|
|
Username string `db:"username" json:"username"`
|
|
PasswordHash string `db:"password_hash" json:"-"`
|
|
EmailVerified bool `db:"email_verified" json:"email_verified"`
|
|
TelegramChatID sql.NullInt64 `db:"telegram_chat_id" json:"-"`
|
|
TelegramChatIDValue *int64 `db:"-" json:"telegram_chat_id"`
|
|
NotificationsEnabled bool `db:"notifications_enabled" json:"notifications_enabled"`
|
|
Timezone string `db:"timezone" json:"timezone"`
|
|
MorningReminderTime sql.NullString `db:"morning_reminder_time" json:"-"`
|
|
EveningReminderTime sql.NullString `db:"evening_reminder_time" json:"-"`
|
|
MorningTime string `db:"-" json:"morning_reminder_time"`
|
|
EveningTime string `db:"-" json:"evening_reminder_time"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
|
}
|
|
|
|
func (u *User) ProcessForJSON() {
|
|
if u.TelegramChatID.Valid {
|
|
u.TelegramChatIDValue = &u.TelegramChatID.Int64
|
|
}
|
|
if u.MorningReminderTime.Valid {
|
|
u.MorningTime = u.MorningReminderTime.String[:5] // "09:00:00" -> "09:00"
|
|
} else {
|
|
u.MorningTime = "09:00"
|
|
}
|
|
if u.EveningReminderTime.Valid {
|
|
u.EveningTime = u.EveningReminderTime.String[:5]
|
|
} else {
|
|
u.EveningTime = "21:00"
|
|
}
|
|
}
|
|
|
|
type RegisterRequest struct {
|
|
Email string `json:"email"`
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
type LoginRequest struct {
|
|
Email string `json:"email"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
type UpdateProfileRequest struct {
|
|
Username *string `json:"username,omitempty"`
|
|
TelegramChatID *int64 `json:"telegram_chat_id,omitempty"`
|
|
NotificationsEnabled *bool `json:"notifications_enabled,omitempty"`
|
|
Timezone *string `json:"timezone,omitempty"`
|
|
MorningReminderTime *string `json:"morning_reminder_time,omitempty"`
|
|
EveningReminderTime *string `json:"evening_reminder_time,omitempty"`
|
|
}
|
|
|
|
type ChangePasswordRequest struct {
|
|
OldPassword string `json:"old_password"`
|
|
NewPassword string `json:"new_password"`
|
|
}
|
|
|
|
type AuthResponse struct {
|
|
User *User `json:"user"`
|
|
AccessToken string `json:"access_token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
}
|
|
|
|
type RefreshRequest struct {
|
|
RefreshToken string `json:"refresh_token"`
|
|
}
|