turash/bugulma/backend/internal/domain/address.go
Damir Mukimov 000eab4740
Major repository reorganization and missing backend endpoints implementation
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools

Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
  * GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
  * GET /api/v1/users/me/organizations - User organizations
  * POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue

API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules

Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
2025-11-25 06:01:16 +01:00

78 lines
2.5 KiB
Go

package domain
import (
"context"
"time"
)
// AddressType defines the purpose of an address
type AddressType string
const (
AddressTypeHeadquarters AddressType = "headquarters"
AddressTypeBilling AddressType = "billing"
AddressTypeShipping AddressType = "shipping"
AddressTypeBranch AddressType = "branch"
AddressTypeSite AddressType = "site"
)
// Address represents a physical address that can be associated with organizations or sites
type Address struct {
ID string `gorm:"primaryKey;type:text"`
// Address components
Street string `gorm:"type:text"`
City string `gorm:"type:text"`
Region string `gorm:"type:text"`
PostalCode string `gorm:"type:varchar(20)"`
Country string `gorm:"type:varchar(2);default:'RU'"` // ISO country code
// Full formatted address in different locales
FormattedRu string `gorm:"type:text;index"` // Russian
FormattedEn string `gorm:"type:text"` // English
FormattedTt string `gorm:"type:text"` // Tatar
// Geolocation
Latitude float64 `gorm:"type:double precision;index:idx_address_location"`
Longitude float64 `gorm:"type:double precision;index:idx_address_location"`
// Address type and usage
AddressType AddressType `gorm:"type:varchar(20);index"`
// Metadata
Verified bool `gorm:"default:false"`
Source string `gorm:"type:text"` // OSM, manual, API, etc.
// Timestamps
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
// Associations - many-to-many relationships
Organizations []Organization `gorm:"many2many:organization_addresses;"`
Sites []Site `gorm:"many2many:site_addresses;"`
}
// TableName specifies the table name for GORM
func (Address) TableName() string {
return "addresses"
}
// AddressRepository defines operations for address management
type AddressRepository interface {
Create(ctx context.Context, address *Address) error
GetByID(ctx context.Context, id string) (*Address, error)
GetAll(ctx context.Context) ([]*Address, error)
Update(ctx context.Context, address *Address) error
Delete(ctx context.Context, id string) error
// Find addresses by location
GetWithinRadius(ctx context.Context, lat, lng, radiusKm float64) ([]*Address, error)
// Find addresses by entity
GetByOrganizationID(ctx context.Context, orgID string) ([]*Address, error)
GetBySiteID(ctx context.Context, siteID string) ([]*Address, error)
// Find or create address (deduplication)
FindOrCreate(ctx context.Context, address *Address) (*Address, error)
}