Initial commit: Homelab API
This commit is contained in:
32
internal/model/email.go
Normal file
32
internal/model/email.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type EmailToken struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
UserID int64 `db:"user_id" json:"user_id"`
|
||||
Token string `db:"token" json:"token"`
|
||||
Type string `db:"type" json:"type"` // verification, reset
|
||||
ExpiresAt time.Time `db:"expires_at" json:"expires_at"`
|
||||
UsedAt *time.Time `db:"used_at" json:"used_at"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
type ForgotPasswordRequest struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
type ResetPasswordRequest struct {
|
||||
Token string `json:"token"`
|
||||
NewPassword string `json:"new_password"`
|
||||
}
|
||||
|
||||
type VerifyEmailRequest struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type ResendVerificationRequest struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
74
internal/model/habit.go
Normal file
74
internal/model/habit.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Habit struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
UserID int64 `db:"user_id" json:"user_id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
Frequency string `db:"frequency" json:"frequency"` // daily, weekly, custom
|
||||
TargetDays []int `db:"-" json:"target_days"` // 0=Sun, 1=Mon, etc.
|
||||
TargetCount int `db:"target_count" json:"target_count"`
|
||||
IsArchived bool `db:"is_archived" json:"is_archived"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
type HabitLog struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
HabitID int64 `db:"habit_id" json:"habit_id"`
|
||||
UserID int64 `db:"user_id" json:"user_id"`
|
||||
Date time.Time `db:"date" json:"date"`
|
||||
Count int `db:"count" json:"count"`
|
||||
Note string `db:"note" json:"note"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
type CreateHabitRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Color string `json:"color,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Frequency string `json:"frequency,omitempty"`
|
||||
TargetDays []int `json:"target_days,omitempty"`
|
||||
TargetCount int `json:"target_count,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateHabitRequest struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Color *string `json:"color,omitempty"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
Frequency *string `json:"frequency,omitempty"`
|
||||
TargetDays []int `json:"target_days,omitempty"`
|
||||
TargetCount *int `json:"target_count,omitempty"`
|
||||
IsArchived *bool `json:"is_archived,omitempty"`
|
||||
}
|
||||
|
||||
type LogHabitRequest struct {
|
||||
Date string `json:"date,omitempty"` // YYYY-MM-DD, defaults to today
|
||||
Count int `json:"count,omitempty"`
|
||||
Note string `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
type HabitStats struct {
|
||||
HabitID int64 `json:"habit_id"`
|
||||
TotalLogs int `json:"total_logs"`
|
||||
CurrentStreak int `json:"current_streak"`
|
||||
LongestStreak int `json:"longest_streak"`
|
||||
CompletionPct float64 `json:"completion_pct"`
|
||||
ThisWeek int `json:"this_week"`
|
||||
ThisMonth int `json:"this_month"`
|
||||
}
|
||||
|
||||
type OverallStats struct {
|
||||
TotalHabits int `json:"total_habits"`
|
||||
ActiveHabits int `json:"active_habits"`
|
||||
TodayCompleted int `json:"today_completed"`
|
||||
WeeklyAvg float64 `json:"weekly_avg"`
|
||||
}
|
||||
48
internal/model/task.go
Normal file
48
internal/model/task.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
UserID int64 `db:"user_id" json:"user_id"`
|
||||
Title string `db:"title" json:"title"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
Color string `db:"color" json:"color"`
|
||||
DueDate sql.NullTime `db:"due_date" json:"-"`
|
||||
DueDateStr *string `db:"-" json:"due_date"`
|
||||
Priority int `db:"priority" json:"priority"` // 0=none, 1=low, 2=medium, 3=high
|
||||
CompletedAt sql.NullTime `db:"completed_at" json:"-"`
|
||||
Completed bool `db:"-" json:"completed"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (t *Task) ProcessForJSON() {
|
||||
if t.DueDate.Valid {
|
||||
s := t.DueDate.Time.Format("2006-01-02")
|
||||
t.DueDateStr = &s
|
||||
}
|
||||
t.Completed = t.CompletedAt.Valid
|
||||
}
|
||||
|
||||
type CreateTaskRequest struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Color string `json:"color,omitempty"`
|
||||
DueDate *string `json:"due_date,omitempty"` // YYYY-MM-DD
|
||||
Priority int `json:"priority,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateTaskRequest struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
Color *string `json:"color,omitempty"`
|
||||
DueDate *string `json:"due_date,omitempty"`
|
||||
Priority *int `json:"priority,omitempty"`
|
||||
}
|
||||
45
internal/model/user.go
Normal file
45
internal/model/user.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"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"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user