refactor: 重构服务层和仓库层
This commit is contained in:
@@ -83,3 +83,5 @@ type YggdrasilRepository interface {
|
||||
ResetPassword(id int64, password string) error
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,11 @@ func (r *profileRepository) FindByUUID(uuid string) (*model.Profile, error) {
|
||||
|
||||
func (r *profileRepository) FindByName(name string) (*model.Profile, error) {
|
||||
var profile model.Profile
|
||||
err := r.db.Where("name = ?", name).First(&profile).Error
|
||||
// 使用 LOWER 函数进行不区分大小写的查询,并预加载 Skin 和 Cape
|
||||
err := r.db.Where("LOWER(name) = LOWER(?)", name).
|
||||
Preload("Skin").
|
||||
Preload("Cape").
|
||||
First(&profile).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -98,7 +102,10 @@ func (r *profileRepository) UpdateLastUsedAt(uuid string) error {
|
||||
|
||||
func (r *profileRepository) GetByNames(names []string) ([]*model.Profile, error) {
|
||||
var profiles []*model.Profile
|
||||
err := r.db.Where("name in (?)", names).Find(&profiles).Error
|
||||
err := r.db.Where("name in (?)", names).
|
||||
Preload("Skin").
|
||||
Preload("Cape").
|
||||
Find(&profiles).Error
|
||||
return profiles, err
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func (r *tokenRepository) GetByUserID(userId int64) ([]*model.Token, error) {
|
||||
|
||||
func (r *tokenRepository) GetUUIDByAccessToken(accessToken string) (string, error) {
|
||||
var token model.Token
|
||||
err := r.db.Where("access_token = ?", accessToken).First(&token).Error
|
||||
err := r.db.Select("profile_id").Where("access_token = ?", accessToken).First(&token).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func (r *tokenRepository) GetUUIDByAccessToken(accessToken string) (string, erro
|
||||
|
||||
func (r *tokenRepository) GetUserIDByAccessToken(accessToken string) (int64, error) {
|
||||
var token model.Token
|
||||
err := r.db.Where("access_token = ?", accessToken).First(&token).Error
|
||||
err := r.db.Select("user_id").Where("access_token = ?", accessToken).First(&token).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func NewYggdrasilRepository(db *gorm.DB) YggdrasilRepository {
|
||||
|
||||
func (r *yggdrasilRepository) GetPasswordByID(id int64) (string, error) {
|
||||
var yggdrasil model.Yggdrasil
|
||||
err := r.db.Where("id = ?", id).First(&yggdrasil).Error
|
||||
err := r.db.Select("password").Where("id = ?", id).First(&yggdrasil).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -28,5 +28,3 @@ func (r *yggdrasilRepository) GetPasswordByID(id int64) (string, error) {
|
||||
func (r *yggdrasilRepository) ResetPassword(id int64, password string) error {
|
||||
return r.db.Model(&model.Yggdrasil{}).Where("id = ?", id).Update("password", password).Error
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user