首次提交:初始化项目代码

This commit is contained in:
sunct
2026-07-31 15:24:14 +08:00
commit 8d3c97bd01
73 changed files with 11720 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package entity
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID uint `json:"id" gorm:"primaryKey;comment:用户ID"`
UserCode string `json:"user_code" gorm:"uniqueIndex;size:8;comment:用户码(8位随机字母数字)"`
Username string `json:"username" gorm:"uniqueIndex;size:50;comment:用户名"`
Password string `json:"-" gorm:"size:255;comment:密码(加密存储)"`
Email string `json:"email" gorm:"size:100;comment:邮箱"`
Phone string `json:"phone" gorm:"size:20;comment:手机号"`
Nickname string `json:"nickname" gorm:"size:50;comment:昵称"`
StorageUsed int64 `json:"storage_used" gorm:"default:0;comment:已使用存储空间(字节)"`
StorageLimit int64 `json:"storage_limit" gorm:"default:52428800;comment:存储空间限制(字节),默认50MB"`
CreatedAt time.Time `json:"created_at" gorm:"comment:创建时间"`
UpdatedAt time.Time `json:"updated_at" gorm:"comment:更新时间"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"comment:删除时间"`
}
func (User) TableName() string {
return "users"
}
func (User) TableComment() string {
return "用户表"
}
func NewUser(username, password, userCode, nickname string) *User {
if nickname == "" {
nickname = username
}
return &User{
Username: username,
Password: password,
UserCode: userCode,
Nickname: nickname,
StorageUsed: 0,
StorageLimit: 52428800,
}
}
@@ -0,0 +1,21 @@
package repository
import "cloudnest/internal/domain/auth/entity"
// UserRepository defines the interface for user data access operations.
// UserRepository 定义了用户数据访问操作的接口。
//
// This interface follows the Dependency Inversion Principle (DIP),
// where the application layer depends on this abstraction rather than concrete implementations.
//
// 此接口遵循依赖倒置原则(DIP),应用层依赖于这个抽象而非具体实现。
type UserRepository interface {
FindByUsername(username string) (*entity.User, error)
FindByUserCode(userCode string) (*entity.User, error)
FindByEmail(email string) (*entity.User, error)
Create(user *entity.User) error
FindByID(id uint) (*entity.User, error)
UpdateStorageUsed(userCode string, size int64) error
UpdateProfile(userCode, email, phone, nickname string) error
UpdatePassword(userCode, newPassword string) error
}