Complete rewrite of Django REST API to Go with: - Gin web framework for HTTP routing - GORM for database operations - GoAdmin for admin panel - Gorush integration for push notifications - Redis for caching and job queues Features implemented: - User authentication (login, register, logout, password reset) - Residence management (CRUD, sharing, share codes) - Task management (CRUD, kanban board, completions) - Contractor management (CRUD, specialties) - Document management (CRUD, warranties) - Notifications (preferences, push notifications) - Subscription management (tiers, limits) Infrastructure: - Docker Compose for local development - Database migrations and seed data - Admin panel for data management 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
874 B
Go
39 lines
874 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// BaseModel contains common columns for all tables with ID, CreatedAt, UpdatedAt
|
|
type BaseModel struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// SoftDeleteModel extends BaseModel with soft delete support
|
|
type SoftDeleteModel struct {
|
|
BaseModel
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
// BeforeCreate sets timestamps before creating a record
|
|
func (b *BaseModel) BeforeCreate(tx *gorm.DB) error {
|
|
now := time.Now().UTC()
|
|
if b.CreatedAt.IsZero() {
|
|
b.CreatedAt = now
|
|
}
|
|
if b.UpdatedAt.IsZero() {
|
|
b.UpdatedAt = now
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BeforeUpdate sets updated_at before updating a record
|
|
func (b *BaseModel) BeforeUpdate(tx *gorm.DB) error {
|
|
b.UpdatedAt = time.Now().UTC()
|
|
return nil
|
|
}
|