refactor: 重构服务层和仓库层
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user