Allow get realm by numeric auto increment id

This commit is contained in:
2024-11-16 21:36:34 +08:00
parent 40b64a3559
commit f91be512f3
3 changed files with 24 additions and 26 deletions

View File

@ -5,6 +5,7 @@ import (
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
"github.com/samber/lo"
"strconv"
)
func ListCommunityRealm() ([]models.Realm, error) {
@ -48,10 +49,15 @@ func ListAvailableRealm(user models.Account) ([]models.Realm, error) {
}
func GetRealmWithAlias(alias string) (models.Realm, error) {
tx := database.C.Where("alias = ?", alias)
numericId, err := strconv.Atoi(alias)
if err == nil {
tx.Or("id = ?", numericId)
}
var realm models.Realm
if err := database.C.Where(&models.Realm{
Alias: alias,
}).First(&realm).Error; err != nil {
if err := tx.First(&realm).Error; err != nil {
return realm, err
}
return realm, nil