Add comments to virtual_* database files
Add human-readable comments explaining each function's purpose, parameters, and return values for better documentation.
This commit is contained in:
parent
0e6fad65e2
commit
19ce2224b8
3 changed files with 95 additions and 0 deletions
|
|
@ -1,5 +1,15 @@
|
|||
// Package db provides database access for the IMC application.
|
||||
// It uses GORM (Go ORM) for database operations.
|
||||
|
||||
package db
|
||||
|
||||
// =============================================================================
|
||||
// VirtualDomain - Mail domain operations
|
||||
// These functions interact with the ISPmail virtual_domains table.
|
||||
// =============================================================================
|
||||
|
||||
// GetAllDomains retrieves all domains with user and alias counts.
|
||||
// Returns a slice of DomainStats (includes counts) or an error.
|
||||
func (d *DB) GetAllDomains() ([]DomainStats, error) {
|
||||
var domains []VirtualDomain
|
||||
if err := d.Order("name ASC").Find(&domains).Error; err != nil {
|
||||
|
|
@ -26,6 +36,9 @@ func (d *DB) GetAllDomains() ([]DomainStats, error) {
|
|||
return stats, nil
|
||||
}
|
||||
|
||||
// GetDomainByID retrieves a single domain by its ID.
|
||||
// id: the domain's ID.
|
||||
// Returns the VirtualDomain or an error (including "record not found").
|
||||
func (d *DB) GetDomainByID(id uint) (*VirtualDomain, error) {
|
||||
var domain VirtualDomain
|
||||
if err := d.Where("id = ?", id).First(&domain).Error; err != nil {
|
||||
|
|
@ -34,6 +47,9 @@ func (d *DB) GetDomainByID(id uint) (*VirtualDomain, error) {
|
|||
return &domain, nil
|
||||
}
|
||||
|
||||
// GetDomainByName retrieves a single domain by its name.
|
||||
// name: the domain name (e.g., "example.org").
|
||||
// Returns the VirtualDomain or an error (including "record not found").
|
||||
func (d *DB) GetDomainByName(name string) (*VirtualDomain, error) {
|
||||
var domain VirtualDomain
|
||||
if err := d.Where("name = ?", name).First(&domain).Error; err != nil {
|
||||
|
|
@ -42,6 +58,9 @@ func (d *DB) GetDomainByName(name string) (*VirtualDomain, error) {
|
|||
return &domain, nil
|
||||
}
|
||||
|
||||
// CreateDomain creates a new mail domain.
|
||||
// name: the domain name (e.g., "example.org").
|
||||
// Returns the created VirtualDomain or an error.
|
||||
func (d *DB) CreateDomain(name string) (*VirtualDomain, error) {
|
||||
domain := VirtualDomain{Name: name}
|
||||
if err := d.Create(&domain).Error; err != nil {
|
||||
|
|
@ -50,6 +69,10 @@ func (d *DB) CreateDomain(name string) (*VirtualDomain, error) {
|
|||
return &domain, nil
|
||||
}
|
||||
|
||||
// DeleteDomain permanently removes a domain and all associated users and aliases.
|
||||
// id: the domain's ID to delete.
|
||||
// This also deletes all virtual_users and virtual_aliases belonging to this domain.
|
||||
// Returns an error if the deletion fails.
|
||||
func (d *DB) DeleteDomain(id uint) error {
|
||||
tx := d.Begin()
|
||||
defer func() { tx.Rollback() }()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue